ryugi-artifacts 1.7.2 → 1.7.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/runtime/ryugi-ui.js +3 -3
- package/dist/server.cjs +39 -11
- package/dist/viewer/index.js +1 -1
- package/package.json +2 -1
package/dist/server.cjs
CHANGED
|
@@ -84619,7 +84619,7 @@ var defaults = () => ({ version: 1, artifacts: {} });
|
|
|
84619
84619
|
function isCloudRecord(value) {
|
|
84620
84620
|
if (typeof value !== "object" || value === null) return false;
|
|
84621
84621
|
const { id: id2, url, publishedAt, visibility } = value;
|
|
84622
|
-
return typeof id2 === "string" && typeof url === "string" && typeof publishedAt === "string" && isVisibility(visibility);
|
|
84622
|
+
return typeof id2 === "string" && typeof url === "string" && (typeof publishedAt === "string" || publishedAt === null) && isVisibility(visibility);
|
|
84623
84623
|
}
|
|
84624
84624
|
function normalize(raw) {
|
|
84625
84625
|
const config = defaults();
|
|
@@ -84886,6 +84886,7 @@ function withCloudRuntime(type, files) {
|
|
|
84886
84886
|
|
|
84887
84887
|
// src/server/cloud.ts
|
|
84888
84888
|
var LOGIN_STATE_TTL_MS = 10 * 60 * 1e3;
|
|
84889
|
+
var UPLOAD_CONCURRENCY = 6;
|
|
84889
84890
|
var MAX_JSON_BODY = 4096;
|
|
84890
84891
|
var CLOUD_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
84891
84892
|
var ROUTE = /^\/api\/cloud\/(status|login|logout|artifacts|publish|visibility)(?:\/([^/]+)(?:\/([^/]+))?)?$/;
|
|
@@ -84938,8 +84939,10 @@ function createCloudRoutes(options) {
|
|
|
84938
84939
|
if (!credentials) throw new SignedOut();
|
|
84939
84940
|
const headers = { Authorization: `Bearer ${credentials.token}` };
|
|
84940
84941
|
let payload;
|
|
84941
|
-
if (body instanceof
|
|
84942
|
-
|
|
84942
|
+
if (body instanceof Uint8Array) {
|
|
84943
|
+
headers["Content-Type"] = "application/octet-stream";
|
|
84944
|
+
payload = body;
|
|
84945
|
+
} else if (body) {
|
|
84943
84946
|
headers["Content-Type"] = "application/json";
|
|
84944
84947
|
payload = JSON.stringify(body);
|
|
84945
84948
|
}
|
|
@@ -84969,15 +84972,40 @@ function createCloudRoutes(options) {
|
|
|
84969
84972
|
}
|
|
84970
84973
|
const key2 = `${ref.type}/${ref.id}`;
|
|
84971
84974
|
const entry = artifactEntry(key2);
|
|
84972
|
-
const
|
|
84973
|
-
|
|
84974
|
-
|
|
84975
|
-
|
|
84976
|
-
|
|
84977
|
-
|
|
84975
|
+
const hashed = files.map((file) => ({ ...file, hash: import_node_crypto3.default.createHash("sha256").update(file.data).digest("hex") }));
|
|
84976
|
+
const byHash = new Map(hashed.map((file) => [file.hash, file.data]));
|
|
84977
|
+
const manifest = hashed.map(({ path: path17, hash }) => ({ path: path17, hash }));
|
|
84978
|
+
const version = (visibility) => ({ title: inspected.title, payload: inspected.payload, files: manifest, ...visibility ? { visibility } : {} });
|
|
84979
|
+
const create3 = async () => {
|
|
84980
|
+
const res2 = await cloudFetch("POST", "/api/artifacts", { type: ref.type, visibility: requested ?? entry.visibility ?? "private" });
|
|
84981
|
+
const created = await (await expectOk(res2)).json();
|
|
84982
|
+
updateArtifactConfig(configFile, key2, {
|
|
84983
|
+
visibility: created.visibility,
|
|
84984
|
+
cloud: { id: created.id, url: created.url, publishedAt: null, visibility: created.visibility }
|
|
84985
|
+
});
|
|
84986
|
+
return created.id;
|
|
84987
|
+
};
|
|
84988
|
+
const upload = async (id2, hashes) => {
|
|
84989
|
+
for (let i6 = 0; i6 < hashes.length; i6 += UPLOAD_CONCURRENCY) {
|
|
84990
|
+
await Promise.all(
|
|
84991
|
+
hashes.slice(i6, i6 + UPLOAD_CONCURRENCY).map(async (hash) => {
|
|
84992
|
+
const data = byHash.get(hash);
|
|
84993
|
+
if (!data) throw new CloudRefused(502, `cloud asked for a file this artifact does not have (${hash})`);
|
|
84994
|
+
await expectOk(await cloudFetch("PUT", `/api/artifacts/${id2}/blobs/${hash}`, new Uint8Array(data)));
|
|
84995
|
+
})
|
|
84996
|
+
);
|
|
84997
|
+
}
|
|
84998
|
+
};
|
|
84999
|
+
const commit = async (id2, visibility) => {
|
|
85000
|
+
const res2 = await cloudFetch("POST", `/api/artifacts/${id2}/versions`, version(visibility));
|
|
85001
|
+
if (res2.status !== 409) return res2;
|
|
85002
|
+
const { missing } = await res2.clone().json().catch(() => ({}));
|
|
85003
|
+
if (!Array.isArray(missing)) return res2;
|
|
85004
|
+
await upload(id2, missing);
|
|
85005
|
+
return cloudFetch("POST", `/api/artifacts/${id2}/versions`, version(visibility));
|
|
84978
85006
|
};
|
|
84979
|
-
let res = entry.cloud ? await
|
|
84980
|
-
if (
|
|
85007
|
+
let res = entry.cloud ? await commit(entry.cloud.id, requested) : await commit(await create3(), void 0);
|
|
85008
|
+
if (res.status === 404 && entry.cloud) res = await commit(await create3(), void 0);
|
|
84981
85009
|
const published = await (await expectOk(res)).json();
|
|
84982
85010
|
updateArtifactConfig(configFile, key2, {
|
|
84983
85011
|
visibility: published.visibility,
|