@mainsoft/agent-cms 0.10.2 → 0.11.0
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/CHANGELOG.md +16 -0
- package/README.md +91 -2
- package/TODO.md +6 -6
- package/UPGRADE-0.11.md +43 -0
- package/dist/agent.d.cts +1 -1
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +7 -7
- package/dist/bin.js +236 -23
- package/dist/{chunk-IU2SMWAM.js → chunk-42PW3HQ3.js} +15 -1
- package/dist/{chunk-6PB4ZCHH.js → chunk-CIMW73L3.js} +58 -1
- package/dist/{chunk-7Y6TU2UA.js → chunk-HY4ED7LT.js} +2 -2
- package/dist/{chunk-DSJETZT4.js → chunk-I3DF6DMI.js} +15 -10
- package/dist/{chunk-KAO3Z3CF.js → chunk-I5UHTAAW.js} +3 -1
- package/dist/{chunk-7SCYDG2G.js → chunk-J25IKU7C.js} +164 -28
- package/dist/{chunk-BFVBHIHV.js → chunk-J5DW3RFQ.js} +4 -1
- package/dist/{chunk-7WJIIJCI.js → chunk-LELPCGDX.js} +8 -5
- package/dist/{chunk-5ODZ2ZJF.js → chunk-NO6S7KOL.js} +1 -1
- package/dist/{chunk-5FMVVBDR.js → chunk-OLHLSSTD.js} +3 -3
- package/dist/{chunk-3OPKTBEI.js → chunk-SV3ZA6XP.js} +1 -1
- package/dist/{chunk-PEQY4N73.js → chunk-TKKTEGHL.js} +1 -0
- package/dist/{chunk-PGV2QPIL.js → chunk-WWG7XDIZ.js} +2 -0
- package/dist/cli.cjs +236 -23
- package/dist/cli.d.cts +2 -2
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +18 -16
- package/dist/client.cjs +4 -1
- package/dist/client.d.cts +14 -2
- package/dist/client.d.ts +14 -2
- package/dist/client.js +1 -1
- package/dist/{cms-pqJyowu1.d.ts → cms-A9tmLmTP.d.ts} +100 -5
- package/dist/{cms-C_vkAxYV.d.cts → cms-CaB81PPX.d.cts} +100 -5
- package/dist/config.d.cts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/{drizzle-repo-DWLD0rWe.d.ts → drizzle-repo-BXV-hFkE.d.ts} +1 -1
- package/dist/{drizzle-repo-CviH3EX7.d.cts → drizzle-repo-CblPVYnK.d.cts} +1 -1
- package/dist/errors.cjs +4 -0
- package/dist/errors.d.cts +3 -1
- package/dist/errors.d.ts +3 -1
- package/dist/errors.js +2 -2
- package/dist/frontmatter.d.cts +1 -1
- package/dist/frontmatter.d.ts +1 -1
- package/dist/http.cjs +17 -7
- package/dist/http.d.cts +2 -2
- package/dist/http.d.ts +2 -2
- package/dist/http.js +16 -15
- package/dist/image-sharp.cjs +104 -0
- package/dist/image-sharp.d.cts +47 -0
- package/dist/image-sharp.d.ts +47 -0
- package/dist/image-sharp.js +70 -0
- package/dist/index.cjs +244 -27
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +21 -21
- package/dist/mcp.cjs +9 -4
- package/dist/mcp.d.cts +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +11 -11
- package/dist/messages/en.cjs +2 -0
- package/dist/messages/en.js +1 -1
- package/dist/messages/ko.cjs +2 -0
- package/dist/messages/ko.js +2 -0
- package/dist/registry/cms-doc-editor.json +6 -1
- package/dist/registry/cms-lib.json +2 -2
- package/dist/registry/cms-media-picker.json +2 -2
- package/dist/registry/cms-media.json +1 -1
- package/dist/registry/registry.json +4 -0
- package/dist/storage-vercel-blob.cjs +199 -0
- package/dist/storage-vercel-blob.d.cts +98 -0
- package/dist/storage-vercel-blob.d.ts +98 -0
- package/dist/storage-vercel-blob.js +165 -0
- package/dist/storage.cjs +63 -3
- package/dist/storage.d.cts +27 -2
- package/dist/storage.d.ts +27 -2
- package/dist/storage.js +9 -3
- package/dist/tables.cjs +15 -1
- package/dist/tables.d.cts +160 -7
- package/dist/tables.d.ts +160 -7
- package/dist/tables.js +2 -2
- package/dist/tools.cjs +8 -3
- package/dist/tools.d.cts +1 -1
- package/dist/tools.d.ts +1 -1
- package/dist/tools.js +9 -9
- package/dist/types.cjs +5 -0
- package/dist/types.d.cts +6 -1
- package/dist/types.d.ts +6 -1
- package/dist/types.js +3 -3
- package/package.json +36 -2
|
@@ -12,27 +12,29 @@ import {
|
|
|
12
12
|
} from "./chunk-MA6VKJ3F.js";
|
|
13
13
|
import {
|
|
14
14
|
docState
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-TKKTEGHL.js";
|
|
16
|
+
import {
|
|
17
|
+
CmsError,
|
|
18
|
+
formatMessage,
|
|
19
|
+
isCmsError
|
|
20
|
+
} from "./chunk-I5UHTAAW.js";
|
|
16
21
|
import {
|
|
17
22
|
SCHEMA_VERSION
|
|
18
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-SV3ZA6XP.js";
|
|
19
24
|
import {
|
|
20
25
|
fieldChanges,
|
|
21
26
|
hunks,
|
|
22
27
|
splitLines,
|
|
23
28
|
unifiedDiff
|
|
24
29
|
} from "./chunk-AKN7SUXU.js";
|
|
25
|
-
import {
|
|
26
|
-
CmsError,
|
|
27
|
-
formatMessage,
|
|
28
|
-
isCmsError
|
|
29
|
-
} from "./chunk-KAO3Z3CF.js";
|
|
30
30
|
import {
|
|
31
31
|
ASSET_ID_RE,
|
|
32
32
|
DEFAULT_ACCEPT,
|
|
33
33
|
DEFAULT_MAX_FILE_SIZE,
|
|
34
|
+
DERIVED_PREFIX,
|
|
34
35
|
MIME_BY_EXT,
|
|
35
36
|
PART_SIZE,
|
|
37
|
+
REPLACE_PREFIX,
|
|
36
38
|
RESERVED_FOLDER,
|
|
37
39
|
THUMB_PREFIX,
|
|
38
40
|
acceptsFile,
|
|
@@ -47,8 +49,9 @@ import {
|
|
|
47
49
|
mimeOf,
|
|
48
50
|
newAssetId,
|
|
49
51
|
numberedName,
|
|
50
|
-
sniff
|
|
51
|
-
|
|
52
|
+
sniff,
|
|
53
|
+
stripJpegMetadata
|
|
54
|
+
} from "./chunk-CIMW73L3.js";
|
|
52
55
|
|
|
53
56
|
// src/net-guard.ts
|
|
54
57
|
var FetchGuardError = class extends Error {
|
|
@@ -204,6 +207,16 @@ import { z } from "zod";
|
|
|
204
207
|
var SIGN_SECONDS = 3600;
|
|
205
208
|
var MAX_THUMB_BYTES = 512 * 1024;
|
|
206
209
|
var TAG_MAX = 30;
|
|
210
|
+
var IMAGE_EXT = { webp: "webp", avif: "avif", jpeg: "jpg", png: "png" };
|
|
211
|
+
var FOREVER = "public, max-age=31536000, immutable";
|
|
212
|
+
function stamp(v) {
|
|
213
|
+
let h = 2166136261;
|
|
214
|
+
for (const c of JSON.stringify(v)) h = Math.imul(h ^ c.charCodeAt(0), 16777619);
|
|
215
|
+
return (h >>> 0).toString(36);
|
|
216
|
+
}
|
|
217
|
+
var withRev = (url, rev) => rev > 0 ? `${url}${url.includes("?") ? "&" : "?"}v=${rev}` : url;
|
|
218
|
+
var focalOf = (a) => a.focalX !== null && a.focalY !== null ? { x: a.focalX, y: a.focalY } : null;
|
|
219
|
+
var resizable = (a) => a.kind === "image" && a.mime !== "image/svg+xml" && a.mime !== "image/gif";
|
|
207
220
|
var assetId = () => z.string().regex(ASSET_ID_RE, "not a file id");
|
|
208
221
|
function humanSize(bytes) {
|
|
209
222
|
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
@@ -225,6 +238,7 @@ function createAssets(ctx) {
|
|
|
225
238
|
const names = Object.keys(media?.stores ?? {});
|
|
226
239
|
const filesUrl = (media?.filesUrl ?? "/api/cms/files").replace(/\/+$/, "");
|
|
227
240
|
const ttl = media?.linkTtlSeconds ?? 300;
|
|
241
|
+
const transforms = media?.transforms ?? null;
|
|
228
242
|
for (const n of names) {
|
|
229
243
|
const s = media.stores[n];
|
|
230
244
|
const rules = s.accept ?? media.accept ?? DEFAULT_ACCEPT;
|
|
@@ -257,11 +271,12 @@ function createAssets(ctx) {
|
|
|
257
271
|
function view(a) {
|
|
258
272
|
const cfg = media?.stores[a.store];
|
|
259
273
|
const href = `${filesUrl}/${a.id}/${encodeURIComponent(a.name)}`;
|
|
260
|
-
|
|
274
|
+
const direct = cfg?.visibility === "public" ? cfg.adapter.publicUrl(a.key) : null;
|
|
275
|
+
return { ...a, visibility: cfg?.visibility ?? "private", href, publicUrl: direct ? withRev(direct, a.rev) : null, thumbHref: a.thumbKey ? `${href}?thumb=1${a.rev ? `&v=${a.rev}` : ""}` : null };
|
|
261
276
|
}
|
|
262
277
|
const info = (a) => {
|
|
263
278
|
const v = view(a);
|
|
264
|
-
return { id: a.id, name: a.name, kind: a.kind, mime: a.mime, size: a.size, width: a.width, height: a.height, duration: a.duration, alt: a.alt, url: v.publicUrl ?? v.href, visibility: v.visibility };
|
|
279
|
+
return { id: a.id, name: a.name, kind: a.kind, mime: a.mime, size: a.size, width: a.width, height: a.height, duration: a.duration, alt: a.alt, url: v.publicUrl ?? v.href, visibility: v.visibility, focal: focalOf(a) };
|
|
265
280
|
};
|
|
266
281
|
async function load(id, o = {}) {
|
|
267
282
|
const a = ASSET_ID_RE.test(id) ? await repo.findAsset(id) : null;
|
|
@@ -304,23 +319,25 @@ function createAssets(ctx) {
|
|
|
304
319
|
}
|
|
305
320
|
async function requestUpload(actor, input) {
|
|
306
321
|
await ctx.ready();
|
|
307
|
-
const
|
|
322
|
+
const target = input.replace ? await replaceable(actor, input.replace, input) : null;
|
|
323
|
+
const store = storeOf(target ? target.store : input.store);
|
|
308
324
|
need(actor, store.name, "write");
|
|
309
|
-
const a = admit(store, input);
|
|
310
|
-
const
|
|
325
|
+
const a = target ? admit(store, { name: target.name, mime: target.mime, size: input.size, folder: target.folder }) : admit(store, input);
|
|
326
|
+
const id = newAssetId();
|
|
327
|
+
const free = target ? { key: `${REPLACE_PREFIX}${target.id}/${id}${extOf(target.name) ? `.${extOf(target.name)}` : ""}`, name: target.name } : await freeKey(store, a.folder, a.name);
|
|
311
328
|
const put2 = { mime: a.mime, disposition: dispositionFor(free.name, a.mime) };
|
|
312
329
|
const who = ctx.actorRef(actor);
|
|
313
330
|
let upload;
|
|
314
331
|
let uploadId = null;
|
|
315
|
-
if (input.size <= PART_SIZE) {
|
|
316
|
-
const signed = await store.cfg.adapter.presignPut(free.key, { ...put2, expires: SIGN_SECONDS });
|
|
332
|
+
if (input.size <= PART_SIZE || store.cfg.adapter.multipart === false) {
|
|
333
|
+
const signed = await store.cfg.adapter.presignPut(free.key, { ...put2, expires: SIGN_SECONDS, size: input.size });
|
|
317
334
|
upload = { kind: "single", url: signed.url, headers: signed.headers };
|
|
318
335
|
} else {
|
|
319
336
|
uploadId = await store.cfg.adapter.createMultipart(free.key, put2);
|
|
320
337
|
upload = { kind: "multipart", partSize: PART_SIZE, partCount: Math.ceil(input.size / PART_SIZE) };
|
|
321
338
|
}
|
|
322
339
|
const row = await repo.insertAsset({
|
|
323
|
-
id
|
|
340
|
+
id,
|
|
324
341
|
store: store.name,
|
|
325
342
|
key: free.key,
|
|
326
343
|
folder: a.folder,
|
|
@@ -368,9 +385,107 @@ function createAssets(ctx) {
|
|
|
368
385
|
});
|
|
369
386
|
if (a.thumbKey) await adapter.delete(a.thumbKey).catch(() => {
|
|
370
387
|
});
|
|
388
|
+
await dropDerived(a);
|
|
371
389
|
}
|
|
372
390
|
await repo.deleteAsset(a.id);
|
|
373
391
|
}
|
|
392
|
+
async function replaceable(actor, id, input) {
|
|
393
|
+
const t = await load(id);
|
|
394
|
+
need(actor, t.store, "delete");
|
|
395
|
+
if (t.kind === "folder" || mimeOf(cleanName(input.name), input.mime) !== t.mime) throw fail("asset_replace_type", { name: input.name, mime: t.mime });
|
|
396
|
+
return t;
|
|
397
|
+
}
|
|
398
|
+
async function replaced(actor, t, now) {
|
|
399
|
+
const adapter = storeOf(t.store).cfg.adapter;
|
|
400
|
+
if (t.thumbKey) await adapter.delete(t.thumbKey).catch(() => {
|
|
401
|
+
});
|
|
402
|
+
await dropDerived(t);
|
|
403
|
+
const row = await repo.updateAsset(t.id, { ...now, thumbKey: null, rev: t.rev + 1, updatedAt: ctx.nowIso() });
|
|
404
|
+
ctx.audit(actor, "asset.replace", { detail: { id: t.id, store: t.store, key: t.key, size: now.size, was: t.size } });
|
|
405
|
+
return row;
|
|
406
|
+
}
|
|
407
|
+
async function replace(actor, id, input) {
|
|
408
|
+
await ctx.ready();
|
|
409
|
+
const t = await replaceable(actor, id, { name: (await load(id)).name, mime: input.mime });
|
|
410
|
+
const store = storeOf(t.store);
|
|
411
|
+
const bytes = media?.stripMetadata && t.mime === "image/jpeg" ? stripJpegMetadata(input.bytes) : input.bytes;
|
|
412
|
+
admit(store, { name: t.name, mime: t.mime, size: bytes.length, folder: t.folder });
|
|
413
|
+
if (!contentMatches(t.mime, bytes.subarray(0, 4096))) throw fail("asset_type_mismatch", { name: t.name, mime: t.mime });
|
|
414
|
+
await scanned(actor, { store: t.store, key: t.key, name: t.name, mime: t.mime, size: bytes.length, bytes }, null);
|
|
415
|
+
await store.cfg.adapter.put(t.key, bytes, { mime: t.mime, disposition: dispositionFor(t.name, t.mime) });
|
|
416
|
+
const given = dims(input);
|
|
417
|
+
const read = t.kind === "image" && !given.width ? imageSize(bytes) : null;
|
|
418
|
+
return view(await serverThumb(await replaced(actor, t, { size: bytes.length, width: given.width ?? read?.width ?? null, height: given.height ?? read?.height ?? null, duration: given.duration }), bytes));
|
|
419
|
+
}
|
|
420
|
+
const made = /* @__PURE__ */ new Set();
|
|
421
|
+
const making = /* @__PURE__ */ new Map();
|
|
422
|
+
const waiting = [];
|
|
423
|
+
let active = 0;
|
|
424
|
+
const jobOf = (a, p) => ({ width: p.width ?? null, height: p.height ?? null, fit: p.fit ?? "inside", format: p.format ?? transforms.format, quality: p.quality ?? null, focal: focalOf(a) });
|
|
425
|
+
async function sized(a, size) {
|
|
426
|
+
const preset = transforms?.presets[size];
|
|
427
|
+
if (!transforms || !preset) throw fail("unknown_image_size", { size });
|
|
428
|
+
if (!resizable(a) || a.size > (transforms.maxInputBytes ?? 40 * 1024 * 1024)) return null;
|
|
429
|
+
const job = jobOf(a, preset);
|
|
430
|
+
const key = `${DERIVED_PREFIX}${a.id}/${size}-${stamp([a.rev, a.size, job])}.${IMAGE_EXT[job.format]}`;
|
|
431
|
+
if (made.has(key)) return key;
|
|
432
|
+
let work = making.get(key);
|
|
433
|
+
if (!work) {
|
|
434
|
+
work = (async () => {
|
|
435
|
+
const adapter = storeOf(a.store).cfg.adapter;
|
|
436
|
+
if (await adapter.head(key)) return key;
|
|
437
|
+
if (active >= (transforms.concurrency ?? 4)) await new Promise((go) => waiting.push(go));
|
|
438
|
+
else active++;
|
|
439
|
+
try {
|
|
440
|
+
const bytes = await adapter.readStart(a.key, a.size);
|
|
441
|
+
if (!bytes) return null;
|
|
442
|
+
const out = await transforms.make(bytes, job);
|
|
443
|
+
await adapter.put(key, out.bytes, { mime: `image/${job.format}`, cacheControl: FOREVER });
|
|
444
|
+
return key;
|
|
445
|
+
} finally {
|
|
446
|
+
const next = waiting.shift();
|
|
447
|
+
if (next) next();
|
|
448
|
+
else active--;
|
|
449
|
+
}
|
|
450
|
+
})().then((k) => (k && made.add(k), k)).catch((e) => (ctx.warn(`image-size-${a.id}-${size}`, `could not make size "${size}" of ${a.key}: ${e instanceof Error ? e.message : String(e)}`), null)).finally(() => making.delete(key));
|
|
451
|
+
making.set(key, work);
|
|
452
|
+
}
|
|
453
|
+
let timer;
|
|
454
|
+
const late = new Promise((r) => timer = setTimeout(() => r(null), transforms.timeoutMs ?? 1e4));
|
|
455
|
+
try {
|
|
456
|
+
return await Promise.race([work, late]);
|
|
457
|
+
} finally {
|
|
458
|
+
clearTimeout(timer);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
async function dropDerived(a) {
|
|
462
|
+
const adapter = media?.stores[a.store]?.adapter;
|
|
463
|
+
if (!adapter || !transforms) return;
|
|
464
|
+
try {
|
|
465
|
+
let cursor = null;
|
|
466
|
+
do {
|
|
467
|
+
const page = await adapter.list({ prefix: `${DERIVED_PREFIX}${a.id}/`, cursor, limit: 200 });
|
|
468
|
+
for (const o of page.objects) {
|
|
469
|
+
await adapter.delete(o.key).catch(() => {
|
|
470
|
+
});
|
|
471
|
+
made.delete(o.key);
|
|
472
|
+
}
|
|
473
|
+
cursor = page.cursor;
|
|
474
|
+
} while (cursor);
|
|
475
|
+
} catch {
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
async function serverThumb(row, bytes) {
|
|
479
|
+
if (!transforms || !resizable(row) || bytes.length > (transforms.maxInputBytes ?? 40 * 1024 * 1024)) return row;
|
|
480
|
+
try {
|
|
481
|
+
const out = await transforms.make(bytes, { width: 480, height: 480, fit: "inside", format: "webp", quality: null, focal: null });
|
|
482
|
+
const key = `${THUMB_PREFIX}${row.id}.webp`;
|
|
483
|
+
await storeOf(row.store).cfg.adapter.put(key, out.bytes, { mime: "image/webp", cacheControl: FOREVER });
|
|
484
|
+
return await repo.updateAsset(row.id, { thumbKey: key }) ?? row;
|
|
485
|
+
} catch {
|
|
486
|
+
return row;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
374
489
|
const dims = (o) => {
|
|
375
490
|
const int = (v) => typeof v === "number" && Number.isFinite(v) && v > 0 && v < 1e5 ? Math.round(v) : null;
|
|
376
491
|
return { width: int(o.width), height: int(o.height), duration: typeof o.duration === "number" && Number.isFinite(o.duration) && o.duration >= 0 ? o.duration : null };
|
|
@@ -405,6 +520,19 @@ function createAssets(ctx) {
|
|
|
405
520
|
});
|
|
406
521
|
const given = dims(meta);
|
|
407
522
|
const read = a.kind === "image" && !given.width ? imageSize(start) : null;
|
|
523
|
+
const settle = (key, name) => adapter.settle?.(key, { mime: a.mime, disposition: dispositionFor(name, a.mime) });
|
|
524
|
+
if (a.key.startsWith(REPLACE_PREFIX)) {
|
|
525
|
+
const t = await repo.findAsset(a.key.slice(REPLACE_PREFIX.length).split("/")[0]);
|
|
526
|
+
if (!t || t.status !== "ready" || !canAsset(actor, t.store, "delete")) {
|
|
527
|
+
await discard({ ...a, uploadId: null });
|
|
528
|
+
throw fail("asset_not_found", { id });
|
|
529
|
+
}
|
|
530
|
+
await adapter.copy(a.key, t.key);
|
|
531
|
+
await settle(t.key, t.name);
|
|
532
|
+
await discard({ ...a, uploadId: null });
|
|
533
|
+
return view(await replaced(actor, t, { size: head.size, width: given.width ?? read?.width ?? null, height: given.height ?? read?.height ?? null, duration: given.duration }));
|
|
534
|
+
}
|
|
535
|
+
await settle(a.key, a.name);
|
|
408
536
|
const row = await repo.updateAsset(a.id, { status: "ready", uploadId: null, width: given.width ?? read?.width ?? null, height: given.height ?? read?.height ?? null, duration: given.duration, updatedAt: ctx.nowIso() });
|
|
409
537
|
ctx.audit(actor, "asset.upload", { detail: { id: a.id, store: a.store, key: a.key, size: a.size } });
|
|
410
538
|
return view(row);
|
|
@@ -430,6 +558,7 @@ function createAssets(ctx) {
|
|
|
430
558
|
await ctx.ready();
|
|
431
559
|
const store = storeOf(input.store);
|
|
432
560
|
need(actor, store.name, "write");
|
|
561
|
+
if (media?.stripMetadata && mimeOf(cleanName(input.name), input.mime) === "image/jpeg") input = { ...input, bytes: stripJpegMetadata(input.bytes) };
|
|
433
562
|
const a = admit(store, { ...input, size: input.bytes.length });
|
|
434
563
|
if (!contentMatches(a.mime, input.bytes.subarray(0, 4096))) throw fail("asset_type_mismatch", { name: a.name, mime: a.mime });
|
|
435
564
|
const free = await freeKey(store, a.folder, a.name);
|
|
@@ -463,7 +592,7 @@ function createAssets(ctx) {
|
|
|
463
592
|
updatedAt: ctx.nowIso()
|
|
464
593
|
});
|
|
465
594
|
ctx.audit(actor, "asset.upload", { detail: { id: row.id, store: row.store, key: row.key, size: row.size } });
|
|
466
|
-
return view(row);
|
|
595
|
+
return view(await serverThumb(row, input.bytes));
|
|
467
596
|
}
|
|
468
597
|
async function importFromUrl(actor, input) {
|
|
469
598
|
const store = storeOf(input.store);
|
|
@@ -574,7 +703,10 @@ function createAssets(ctx) {
|
|
|
574
703
|
async function update(actor, id, patch) {
|
|
575
704
|
const a = await load(id);
|
|
576
705
|
need(actor, a.store, "write");
|
|
577
|
-
const
|
|
706
|
+
const unit = (v) => Math.round(Math.min(1, Math.max(0, Number(v) || 0)) * 1e3) / 1e3;
|
|
707
|
+
const focal = patch.focal === void 0 ? {} : patch.focal === null || a.kind !== "image" ? { focalX: null, focalY: null } : { focalX: unit(patch.focal.x), focalY: unit(patch.focal.y) };
|
|
708
|
+
const row = await repo.updateAsset(a.id, { ...patch.alt !== void 0 ? { alt: String(patch.alt).trim().slice(0, 500) } : {}, ...patch.tags !== void 0 ? { tags: cleanTags(patch.tags) } : {}, ...focal, updatedAt: ctx.nowIso() });
|
|
709
|
+
if ("focalX" in focal && (focal.focalX !== a.focalX || focal.focalY !== a.focalY)) await dropDerived(a);
|
|
578
710
|
return view(row);
|
|
579
711
|
}
|
|
580
712
|
async function move(actor, id, to) {
|
|
@@ -644,8 +776,9 @@ function createAssets(ctx) {
|
|
|
644
776
|
const a = await load(id);
|
|
645
777
|
const store = storeOf(a.store);
|
|
646
778
|
if (store.cfg.visibility === "private" || store.cfg.access?.read) need(actor, a.store, "read");
|
|
647
|
-
const key = o.thumb && a.thumbKey ? a.thumbKey : a.key;
|
|
648
|
-
const
|
|
779
|
+
const key = o.thumb && a.thumbKey ? a.thumbKey : o.size && !o.thumb ? await sized(a, o.size) ?? a.key : a.key;
|
|
780
|
+
const plain = store.cfg.visibility === "public" && !o.download ? store.cfg.adapter.publicUrl(key) : null;
|
|
781
|
+
const direct = plain && !key.startsWith(DERIVED_PREFIX) ? withRev(plain, a.rev) : plain;
|
|
649
782
|
return { url: direct ?? await store.cfg.adapter.presignGet(key, { expires: ttl, download: o.download ? a.name : null }), visibility: store.cfg.visibility, ttl };
|
|
650
783
|
}
|
|
651
784
|
async function cleanup(o = {}) {
|
|
@@ -725,7 +858,9 @@ function createAssets(ctx) {
|
|
|
725
858
|
return Object.fromEntries(rows.filter((a) => a.status === "ready" && media.stores[a.store]).map((a) => [a.id, info(a)]));
|
|
726
859
|
}
|
|
727
860
|
function imageUrl(asset, o) {
|
|
728
|
-
|
|
861
|
+
if (asset.kind !== "image" || asset.mime === "image/svg+xml") return asset.url;
|
|
862
|
+
if (o.size && transforms?.presets[o.size] && asset.mime !== "image/gif") return `${filesUrl}/${asset.id}/${encodeURIComponent(asset.name)}?size=${encodeURIComponent(o.size)}`;
|
|
863
|
+
return media?.imageUrl && o.width ? media.imageUrl({ url: asset.url, width: o.width, asset }) : asset.url;
|
|
729
864
|
}
|
|
730
865
|
async function scanned(actor, f, adapter) {
|
|
731
866
|
if (!media?.scan) return;
|
|
@@ -936,9 +1071,9 @@ function createAssets(ctx) {
|
|
|
936
1071
|
if (!media) return null;
|
|
937
1072
|
const stores = names.filter((n) => canAsset(actor, n, "read")).map((n) => {
|
|
938
1073
|
const cfg = media.stores[n];
|
|
939
|
-
return { name: n, label: cfg.label ?? n, visibility: cfg.visibility, ...rulesOf(cfg), can: { write: canAsset(actor, n, "write"), delete: canAsset(actor, n, "delete"), browse: canBrowse(actor, n) } };
|
|
1074
|
+
return { name: n, label: cfg.label ?? n, visibility: cfg.visibility, ...rulesOf(cfg), parts: cfg.adapter.multipart !== false, can: { write: canAsset(actor, n, "write"), delete: canAsset(actor, n, "delete"), browse: canBrowse(actor, n) } };
|
|
940
1075
|
});
|
|
941
|
-
return stores.length ? { stores, partSize: PART_SIZE } : null;
|
|
1076
|
+
return stores.length ? { stores, partSize: PART_SIZE, stripMetadata: !!media.stripMetadata, sizes: Object.keys(transforms?.presets ?? {}) } : null;
|
|
942
1077
|
}
|
|
943
1078
|
return {
|
|
944
1079
|
enabled: !!media && names.length > 0,
|
|
@@ -952,6 +1087,7 @@ function createAssets(ctx) {
|
|
|
952
1087
|
abortUpload,
|
|
953
1088
|
setThumb,
|
|
954
1089
|
put,
|
|
1090
|
+
replace,
|
|
955
1091
|
import: importFromUrl,
|
|
956
1092
|
list,
|
|
957
1093
|
folders,
|
|
@@ -2645,17 +2781,17 @@ ${h.added.join("\n")}`).digest("hex").slice(0, 12);
|
|
|
2645
2781
|
const t = Date.now();
|
|
2646
2782
|
if (index.built && !index.dirty && t - index.checkedAt > refreshMs) {
|
|
2647
2783
|
index.checkedAt = t;
|
|
2648
|
-
const
|
|
2649
|
-
if (
|
|
2784
|
+
const stamp2 = await repo.changeStamp().catch(() => index.stamp);
|
|
2785
|
+
if (stamp2 !== index.stamp) index.dirty = true;
|
|
2650
2786
|
}
|
|
2651
2787
|
if (index.built && !index.dirty) return index.built;
|
|
2652
2788
|
if (!index.building) {
|
|
2653
2789
|
index.dirty = false;
|
|
2654
2790
|
index.building = (async () => {
|
|
2655
|
-
const
|
|
2791
|
+
const stamp2 = await repo.changeStamp();
|
|
2656
2792
|
const built = await buildIndex();
|
|
2657
2793
|
index.built = built;
|
|
2658
|
-
index.stamp =
|
|
2794
|
+
index.stamp = stamp2;
|
|
2659
2795
|
index.checkedAt = Date.now();
|
|
2660
2796
|
return built;
|
|
2661
2797
|
})().catch((err) => {
|
|
@@ -216,7 +216,10 @@ function createRestClient(opts) {
|
|
|
216
216
|
/** Address of a file by its key (files the CMS has no row for). */
|
|
217
217
|
storeFileUrl: (store, key, o = {}) => `${base}/stores/${enc(store)}/files/_open?key=${enc(key)}${o.download ? "&download=1" : ""}`,
|
|
218
218
|
/** Address of a file through the CMS route (`thumb`: its small picture). */
|
|
219
|
-
fileUrl: (a, o = {}) =>
|
|
219
|
+
fileUrl: (a, o = {}) => {
|
|
220
|
+
const query = [o.thumb ? "thumb=1" : o.download ? "download=1" : o.size ? `size=${enc(o.size)}` : "", a.rev ? `v=${a.rev}` : ""].filter(Boolean).join("&");
|
|
221
|
+
return `${base}/files/${enc(a.id)}/${enc(a.name)}${query ? `?${query}` : ""}`;
|
|
222
|
+
},
|
|
220
223
|
audit: (q = {}) => req("GET", "/audit", { query: q })
|
|
221
224
|
};
|
|
222
225
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
LEGACY_COLUMNS,
|
|
3
3
|
defaultTables
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import {
|
|
6
|
-
SCHEMA_VERSION
|
|
7
|
-
} from "./chunk-3OPKTBEI.js";
|
|
4
|
+
} from "./chunk-42PW3HQ3.js";
|
|
8
5
|
import {
|
|
9
6
|
CmsError
|
|
10
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-I5UHTAAW.js";
|
|
8
|
+
import {
|
|
9
|
+
SCHEMA_VERSION
|
|
10
|
+
} from "./chunk-SV3ZA6XP.js";
|
|
11
11
|
|
|
12
12
|
// src/drizzle-repo.ts
|
|
13
13
|
import { and, asc, desc, eq, gte, inArray, isNotNull, isNull, lt, lte, ne, notInArray, or, sql } from "drizzle-orm";
|
|
@@ -110,6 +110,9 @@ var DrizzleRepo = class _DrizzleRepo {
|
|
|
110
110
|
alt: r.alt,
|
|
111
111
|
tags: r.tags ?? [],
|
|
112
112
|
thumbKey: r.thumbKey,
|
|
113
|
+
focalX: r.focalX ?? null,
|
|
114
|
+
focalY: r.focalY ?? null,
|
|
115
|
+
rev: r.rev ?? 0,
|
|
113
116
|
status: r.status,
|
|
114
117
|
uploadId: r.uploadId,
|
|
115
118
|
createdBy: r.createdBy,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
VERSION
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-NO6S7KOL.js";
|
|
4
4
|
import {
|
|
5
5
|
CMS_TOOL_NAMES,
|
|
6
6
|
runTool,
|
|
7
7
|
toolsFor
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-I3DF6DMI.js";
|
|
9
9
|
import {
|
|
10
10
|
coreOf
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-J25IKU7C.js";
|
|
12
12
|
|
|
13
13
|
// src/mcp.ts
|
|
14
14
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
@@ -55,6 +55,8 @@ var en = {
|
|
|
55
55
|
import_blocked: "That address cannot be fetched",
|
|
56
56
|
import_failed: "Could not fetch the file ({reason})",
|
|
57
57
|
asset_rejected: "This file did not pass the check",
|
|
58
|
+
asset_replace_type: "A file can only be replaced by one of the same type ({mime})",
|
|
59
|
+
unknown_image_size: "There is no image size named \u201C{size}\u201D",
|
|
58
60
|
asset_missing: "The file {id} does not exist",
|
|
59
61
|
asset_wrong_kind: "The file {id} is not a kind this field takes",
|
|
60
62
|
asset_alt_missing: "The image on line {line} has no alt text",
|