openmates 0.10.0-alpha.3 → 0.10.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-R4HKMYBT.js → chunk-N6QY7K6L.js} +31 -16
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -4847,36 +4847,51 @@ function formatEmbedsForMessage(embeds) {
|
|
|
4847
4847
|
// src/uploadService.ts
|
|
4848
4848
|
import { readFileSync as readFileSync4 } from "fs";
|
|
4849
4849
|
import { basename as basename2 } from "path";
|
|
4850
|
+
var UPLOAD_MAX_ATTEMPTS = 3;
|
|
4851
|
+
var UPLOAD_RETRY_DELAY_MS = 2e3;
|
|
4850
4852
|
function getUploadUrl(apiUrl) {
|
|
4851
4853
|
try {
|
|
4852
4854
|
const url = new URL(apiUrl);
|
|
4853
|
-
url.hostname
|
|
4854
|
-
url.port = "";
|
|
4855
|
-
return url.origin;
|
|
4855
|
+
if (url.hostname === "localhost") return "http://localhost:8001";
|
|
4856
4856
|
} catch {
|
|
4857
|
-
return "https://upload.openmates.org";
|
|
4858
4857
|
}
|
|
4858
|
+
return "https://upload.openmates.org";
|
|
4859
4859
|
}
|
|
4860
4860
|
async function uploadFile(filePath, session) {
|
|
4861
4861
|
const filename = basename2(filePath);
|
|
4862
4862
|
const fileBytes = readFileSync4(filePath);
|
|
4863
4863
|
const uploadUrl = `${getUploadUrl(session.apiUrl)}/v1/upload/file`;
|
|
4864
|
-
const blob = new Blob([fileBytes]);
|
|
4865
|
-
const formData = new FormData();
|
|
4866
|
-
formData.append("file", blob, filename);
|
|
4867
4864
|
const cookies = [];
|
|
4868
4865
|
if (session.cookies?.auth_refresh_token) {
|
|
4869
4866
|
cookies.push(`auth_refresh_token=${session.cookies.auth_refresh_token}`);
|
|
4870
4867
|
}
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4868
|
+
let response;
|
|
4869
|
+
let lastError;
|
|
4870
|
+
for (let attempt = 1; attempt <= UPLOAD_MAX_ATTEMPTS; attempt++) {
|
|
4871
|
+
try {
|
|
4872
|
+
const blob = new Blob([fileBytes]);
|
|
4873
|
+
const formData = new FormData();
|
|
4874
|
+
formData.append("file", blob, filename);
|
|
4875
|
+
response = await fetch(uploadUrl, {
|
|
4876
|
+
method: "POST",
|
|
4877
|
+
body: formData,
|
|
4878
|
+
headers: {
|
|
4879
|
+
...cookies.length > 0 ? { Cookie: cookies.join("; ") } : {}
|
|
4880
|
+
},
|
|
4881
|
+
signal: AbortSignal.timeout(10 * 60 * 1e3)
|
|
4882
|
+
// 10-minute timeout
|
|
4883
|
+
});
|
|
4884
|
+
break;
|
|
4885
|
+
} catch (error) {
|
|
4886
|
+
lastError = error;
|
|
4887
|
+
if (attempt === UPLOAD_MAX_ATTEMPTS) break;
|
|
4888
|
+
await new Promise((resolve4) => setTimeout(resolve4, UPLOAD_RETRY_DELAY_MS));
|
|
4889
|
+
}
|
|
4890
|
+
}
|
|
4891
|
+
if (!response) {
|
|
4892
|
+
const message = lastError instanceof Error ? lastError.message : String(lastError);
|
|
4893
|
+
throw new Error(message || "Upload request failed.");
|
|
4894
|
+
}
|
|
4880
4895
|
if (!response.ok) {
|
|
4881
4896
|
const status = response.status;
|
|
4882
4897
|
let errorMessage;
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED