Automatically upload export to master server

Upload the created export data zip file to a new /api/upload-export
endpoint on the master server which unpacks it into the appropriate
directory on the master.
This commit is contained in:
Hornwitser committed 2020-05-26 15:31:42 +02:00
1 parent f3d4cfdcf5
commit 36cf14074e
5 files changed
+62 -4

No files matched your search

+18 -1
View File
@@ -16,6 +16,7 @@ const yargs = require("yargs");
const events = require("events");
const pidusage = require("pidusage");
const setBlocking = require("set-blocking");
const phin = require("phin");
const version = require("./package").version;
// internal libraries
@@ -446,7 +447,23 @@ class Instance extends link.Link{
console.log("Exporting data .....");
await symlinkMods(this, "sharedMods", console);
await factorio.exportData(this.server);
let zip = await factorio.exportData(this.server);
let content = await zip.generateAsync({ type: "nodebuffer" });
let url = new URL(this._slave.config.get("slave.master_url"));
url.pathname += "api/upload-export";
let response = await phin({
url, method: "PUT",
data: content,
core: { rejectUnauthorized: false },
headers: {
"Content-Type": "application/zip",
"x-access-token": this._slave.config.get("slave.master_token"),
},
});
if (response.statusCode !== 200) {
throw Error(`Upload failed: ${response.statusCode} ${response.statusMessage}: ${response.body}`)
}
} finally {
this.notifyExit();