trajectories-sh 1.25.0 → 1.25.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
|
@@ -708,7 +708,7 @@ async function uploadTrajectoryAction(pathArg, opts) {
|
|
|
708
708
|
);
|
|
709
709
|
}
|
|
710
710
|
if (isZip) {
|
|
711
|
-
const { uploadZip } = await import("./upload-
|
|
711
|
+
const { uploadZip } = await import("./upload-OW7RWQVX.js");
|
|
712
712
|
const slug2 = opts.slug ?? pathArg.replace(/\.zip$/i, "").replace(/\/+$/, "").split("/").pop();
|
|
713
713
|
console.log(chalk.bold(`
|
|
714
714
|
Uploading ZIP ${pathArg} \u2192 ${chalk.cyan(slug2)}
|
|
@@ -737,7 +737,7 @@ async function uploadTrajectoryAction(pathArg, opts) {
|
|
|
737
737
|
Uploading trajectory ${pathArg} \u2192 ${chalk.cyan(slug)}
|
|
738
738
|
`));
|
|
739
739
|
try {
|
|
740
|
-
const { uploadJob } = await import("./upload-
|
|
740
|
+
const { uploadJob } = await import("./upload-OW7RWQVX.js");
|
|
741
741
|
const result = await uploadJob(pathArg, {
|
|
742
742
|
slug,
|
|
743
743
|
name: opts.name
|
|
@@ -9,9 +9,27 @@ import {
|
|
|
9
9
|
getAuthHeader
|
|
10
10
|
} from "./chunk-ERO5HP43.js";
|
|
11
11
|
|
|
12
|
+
// src/converted-image-paths.ts
|
|
13
|
+
import { dirname, resolve } from "path";
|
|
14
|
+
function rewriteConvertedImagePaths(value, trajectoryPath, converted) {
|
|
15
|
+
if (!value || typeof value !== "object") return;
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
for (const item of value) rewriteConvertedImagePaths(item, trajectoryPath, converted);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const object = value;
|
|
21
|
+
if (object.type === "image" && object.source && typeof object.source === "object") {
|
|
22
|
+
const source = object.source;
|
|
23
|
+
if (typeof source.path === "string" && converted.has(resolve(dirname(trajectoryPath), source.path))) {
|
|
24
|
+
source.path = source.path.replace(/\.png$/i, ".webp");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const item of Object.values(object)) rewriteConvertedImagePaths(item, trajectoryPath, converted);
|
|
28
|
+
}
|
|
29
|
+
|
|
12
30
|
// src/upload.ts
|
|
13
31
|
import { readdirSync, statSync, readFileSync, writeFileSync, mkdirSync, copyFileSync, unlinkSync } from "fs";
|
|
14
|
-
import { join, relative
|
|
32
|
+
import { join, relative } from "path";
|
|
15
33
|
import { tmpdir } from "os";
|
|
16
34
|
import { randomBytes, createHash } from "crypto";
|
|
17
35
|
var SKIP = /* @__PURE__ */ new Set(["__pycache__", ".DS_Store", ".git", "node_modules"]);
|
|
@@ -78,7 +96,7 @@ async function uploadZip(zipPath, opts) {
|
|
|
78
96
|
console.log(" Uploading ZIP via resumable upload...");
|
|
79
97
|
const { createReadStream } = await import("fs");
|
|
80
98
|
const tus = await import("tus-js-client");
|
|
81
|
-
await new Promise((
|
|
99
|
+
await new Promise((resolve2, reject) => {
|
|
82
100
|
const fileStream = createReadStream(zipPath);
|
|
83
101
|
const upload = new tus.Upload(fileStream, {
|
|
84
102
|
endpoint: `${uploadInfo.supabase_url}/storage/v1/upload/resumable`,
|
|
@@ -107,7 +125,7 @@ async function uploadZip(zipPath, opts) {
|
|
|
107
125
|
},
|
|
108
126
|
onSuccess() {
|
|
109
127
|
console.log(` \u2191 100% \u2014 ZIP uploaded to storage.`);
|
|
110
|
-
|
|
128
|
+
resolve2();
|
|
111
129
|
}
|
|
112
130
|
});
|
|
113
131
|
upload.start();
|
|
@@ -204,6 +222,7 @@ async function convertToWebP(dir) {
|
|
|
204
222
|
const prevConcurrency = sharp.concurrency();
|
|
205
223
|
sharp.concurrency(1);
|
|
206
224
|
sharp.cache({ memory: 0, files: 0, items: 0 });
|
|
225
|
+
const convertedPaths = /* @__PURE__ */ new Map();
|
|
207
226
|
let converted = 0;
|
|
208
227
|
let savedBytes = 0;
|
|
209
228
|
let processed = 0;
|
|
@@ -216,6 +235,7 @@ async function convertToWebP(dir) {
|
|
|
216
235
|
const origSize = statSync(srcPath).size;
|
|
217
236
|
const newSize = statSync(webpPath).size;
|
|
218
237
|
if (newSize < origSize) {
|
|
238
|
+
convertedPaths.set(srcPath, webpPath);
|
|
219
239
|
unlinkSync(srcPath);
|
|
220
240
|
savedBytes += origSize - newSize;
|
|
221
241
|
converted++;
|
|
@@ -241,20 +261,11 @@ async function convertToWebP(dir) {
|
|
|
241
261
|
const trajFiles = collectFiles(tmpDir).files.filter((f) => f.relPath.endsWith("trajectory.json"));
|
|
242
262
|
for (const tf of trajFiles) {
|
|
243
263
|
try {
|
|
244
|
-
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
statSync(webpPath);
|
|
250
|
-
return `screenshots/${name}.webp`;
|
|
251
|
-
} catch {
|
|
252
|
-
return match;
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
if (content !== original) {
|
|
256
|
-
writeFileSync(tf.absPath, content);
|
|
257
|
-
}
|
|
264
|
+
const original = readFileSync(tf.absPath, "utf-8");
|
|
265
|
+
const trajectory = JSON.parse(original);
|
|
266
|
+
const before = JSON.stringify(trajectory);
|
|
267
|
+
rewriteConvertedImagePaths(trajectory, tf.absPath, convertedPaths);
|
|
268
|
+
if (JSON.stringify(trajectory) !== before) writeFileSync(tf.absPath, JSON.stringify(trajectory));
|
|
258
269
|
} catch {
|
|
259
270
|
}
|
|
260
271
|
}
|
|
@@ -673,6 +684,7 @@ function truncate(s, n) {
|
|
|
673
684
|
}
|
|
674
685
|
export {
|
|
675
686
|
collectFiles,
|
|
687
|
+
convertToWebP,
|
|
676
688
|
uploadJob,
|
|
677
689
|
uploadZip
|
|
678
690
|
};
|