mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-23 09:42:53 +02:00
Finished wget() Netscript fn implementation. Updated documentation
This commit is contained in:
+23
-24
@@ -2262,35 +2262,34 @@ function NetscriptFunctions(workerScript) {
|
||||
});
|
||||
},
|
||||
wget : async function(url, target, ip=workerScript.serverIp) {
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("wget", CONSTANTS.ScriptWgetRamCost);
|
||||
}
|
||||
updateDynamicRam("wget", CONSTANTS.ScriptWgetRamCost);
|
||||
if (workerScript.checkingRam) { return 0; }
|
||||
if (!isScriptFilename(target) && !target.endsWith(".txt")) {
|
||||
workerSript.log(`ERROR: wget() failed because of an invalid target file: ${target}. Target file must be a script or text file`);
|
||||
return false;
|
||||
}
|
||||
var s = safeGetServer(ip, "wget");
|
||||
$.get(url, function(data) {
|
||||
let res;
|
||||
if (isScriptFilename(target)) {
|
||||
res = s.writeToScriptFile(target, data);
|
||||
} else {
|
||||
res = s.writeToTextFile(target, data);
|
||||
}
|
||||
if (!res.success) {
|
||||
workerScript.log("ERROR: wget() failed");
|
||||
return false;
|
||||
}
|
||||
if (res.overwritten) {
|
||||
workerScript.log(`wget() successfully retrieved content and overwrote ${target} on ${ip}`);
|
||||
return true;
|
||||
}
|
||||
workerScript.log(`wget successfully retrieved content to new file ${target} on ${ip}`);
|
||||
return true;
|
||||
}, 'text').fail(function(e) {
|
||||
workerScript.log("ERROR: wget() failed: " + JSON.stringify(e));
|
||||
return false;
|
||||
return new Promise(function(resolve, reject) {
|
||||
$.get(url, function(data) {
|
||||
let res;
|
||||
if (isScriptFilename(target)) {
|
||||
res = s.writeToScriptFile(target, data);
|
||||
} else {
|
||||
res = s.writeToTextFile(target, data);
|
||||
}
|
||||
if (!res.success) {
|
||||
workerScript.log("ERROR: wget() failed");
|
||||
return resolve(false);
|
||||
}
|
||||
if (res.overwritten) {
|
||||
workerScript.log(`wget() successfully retrieved content and overwrote ${target} on ${ip}`);
|
||||
return resolve(true);
|
||||
}
|
||||
workerScript.log(`wget successfully retrieved content to new file ${target} on ${ip}`);
|
||||
return resolve(true);
|
||||
}, 'text').fail(function(e) {
|
||||
workerScript.log(`ERROR: wget() failed: ${JSON.stringify(e)}`);
|
||||
return resolve(false)
|
||||
});
|
||||
});
|
||||
},
|
||||
getFavorToDonate: function() {
|
||||
|
||||
Reference in New Issue
Block a user