@ikas/component-cli 1.4.0-beta.30 → 1.4.0-beta.32
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/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +33 -0
- package/dist/commands/dev.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -26
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/editor-action-client.d.ts +1 -1
- package/dist/utils/editor-action-client.d.ts.map +1 -1
- package/dist/utils/editor-action-client.js +8 -23
- package/dist/utils/editor-action-client.js.map +1 -1
- package/dist/utils/websocket-server.d.ts +22 -3
- package/dist/utils/websocket-server.d.ts.map +1 -1
- package/dist/utils/websocket-server.js +14 -0
- package/dist/utils/websocket-server.js.map +1 -1
- package/package.json +1 -1
- package/dist/commands/add-sections-to-page.d.ts +0 -3
- package/dist/commands/add-sections-to-page.d.ts.map +0 -1
- package/dist/commands/add-sections-to-page.js +0 -39
- package/dist/commands/add-sections-to-page.js.map +0 -1
- package/dist/commands/create-page.d.ts +0 -3
- package/dist/commands/create-page.d.ts.map +0 -1
- package/dist/commands/create-page.js +0 -31
- package/dist/commands/create-page.js.map +0 -1
- package/dist/commands/create.d.ts +0 -4
- package/dist/commands/create.d.ts.map +0 -1
- package/dist/commands/create.js +0 -228
- package/dist/commands/create.js.map +0 -1
- package/dist/commands/get-component-props.d.ts +0 -3
- package/dist/commands/get-component-props.d.ts.map +0 -1
- package/dist/commands/get-component-props.js +0 -32
- package/dist/commands/get-component-props.js.map +0 -1
- package/dist/commands/get-page-by-type.d.ts +0 -3
- package/dist/commands/get-page-by-type.d.ts.map +0 -1
- package/dist/commands/get-page-by-type.js +0 -25
- package/dist/commands/get-page-by-type.js.map +0 -1
- package/dist/commands/get-section-values.d.ts +0 -3
- package/dist/commands/get-section-values.d.ts.map +0 -1
- package/dist/commands/get-section-values.js +0 -39
- package/dist/commands/get-section-values.js.map +0 -1
- package/dist/commands/list-entities.d.ts +0 -3
- package/dist/commands/list-entities.d.ts.map +0 -1
- package/dist/commands/list-entities.js +0 -32
- package/dist/commands/list-entities.js.map +0 -1
- package/dist/commands/list-page-sections.d.ts +0 -3
- package/dist/commands/list-page-sections.d.ts.map +0 -1
- package/dist/commands/list-page-sections.js +0 -25
- package/dist/commands/list-page-sections.js.map +0 -1
- package/dist/commands/proxy.d.ts +0 -39
- package/dist/commands/proxy.d.ts.map +0 -1
- package/dist/commands/proxy.js +0 -210
- package/dist/commands/proxy.js.map +0 -1
- package/dist/commands/publish-theme.d.ts +0 -3
- package/dist/commands/publish-theme.d.ts.map +0 -1
- package/dist/commands/publish-theme.js +0 -29
- package/dist/commands/publish-theme.js.map +0 -1
- package/dist/commands/search-products.d.ts +0 -3
- package/dist/commands/search-products.d.ts.map +0 -1
- package/dist/commands/search-products.js +0 -40
- package/dist/commands/search-products.js.map +0 -1
- package/dist/commands/update-page-sections.d.ts +0 -3
- package/dist/commands/update-page-sections.d.ts.map +0 -1
- package/dist/commands/update-page-sections.js +0 -39
- package/dist/commands/update-page-sections.js.map +0 -1
- package/dist/commands/update-section-prop.d.ts +0 -3
- package/dist/commands/update-section-prop.d.ts.map +0 -1
- package/dist/commands/update-section-prop.js +0 -59
- package/dist/commands/update-section-prop.js.map +0 -1
- package/dist/commands/update-section-props.d.ts +0 -3
- package/dist/commands/update-section-props.d.ts.map +0 -1
- package/dist/commands/update-section-props.js +0 -43
- package/dist/commands/update-section-props.js.map +0 -1
- package/dist/commands/upload-image.d.ts +0 -3
- package/dist/commands/upload-image.d.ts.map +0 -1
- package/dist/commands/upload-image.js +0 -38
- package/dist/commands/upload-image.js.map +0 -1
- package/dist/commands/upload-images.d.ts +0 -3
- package/dist/commands/upload-images.d.ts.map +0 -1
- package/dist/commands/upload-images.js +0 -48
- package/dist/commands/upload-images.js.map +0 -1
- package/dist/utils/load-image.d.ts +0 -16
- package/dist/utils/load-image.d.ts.map +0 -1
- package/dist/utils/load-image.js +0 -50
- package/dist/utils/load-image.js.map +0 -1
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { printErrorAndExit, printResultAndExit, runEditorAction, } from "../utils/editor-action-client.js";
|
|
3
|
-
async function runUpdateSectionProps(options) {
|
|
4
|
-
if (!options.pageId || typeof options.pageId !== "string") {
|
|
5
|
-
printErrorAndExit(new Error("--page-id is required (use `ikas-component list-pages`)"));
|
|
6
|
-
}
|
|
7
|
-
if (!options.elementId || typeof options.elementId !== "string") {
|
|
8
|
-
printErrorAndExit(new Error("--element-id is required (use `ikas-component list-page-sections`)"));
|
|
9
|
-
}
|
|
10
|
-
if (options.updates === undefined) {
|
|
11
|
-
printErrorAndExit(new Error('--updates is required: a JSON array, e.g. \'[{"propName":"heading","value":{"value":"Hi"}}]\''));
|
|
12
|
-
}
|
|
13
|
-
let updates;
|
|
14
|
-
try {
|
|
15
|
-
updates = JSON.parse(options.updates);
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
printErrorAndExit(new Error(`--updates must be valid JSON. Received: ${options.updates}`));
|
|
19
|
-
}
|
|
20
|
-
if (!Array.isArray(updates) || updates.length === 0) {
|
|
21
|
-
printErrorAndExit(new Error('--updates must be a non-empty JSON array of { propId|propName, value } objects.'));
|
|
22
|
-
}
|
|
23
|
-
const port = options.port ? parseInt(options.port, 10) : undefined;
|
|
24
|
-
try {
|
|
25
|
-
const result = await runEditorAction("update-section-props", { pageId: options.pageId, elementId: options.elementId, updates }, { ...(port ? { port } : {}), timeoutMs: 30_000 });
|
|
26
|
-
printResultAndExit(result);
|
|
27
|
-
}
|
|
28
|
-
catch (e) {
|
|
29
|
-
printErrorAndExit(e);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export function createUpdateSectionPropsCommand() {
|
|
33
|
-
const cmd = new Command("update-section-props");
|
|
34
|
-
cmd
|
|
35
|
-
.description("Set MANY prop values on one placed section in a single call (batch update-section-prop). --updates is a JSON array of { propId|propName, value }, each value using the same per-type shape as update-section-prop. All-or-nothing: every entry is resolved and validated before any is written.")
|
|
36
|
-
.requiredOption("--page-id <id>", "Page id (from `ikas-component list-pages`)")
|
|
37
|
-
.requiredOption("--element-id <id>", "Placed section elementId (from `ikas-component list-page-sections`)")
|
|
38
|
-
.requiredOption("--updates <json>", 'JSON array, e.g. \'[{"propName":"heading","value":{"value":"Hi"}},{"propName":"image","value":{"id":"<asset-id>"}}]\'')
|
|
39
|
-
.option("--port <port>", "Dev server WebSocket port", "5201")
|
|
40
|
-
.action(runUpdateSectionProps);
|
|
41
|
-
return cmd;
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=update-section-props.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update-section-props.js","sourceRoot":"","sources":["../../src/commands/update-section-props.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAS1C,KAAK,UAAU,qBAAqB,CAAC,OAAkC;IACrE,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1D,iBAAiB,CAAC,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC,CAAC;IAC1F,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,OAAO,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;QAChE,iBAAiB,CAAC,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC,CAAC;IACrG,CAAC;IACD,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAClC,iBAAiB,CACf,IAAI,KAAK,CAAC,+FAA+F,CAAC,CAC3G,CAAC;IACJ,CAAC;IAED,IAAI,OAAgB,CAAC;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AClB,uHAAuH,CACxH;SACA,MAAM,CAAC,eAAe,EAAE,2BAA2B,EAAE,MAAM,CAAC;SAC5D,MAAM,CAAC,qBAAqB,CAAC,CAAC;IACjC,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"upload-image.d.ts","sourceRoot":"","sources":["../../src/commands/upload-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAyCpC,wBAAgB,wBAAwB,IAAI,OAAO,CAYlD"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { printErrorAndExit, printResultAndExit, runEditorAction, } from "../utils/editor-action-client.js";
|
|
3
|
-
import { loadImageSource } from "../utils/load-image.js";
|
|
4
|
-
async function runUploadImage(options) {
|
|
5
|
-
const port = options.port ? parseInt(options.port, 10) : undefined;
|
|
6
|
-
if (!options.file && !options.url) {
|
|
7
|
-
printErrorAndExit(new Error("Provide --file <path> or --url <url>"));
|
|
8
|
-
}
|
|
9
|
-
try {
|
|
10
|
-
const { base64, mimeType, fileName } = await loadImageSource({ file: options.file, url: options.url });
|
|
11
|
-
const result = await runEditorAction("upload-image", {
|
|
12
|
-
base64,
|
|
13
|
-
mimeType,
|
|
14
|
-
fileName,
|
|
15
|
-
...(options.alt ? { altText: options.alt } : {}),
|
|
16
|
-
isVideo: false,
|
|
17
|
-
},
|
|
18
|
-
// Uploads carry the full image payload and round-trip to the host, so give
|
|
19
|
-
// them a far more generous timeout than the default 10s.
|
|
20
|
-
{ ...(port ? { port } : {}), timeoutMs: 60_000 });
|
|
21
|
-
printResultAndExit(result);
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
printErrorAndExit(e);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export function createUploadImageCommand() {
|
|
28
|
-
const cmd = new Command("upload-image");
|
|
29
|
-
cmd
|
|
30
|
-
.description("Upload an image to the connected editor's project and return its image id. Supply the image with --file (local path) or --url. The returned id can be used as the `id` of an IMAGE prop value via `ikas-component update-section-prop`. Requires the editor to be embedded in the ikas admin panel (the host performs the actual upload).")
|
|
31
|
-
.option("--file <path>", "Local image file path (.png, .jpg, .jpeg, .webp, .gif)")
|
|
32
|
-
.option("--url <url>", "Image URL to fetch and upload")
|
|
33
|
-
.option("--alt <text>", "Alt text for the image")
|
|
34
|
-
.option("--port <port>", "Dev server WebSocket port", "5201")
|
|
35
|
-
.action(runUploadImage);
|
|
36
|
-
return cmd;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=upload-image.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"upload-image.js","sourceRoot":"","sources":["../../src/commands/upload-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AASzD,KAAK,UAAU,cAAc,CAAC,OAA2B;IACvD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACnE,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;QAClC,iBAAiB,CAAC,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC,CAAC;IACvE,CAAC;IACD,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,MAAM,eAAe,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACvG,MAAM,MAAM,GAAG,MAAM,eAAe,CAClC,cAAc,EACd;YACE,MAAM;YACN,QAAQ;YACR,QAAQ;YACR,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAChD,OAAO,EAAE,KAAK;SACf;QACD,2EAA2E;QAC3E,yDAAyD;QACzD,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CACjD,CAAC;QACF,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,iBAAiB,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,cAAc,CAAC,CAAC;IACxC,GAAG;SACA,WAAW,CACV,2UAA2U,CAC5U;SACA,MAAM,CAAC,eAAe,EAAE,wDAAwD,CAAC;SACjF,MAAM,CAAC,aAAa,EAAE,+BAA+B,CAAC;SACtD,MAAM,CAAC,cAAc,EAAE,wBAAwB,CAAC;SAChD,MAAM,CAAC,eAAe,EAAE,2BAA2B,EAAE,MAAM,CAAC;SAC5D,MAAM,CAAC,cAAc,CAAC,CAAC;IAC1B,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"upload-images.d.ts","sourceRoot":"","sources":["../../src/commands/upload-images.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA8DpC,wBAAgB,yBAAyB,IAAI,OAAO,CAanD"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
import { printErrorAndExit, printResultAndExit, runEditorAction, } from "../utils/editor-action-client.js";
|
|
3
|
-
import { loadImageSource } from "../utils/load-image.js";
|
|
4
|
-
async function runUploadImages(options) {
|
|
5
|
-
if (options.manifest === undefined) {
|
|
6
|
-
printErrorAndExit(new Error('--manifest is required: a JSON array, e.g. \'[{"file":"/a.png","alt":"A"},{"url":"https://...","alt":"B"}]\''));
|
|
7
|
-
}
|
|
8
|
-
let manifest;
|
|
9
|
-
try {
|
|
10
|
-
manifest = JSON.parse(options.manifest);
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
printErrorAndExit(new Error(`--manifest must be valid JSON. Received: ${options.manifest}`));
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if (!Array.isArray(manifest) || manifest.length === 0) {
|
|
17
|
-
printErrorAndExit(new Error("--manifest must be a non-empty JSON array of { file|url, alt? } objects."));
|
|
18
|
-
}
|
|
19
|
-
const port = options.port ? parseInt(options.port, 10) : undefined;
|
|
20
|
-
try {
|
|
21
|
-
// Read/encode all sources in parallel, then send one batch editor-action.
|
|
22
|
-
const images = await Promise.all(manifest.map(async (entry) => {
|
|
23
|
-
const { base64, mimeType, fileName } = await loadImageSource({ file: entry.file, url: entry.url });
|
|
24
|
-
return {
|
|
25
|
-
base64,
|
|
26
|
-
mimeType,
|
|
27
|
-
fileName,
|
|
28
|
-
...(entry.alt ? { altText: entry.alt } : {}),
|
|
29
|
-
isVideo: false,
|
|
30
|
-
};
|
|
31
|
-
}));
|
|
32
|
-
const result = await runEditorAction("upload-images", { images }, { ...(port ? { port } : {}), timeoutMs: 60_000 });
|
|
33
|
-
printResultAndExit(result);
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
printErrorAndExit(e);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export function createUploadImagesCommand() {
|
|
40
|
-
const cmd = new Command("upload-images");
|
|
41
|
-
cmd
|
|
42
|
-
.description("Upload MANY images in one call (batch upload-image) and return their ids in order. --manifest is a JSON array of { file|url, alt? }. The host uploads them all in a single round-trip. Requires the editor embedded in the ikas admin panel.")
|
|
43
|
-
.requiredOption("--manifest <json>", 'JSON array, e.g. \'[{"file":"/a.png","alt":"A"},{"url":"https://x/b.jpg"}]\'')
|
|
44
|
-
.option("--port <port>", "Dev server WebSocket port", "5201")
|
|
45
|
-
.action(runUploadImages);
|
|
46
|
-
return cmd;
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=upload-images.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"upload-images.js","sourceRoot":"","sources":["../../src/commands/upload-images.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAazD,KAAK,UAAU,eAAe,CAAC,OAA4B;IACzD,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACnC,iBAAiB,CACf,IAAI,KAAK,CAAC,8GAA8G,CAAC,CAC1H,CAAC;IACJ,CAAC;IACD,IAAI,QAAyB,CAAC;IAC9B,IAAI,CAAC;QACH,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAAC,MAAM,CAAC;QACP,iBAAiB,CAAC,IAAI,KAAK,CAAC,4CAA4C,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QAC7F,OAAO;IACT,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtD,iBAAiB,CAAC,IAAI,KAAK,CAAC,0EAA0E,CAAC,CAAC,CAAC;IAC3G,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO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;IAC3B,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export declare const VALID_IMAGE_TYPES: string[];
|
|
2
|
-
export interface ImageSource {
|
|
3
|
-
file?: string;
|
|
4
|
-
url?: string;
|
|
5
|
-
}
|
|
6
|
-
export interface LoadedImage {
|
|
7
|
-
base64: string;
|
|
8
|
-
mimeType: string;
|
|
9
|
-
fileName: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Read an image from a local file path or URL and return its base64 (raw, no
|
|
13
|
-
* data: prefix), mime type, and a file name. Validates type and the 10MB limit.
|
|
14
|
-
*/
|
|
15
|
-
export declare function loadImageSource(src: ImageSource): Promise<LoadedImage>;
|
|
16
|
-
//# sourceMappingURL=load-image.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"load-image.d.ts","sourceRoot":"","sources":["../../src/utils/load-image.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,iBAAiB,UAA6B,CAAC;AAG5D,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAsC5E"}
|
package/dist/utils/load-image.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { basename, extname } from "node:path";
|
|
3
|
-
const MIME_BY_EXT = {
|
|
4
|
-
".png": "image/png",
|
|
5
|
-
".jpg": "image/jpeg",
|
|
6
|
-
".jpeg": "image/jpeg",
|
|
7
|
-
".webp": "image/webp",
|
|
8
|
-
".gif": "image/gif",
|
|
9
|
-
};
|
|
10
|
-
export const VALID_IMAGE_TYPES = Object.values(MIME_BY_EXT);
|
|
11
|
-
const MAX_SIZE_BYTES = 10 * 1024 * 1024; // 10MB, mirrors the editor's IMAGE_UPLOAD_LIMIT_SIZE
|
|
12
|
-
/**
|
|
13
|
-
* Read an image from a local file path or URL and return its base64 (raw, no
|
|
14
|
-
* data: prefix), mime type, and a file name. Validates type and the 10MB limit.
|
|
15
|
-
*/
|
|
16
|
-
export async function loadImageSource(src) {
|
|
17
|
-
if (src.file && src.url) {
|
|
18
|
-
throw new Error("Provide only one of file or url, not both");
|
|
19
|
-
}
|
|
20
|
-
if (src.file) {
|
|
21
|
-
const buffer = await readFile(src.file);
|
|
22
|
-
const ext = extname(src.file).toLowerCase();
|
|
23
|
-
const mimeType = MIME_BY_EXT[ext];
|
|
24
|
-
if (!mimeType) {
|
|
25
|
-
throw new Error(`Unsupported image extension "${ext || "(none)"}" for ${src.file}. Supported: ${Object.keys(MIME_BY_EXT).join(", ")}`);
|
|
26
|
-
}
|
|
27
|
-
if (buffer.byteLength > MAX_SIZE_BYTES) {
|
|
28
|
-
throw new Error(`${src.file} is ${(buffer.byteLength / 1024 / 1024).toFixed(1)}MB; the limit is 10MB`);
|
|
29
|
-
}
|
|
30
|
-
return { base64: buffer.toString("base64"), mimeType, fileName: basename(src.file) };
|
|
31
|
-
}
|
|
32
|
-
if (src.url) {
|
|
33
|
-
const res = await fetch(src.url);
|
|
34
|
-
if (!res.ok) {
|
|
35
|
-
throw new Error(`Failed to fetch ${src.url}: ${res.status} ${res.statusText}`);
|
|
36
|
-
}
|
|
37
|
-
const mimeType = (res.headers.get("content-type") || "").split(";")[0].trim();
|
|
38
|
-
if (!VALID_IMAGE_TYPES.includes(mimeType)) {
|
|
39
|
-
throw new Error(`${src.url} returned content-type "${mimeType || "(none)"}". Supported: ${VALID_IMAGE_TYPES.join(", ")}`);
|
|
40
|
-
}
|
|
41
|
-
const buffer = Buffer.from(await res.arrayBuffer());
|
|
42
|
-
if (buffer.byteLength > MAX_SIZE_BYTES) {
|
|
43
|
-
throw new Error(`${src.url} is ${(buffer.byteLength / 1024 / 1024).toFixed(1)}MB; the limit is 10MB`);
|
|
44
|
-
}
|
|
45
|
-
const urlName = basename(new URL(src.url).pathname) || "image";
|
|
46
|
-
return { base64: buffer.toString("base64"), mimeType, fileName: urlName };
|
|
47
|
-
}
|
|
48
|
-
throw new Error("Provide a file path or url");
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=load-image.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"load-image.js","sourceRoot":"","sources":["../../src/utils/load-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,WAAW,GAA2B;IAC1C,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAC5D,MAAM,cAAc,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,qDAAqD;AAa9F;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAAgB;IACpD,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IAED,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;QACb,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACxC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,W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