filecafe 0.4.0 → 0.4.1
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/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as updateCachePath, c as configPath, d as readConfig, f as resolveSettings, l as deleteConfig, m as VERSION, n as fetchLatestVersion, o as updateUpdateCache, p as writeConfig, r as readUpdateCache, t as CHECK_INTERVAL_MS, u as normalizeBaseUrl } from "./update-cache-
|
|
2
|
+
import { a as updateCachePath, c as configPath, d as readConfig, f as resolveSettings, l as deleteConfig, m as VERSION, n as fetchLatestVersion, o as updateUpdateCache, p as writeConfig, r as readUpdateCache, t as CHECK_INTERVAL_MS, u as normalizeBaseUrl } from "./update-cache-INu00cnB.js";
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import { execFile, spawn } from "node:child_process";
|
|
5
5
|
import { realpath, stat } from "node:fs/promises";
|
|
@@ -600,7 +600,7 @@ function isSignedTarget(value) {
|
|
|
600
600
|
function planTransfer(upload, size) {
|
|
601
601
|
const unexpected = (detail) => new ApiError(`Unexpected response when starting the upload: ${detail}.`, null);
|
|
602
602
|
const data = upload;
|
|
603
|
-
if (!isRecord(data) || typeof data.id !== "string"
|
|
603
|
+
if (!isRecord(data) || typeof data.id !== "string") throw unexpected("missing id");
|
|
604
604
|
if ("parts" in data) {
|
|
605
605
|
const { parts, part_size: partSize } = data;
|
|
606
606
|
if (typeof partSize !== "number" || !Number.isSafeInteger(partSize) || partSize <= 0) throw unexpected("invalid part_size");
|
|
@@ -732,13 +732,12 @@ async function uploadFile(options) {
|
|
|
732
732
|
}
|
|
733
733
|
});
|
|
734
734
|
});
|
|
735
|
-
return client.request("PUT", `/api/v1/uploads/${encodeURIComponent(started.id)}`,
|
|
735
|
+
return client.request("PUT", `/api/v1/uploads/${encodeURIComponent(started.id)}`, void 0, { idempotent: true });
|
|
736
736
|
}
|
|
737
737
|
/**
|
|
738
738
|
* The URL for each part of an upload, in batches of PART_URL_BATCH_SIZE. The first batch comes
|
|
739
739
|
* from the start response; later ones, and any batch older than PART_URL_MAX_AGE_MS, are fetched
|
|
740
|
-
* when a part in them is about to be uploaded. Each fetch also renews the upload
|
|
741
|
-
* latest token is the one to complete with.
|
|
740
|
+
* when a part in them is about to be uploaded. Each fetch also renews the upload's expiry.
|
|
742
741
|
*/
|
|
743
742
|
function createPartUrls(options, started, targets) {
|
|
744
743
|
const now = options.now ?? Date.now;
|
|
@@ -746,39 +745,31 @@ function createPartUrls(options, started, targets) {
|
|
|
746
745
|
fetchedAt: now(),
|
|
747
746
|
targets: Promise.resolve(targets.slice(0, PART_URL_BATCH_SIZE))
|
|
748
747
|
}]]);
|
|
749
|
-
let token = started.token;
|
|
750
748
|
const fetchBatch = async (batch) => {
|
|
751
749
|
const first = batch * PART_URL_BATCH_SIZE + 1;
|
|
752
750
|
const partNumbers = Array.from({ length: Math.min(PART_URL_BATCH_SIZE, targets.length - first + 1) }, (_, i) => first + i);
|
|
753
|
-
const response = await options.client.request("POST", `/api/v1/uploads/${encodeURIComponent(started.id)}/parts`, {
|
|
754
|
-
token,
|
|
755
|
-
part_numbers: partNumbers
|
|
756
|
-
}, { idempotent: true });
|
|
751
|
+
const response = await options.client.request("POST", `/api/v1/uploads/${encodeURIComponent(started.id)}/parts`, { part_numbers: partNumbers }, { idempotent: true });
|
|
757
752
|
const parts = isRecord(response) && Array.isArray(response.parts) ? response.parts : [];
|
|
758
753
|
const fresh = partNumbers.map((partNumber) => parts.find((part) => isRecord(part) && part.part_number === partNumber));
|
|
759
|
-
if (!
|
|
760
|
-
token = response.token;
|
|
754
|
+
if (!fresh.every(isSignedTarget)) throw new ApiError("Unexpected response when fetching upload URLs.", null);
|
|
761
755
|
return fresh.map((part) => ({
|
|
762
756
|
url: part.url,
|
|
763
757
|
headers: part.headers
|
|
764
758
|
}));
|
|
765
759
|
};
|
|
766
|
-
return {
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
},
|
|
780
|
-
token: () => token
|
|
781
|
-
};
|
|
760
|
+
return { async target(index) {
|
|
761
|
+
if (!("parts" in started)) return targets[index];
|
|
762
|
+
const batch = Math.floor(index / PART_URL_BATCH_SIZE);
|
|
763
|
+
let entry = batches.get(batch);
|
|
764
|
+
if (!entry || now() - entry.fetchedAt > PART_URL_MAX_AGE_MS) {
|
|
765
|
+
entry = {
|
|
766
|
+
fetchedAt: now(),
|
|
767
|
+
targets: fetchBatch(batch)
|
|
768
|
+
};
|
|
769
|
+
batches.set(batch, entry);
|
|
770
|
+
}
|
|
771
|
+
return (await entry.targets)[index % PART_URL_BATCH_SIZE];
|
|
772
|
+
} };
|
|
782
773
|
}
|
|
783
774
|
// src/commands/upload.ts
|
|
784
775
|
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
package/dist/update-worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as refreshUpdateCache, m as VERSION } from "./update-cache-
|
|
1
|
+
import { i as refreshUpdateCache, m as VERSION } from "./update-cache-INu00cnB.js";
|
|
2
2
|
// src/update-worker.ts
|
|
3
3
|
/**
|
|
4
4
|
* Spawned detached by the CLI to refresh the update cache, so no command ever waits on npm.
|