Replace remaining usage of phin (#862)

Replace the remaining places in the codebase using phin with fetch.
With the exception of HttpCloser which uses the http/https request
method instead.
This commit is contained in:
Hornwitser authored and GitHub committed 2026-03-06 15:27:12 +01:00
1 parent ef0baaa30f
commit 05b6bf8c04
13 files changed
+91 -102

No files matched your search

+3 -5
View File
@@ -4,7 +4,6 @@ const fs = require("fs-extra");
const jwt = require("jsonwebtoken");
const path = require("path");
const events = require("events");
const phin = require("phin");
const lib = require("@clusterio/lib");
const libBuildMod = require("@clusterio/lib/build_mod");
@@ -79,16 +78,15 @@ async function runWithAltHost(callback) {
}
async function uploadSave(instanceId, name, content) {
return await phin({
url: `https://localhost:4443/api/upload-save?instance_id=${instanceId}&filename=${name}`,
const uploadUrl = `https://localhost:4443/api/upload-save?instance_id=${instanceId}&filename=${name}`;
return await fetch(uploadUrl, {
method: "POST",
core: { rejectUnauthorized: false },
headers: {
"X-Access-Token": controlToken,
"Content-Type": "application/zip",
"Content-Length": String(content.length),
},
data: content,
body: content,
});
}
+6 -8
View File
@@ -4,7 +4,6 @@ const path = require("path");
const fs = require("fs-extra");
const child_process = require("child_process");
const jwt = require("jsonwebtoken");
const phin = require("phin");
const util = require("util");
const events = require("events");
@@ -148,13 +147,12 @@ function hasFactorio() {
}
async function get(urlPath) {
let res = await phin({
method: "GET",
url: `https://localhost:4443${urlPath}`,
core: { rejectUnauthorized: false },
});
if (res.statusCode !== 200) {
throw new Error(`Got response code ${res.statusCode}, content: ${res.body}`);
const url = new URL("https://localhost:4443");
url.pathname = urlPath;
let res = await fetch(url);
if (res.status !== 200) {
const body = Buffer.from(await res.arrayBuffer());
throw new Error(`Got response code ${res.status}, content: ${body.toString()}`);
}
return res;
}