openmates 0.10.0-alpha.3 → 0.10.0-alpha.4
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-H76DR4ER.js} +29 -12
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -4847,6 +4847,8 @@ 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);
|
|
@@ -4861,22 +4863,37 @@ async function uploadFile(filePath, session) {
|
|
|
4861
4863
|
const filename = basename2(filePath);
|
|
4862
4864
|
const fileBytes = readFileSync4(filePath);
|
|
4863
4865
|
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
4866
|
const cookies = [];
|
|
4868
4867
|
if (session.cookies?.auth_refresh_token) {
|
|
4869
4868
|
cookies.push(`auth_refresh_token=${session.cookies.auth_refresh_token}`);
|
|
4870
4869
|
}
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4870
|
+
let response;
|
|
4871
|
+
let lastError;
|
|
4872
|
+
for (let attempt = 1; attempt <= UPLOAD_MAX_ATTEMPTS; attempt++) {
|
|
4873
|
+
try {
|
|
4874
|
+
const blob = new Blob([fileBytes]);
|
|
4875
|
+
const formData = new FormData();
|
|
4876
|
+
formData.append("file", blob, filename);
|
|
4877
|
+
response = await fetch(uploadUrl, {
|
|
4878
|
+
method: "POST",
|
|
4879
|
+
body: formData,
|
|
4880
|
+
headers: {
|
|
4881
|
+
...cookies.length > 0 ? { Cookie: cookies.join("; ") } : {}
|
|
4882
|
+
},
|
|
4883
|
+
signal: AbortSignal.timeout(10 * 60 * 1e3)
|
|
4884
|
+
// 10-minute timeout
|
|
4885
|
+
});
|
|
4886
|
+
break;
|
|
4887
|
+
} catch (error) {
|
|
4888
|
+
lastError = error;
|
|
4889
|
+
if (attempt === UPLOAD_MAX_ATTEMPTS) break;
|
|
4890
|
+
await new Promise((resolve4) => setTimeout(resolve4, UPLOAD_RETRY_DELAY_MS));
|
|
4891
|
+
}
|
|
4892
|
+
}
|
|
4893
|
+
if (!response) {
|
|
4894
|
+
const message = lastError instanceof Error ? lastError.message : String(lastError);
|
|
4895
|
+
throw new Error(message || "Upload request failed.");
|
|
4896
|
+
}
|
|
4880
4897
|
if (!response.ok) {
|
|
4881
4898
|
const status = response.status;
|
|
4882
4899
|
let errorMessage;
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED