@qaecy/cue-cli 0.0.14 → 0.0.15
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/main.js +82 -41
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -5733,7 +5733,7 @@ function turtleFileMetadata(sourceFile, processorId, locationUUID, stored = fals
|
|
|
5733
5733
|
|
|
5734
5734
|
// apps/desktop/cue-cli/src/helpers/upload-file.ts
|
|
5735
5735
|
var import_promises6 = require("fs/promises");
|
|
5736
|
-
async function uploadFile(file, spaceId, userId, providerId
|
|
5736
|
+
async function uploadFile(file, spaceId, userId, providerId) {
|
|
5737
5737
|
const firebase = CueFirebase.getInstance();
|
|
5738
5738
|
const rawFileMetadata = uploadedFileMetadata(
|
|
5739
5739
|
file.relativePath,
|
|
@@ -5745,37 +5745,64 @@ async function uploadFile(file, spaceId, userId, providerId, verbose) {
|
|
|
5745
5745
|
const storage = firebase.storageRaw;
|
|
5746
5746
|
const fileRef = (0, import_storage5.ref)(storage, rawFileMetadata.blob_name);
|
|
5747
5747
|
const fileBuffer = await (0, import_promises6.readFile)(file.fullPath);
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
console.error("[uploadFile] Error uploading file:", {
|
|
5757
|
-
filePath: file.fullPath,
|
|
5758
|
-
relativePath: file.relativePath,
|
|
5759
|
-
md5: file.md5,
|
|
5760
|
-
blobName: rawFileMetadata.blob_name,
|
|
5761
|
-
errorCode: error?.code,
|
|
5762
|
-
errorMessage: error?.message,
|
|
5763
|
-
errorPayload: error
|
|
5748
|
+
const maxRetries = 3;
|
|
5749
|
+
let attempt = 0;
|
|
5750
|
+
let lastError = null;
|
|
5751
|
+
while (attempt < maxRetries) {
|
|
5752
|
+
try {
|
|
5753
|
+
await new Promise((resolve, reject) => {
|
|
5754
|
+
const uploadTask = (0, import_storage5.uploadBytesResumable)(fileRef, fileBuffer, {
|
|
5755
|
+
customMetadata: rawFileMetadata
|
|
5764
5756
|
});
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5757
|
+
uploadTask.on(
|
|
5758
|
+
"state_changed",
|
|
5759
|
+
null,
|
|
5760
|
+
(error) => {
|
|
5761
|
+
const blobName = rawFileMetadata.blob_name;
|
|
5762
|
+
console.error("[uploadFile] Error uploading file:", {
|
|
5763
|
+
filePath: file.fullPath,
|
|
5764
|
+
relativePath: file.relativePath,
|
|
5765
|
+
md5: file.md5,
|
|
5766
|
+
blobName,
|
|
5767
|
+
blobNameLength: blobName?.length,
|
|
5768
|
+
blobNameIsUnusual: blobName && (blobName.length > 256 || /[^\w\-./]/.test(blobName)),
|
|
5769
|
+
errorCode: error?.code,
|
|
5770
|
+
errorMessage: error?.message,
|
|
5771
|
+
errorPayload: error,
|
|
5772
|
+
fileBufferSize: fileBuffer?.length,
|
|
5773
|
+
rawFileMetadataKeys: Object.keys(rawFileMetadata),
|
|
5774
|
+
rawFileMetadataLength: Object.keys(rawFileMetadata).length,
|
|
5775
|
+
attempt
|
|
5776
|
+
});
|
|
5777
|
+
reject(error);
|
|
5778
|
+
},
|
|
5779
|
+
() => resolve()
|
|
5780
|
+
);
|
|
5781
|
+
if (!uploadTask) {
|
|
5782
|
+
console.error("[uploadFile] Upload task could not be created:", {
|
|
5783
|
+
filePath: file.fullPath,
|
|
5784
|
+
relativePath: file.relativePath,
|
|
5785
|
+
md5: file.md5,
|
|
5786
|
+
blobName: rawFileMetadata.blob_name,
|
|
5787
|
+
attempt
|
|
5788
|
+
});
|
|
5789
|
+
reject(new Error("Upload task could not be created"));
|
|
5790
|
+
}
|
|
5775
5791
|
});
|
|
5776
|
-
|
|
5792
|
+
lastError = null;
|
|
5793
|
+
break;
|
|
5794
|
+
} catch (err) {
|
|
5795
|
+
lastError = err;
|
|
5796
|
+
attempt++;
|
|
5797
|
+
if (attempt < maxRetries) {
|
|
5798
|
+
console.warn(`[uploadFile] Retry attempt ${attempt} for file: ${file.fullPath}`);
|
|
5799
|
+
await new Promise((res) => setTimeout(res, 1e3 * attempt));
|
|
5800
|
+
}
|
|
5777
5801
|
}
|
|
5778
|
-
}
|
|
5802
|
+
}
|
|
5803
|
+
if (lastError) {
|
|
5804
|
+
throw lastError;
|
|
5805
|
+
}
|
|
5779
5806
|
return rawFileMetadata;
|
|
5780
5807
|
}
|
|
5781
5808
|
|
|
@@ -5895,20 +5922,31 @@ async function syncHandler(options) {
|
|
|
5895
5922
|
if (verbose && report.localNotOnRemote.length)
|
|
5896
5923
|
console.info("Syncing missing files \u23F3");
|
|
5897
5924
|
let rdfWritten = false;
|
|
5925
|
+
let failedUploads = 0;
|
|
5898
5926
|
for (const file of report.localNotOnRemote) {
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5927
|
+
let rawFileMetadata;
|
|
5928
|
+
try {
|
|
5929
|
+
rawFileMetadata = await uploadFile(file, space, userId, provider);
|
|
5930
|
+
await uploadFileRDF(file, rawFileMetadata, verbose);
|
|
5931
|
+
syncCount += 1;
|
|
5932
|
+
syncSize += file.size || 0;
|
|
5933
|
+
const pct = Math.floor(syncCount / report.totalCount * 100);
|
|
5934
|
+
if (verbose && report.totalCount > 0 && syncCount % Math.ceil(report.totalCount / 100) === 0) {
|
|
5935
|
+
console.info(
|
|
5936
|
+
`Progress: ${pct}% (${syncCount}/$${report.totalCount} files, ${fileSizePretty(syncSize)}/${fileSizePretty(
|
|
5937
|
+
report.totalSize
|
|
5938
|
+
)})`
|
|
5939
|
+
);
|
|
5940
|
+
}
|
|
5941
|
+
rdfWritten = true;
|
|
5942
|
+
} catch (err) {
|
|
5943
|
+
failedUploads += 1;
|
|
5944
|
+
console.error(`[syncHandler] Failed to upload file: ${file.fullPath}`);
|
|
5945
|
+
if (verbose) {
|
|
5946
|
+
console.error("[syncHandler] Upload error details:", err);
|
|
5947
|
+
}
|
|
5948
|
+
continue;
|
|
5910
5949
|
}
|
|
5911
|
-
rdfWritten = true;
|
|
5912
5950
|
}
|
|
5913
5951
|
const zipDeletePromise = zip ? deleteUnzipped(path) : Promise.resolve();
|
|
5914
5952
|
if (verbose && report.localNotOnRemotePathOnly.length)
|
|
@@ -5958,6 +5996,9 @@ async function syncHandler(options) {
|
|
|
5958
5996
|
if (verbose) {
|
|
5959
5997
|
console.info("");
|
|
5960
5998
|
console.info(`Sync finished \u{1F680}\u{1F680}\u{1F680}`);
|
|
5999
|
+
if (failedUploads > 0) {
|
|
6000
|
+
console.warn(`Total files failed to upload: ${failedUploads}`);
|
|
6001
|
+
}
|
|
5961
6002
|
}
|
|
5962
6003
|
} catch (err) {
|
|
5963
6004
|
console.error("Error:", err);
|