@mindstudio-ai/remy 0.1.237 → 0.1.239
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/headless.js +15 -7
- package/dist/index.js +15 -7
- package/package.json +1 -1
package/dist/headless.js
CHANGED
|
@@ -7569,14 +7569,15 @@ function filenameFromUrl(url) {
|
|
|
7569
7569
|
return `upload-${Date.now()}`;
|
|
7570
7570
|
}
|
|
7571
7571
|
}
|
|
7572
|
-
function resolveUniqueFilename(name) {
|
|
7573
|
-
|
|
7572
|
+
function resolveUniqueFilename(name, claimed) {
|
|
7573
|
+
const isFree = (candidate) => !claimed.has(candidate) && !existsSync(join(UPLOADS_DIR, candidate));
|
|
7574
|
+
if (isFree(name)) {
|
|
7574
7575
|
return name;
|
|
7575
7576
|
}
|
|
7576
7577
|
const ext = extname(name);
|
|
7577
7578
|
const base = name.slice(0, name.length - ext.length);
|
|
7578
7579
|
let counter = 1;
|
|
7579
|
-
while (
|
|
7580
|
+
while (!isFree(`${base}-${counter}${ext}`)) {
|
|
7580
7581
|
counter++;
|
|
7581
7582
|
}
|
|
7582
7583
|
return `${base}-${counter}${ext}`;
|
|
@@ -7592,11 +7593,18 @@ async function persistAttachments(attachments) {
|
|
|
7592
7593
|
return { documents: [], images: [] };
|
|
7593
7594
|
}
|
|
7594
7595
|
mkdirSync(UPLOADS_DIR, { recursive: true });
|
|
7596
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
7597
|
+
const names = nonVoice.map((att) => {
|
|
7598
|
+
const name = resolveUniqueFilename(
|
|
7599
|
+
att.filename || filenameFromUrl(att.url),
|
|
7600
|
+
claimed
|
|
7601
|
+
);
|
|
7602
|
+
claimed.add(name);
|
|
7603
|
+
return name;
|
|
7604
|
+
});
|
|
7595
7605
|
const results = await Promise.allSettled(
|
|
7596
|
-
nonVoice.map(async (att) => {
|
|
7597
|
-
const name =
|
|
7598
|
-
att.filename || filenameFromUrl(att.url)
|
|
7599
|
-
);
|
|
7606
|
+
nonVoice.map(async (att, i) => {
|
|
7607
|
+
const name = names[i];
|
|
7600
7608
|
const localPath = join(UPLOADS_DIR, name);
|
|
7601
7609
|
const res = await fetch(att.url, {
|
|
7602
7610
|
signal: AbortSignal.timeout(3e4)
|
package/dist/index.js
CHANGED
|
@@ -8392,14 +8392,15 @@ function filenameFromUrl(url) {
|
|
|
8392
8392
|
return `upload-${Date.now()}`;
|
|
8393
8393
|
}
|
|
8394
8394
|
}
|
|
8395
|
-
function resolveUniqueFilename(name) {
|
|
8396
|
-
|
|
8395
|
+
function resolveUniqueFilename(name, claimed) {
|
|
8396
|
+
const isFree = (candidate) => !claimed.has(candidate) && !existsSync(join(UPLOADS_DIR, candidate));
|
|
8397
|
+
if (isFree(name)) {
|
|
8397
8398
|
return name;
|
|
8398
8399
|
}
|
|
8399
8400
|
const ext = extname(name);
|
|
8400
8401
|
const base = name.slice(0, name.length - ext.length);
|
|
8401
8402
|
let counter = 1;
|
|
8402
|
-
while (
|
|
8403
|
+
while (!isFree(`${base}-${counter}${ext}`)) {
|
|
8403
8404
|
counter++;
|
|
8404
8405
|
}
|
|
8405
8406
|
return `${base}-${counter}${ext}`;
|
|
@@ -8414,11 +8415,18 @@ async function persistAttachments(attachments) {
|
|
|
8414
8415
|
return { documents: [], images: [] };
|
|
8415
8416
|
}
|
|
8416
8417
|
mkdirSync(UPLOADS_DIR, { recursive: true });
|
|
8418
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
8419
|
+
const names = nonVoice.map((att) => {
|
|
8420
|
+
const name = resolveUniqueFilename(
|
|
8421
|
+
att.filename || filenameFromUrl(att.url),
|
|
8422
|
+
claimed
|
|
8423
|
+
);
|
|
8424
|
+
claimed.add(name);
|
|
8425
|
+
return name;
|
|
8426
|
+
});
|
|
8417
8427
|
const results = await Promise.allSettled(
|
|
8418
|
-
nonVoice.map(async (att) => {
|
|
8419
|
-
const name =
|
|
8420
|
-
att.filename || filenameFromUrl(att.url)
|
|
8421
|
-
);
|
|
8428
|
+
nonVoice.map(async (att, i) => {
|
|
8429
|
+
const name = names[i];
|
|
8422
8430
|
const localPath = join(UPLOADS_DIR, name);
|
|
8423
8431
|
const res = await fetch(att.url, {
|
|
8424
8432
|
signal: AbortSignal.timeout(3e4)
|