@slopmachine/core 0.1.24 → 0.1.25
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/index.d.mts +23 -1
- package/dist/index.d.ts +23 -1
- package/dist/index.js +41 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +60 -0
package/dist/index.d.mts
CHANGED
|
@@ -40,6 +40,10 @@ interface SlopImageOptions {
|
|
|
40
40
|
* Defaults to false.
|
|
41
41
|
*/
|
|
42
42
|
original?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Array of attachment URLs to include with the request.
|
|
45
|
+
*/
|
|
46
|
+
attachments?: string[];
|
|
43
47
|
}
|
|
44
48
|
declare function interpolatePrompt(prompt?: string, variables?: Record<string, string | number | undefined | null>): string;
|
|
45
49
|
/**
|
|
@@ -104,6 +108,10 @@ interface SlopVideoOptions {
|
|
|
104
108
|
* Defaults to false.
|
|
105
109
|
*/
|
|
106
110
|
original?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Array of attachment URLs to include with the request.
|
|
113
|
+
*/
|
|
114
|
+
attachments?: string[];
|
|
107
115
|
}
|
|
108
116
|
/**
|
|
109
117
|
* Builds a URL to render or retrieve a video from Slop Machine.
|
|
@@ -145,6 +153,10 @@ interface SlopTextOptions {
|
|
|
145
153
|
* Defaults to the production URL. Useful for testing against local deployments.
|
|
146
154
|
*/
|
|
147
155
|
baseUrl?: string;
|
|
156
|
+
/**
|
|
157
|
+
* Array of attachment URLs to include with the request.
|
|
158
|
+
*/
|
|
159
|
+
attachments?: string[];
|
|
148
160
|
}
|
|
149
161
|
/**
|
|
150
162
|
* Builds a URL to render or retrieve text from Slop Machine.
|
|
@@ -161,5 +173,15 @@ declare function buildTextUrl(options: SlopTextOptions): string;
|
|
|
161
173
|
* @returns A promise that resolves when the text preload request has been initiated.
|
|
162
174
|
*/
|
|
163
175
|
declare function preloadText(options: SlopTextOptions): Promise<void>;
|
|
176
|
+
/**
|
|
177
|
+
* Uploads a base64 encoded file as a temporary attachment to be used in generation requests.
|
|
178
|
+
*
|
|
179
|
+
* @param base64 - The base64 encoded file data (without the data:mime/type;base64, prefix).
|
|
180
|
+
* @param mimeType - The MIME type of the file.
|
|
181
|
+
* @returns A promise that resolves to an object containing the URL of the uploaded attachment.
|
|
182
|
+
*/
|
|
183
|
+
declare function uploadTempAttachment(base64: string, mimeType: string): Promise<{
|
|
184
|
+
url: string;
|
|
185
|
+
}>;
|
|
164
186
|
|
|
165
|
-
export { type ImageAspectRatio, type SlopImageOptions, type SlopTextOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildTextUrl, buildVideoUrl, interpolatePrompt, preloadImage, preloadText, preloadVideo };
|
|
187
|
+
export { type ImageAspectRatio, type SlopImageOptions, type SlopTextOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildTextUrl, buildVideoUrl, interpolatePrompt, preloadImage, preloadText, preloadVideo, uploadTempAttachment };
|
package/dist/index.d.ts
CHANGED
|
@@ -40,6 +40,10 @@ interface SlopImageOptions {
|
|
|
40
40
|
* Defaults to false.
|
|
41
41
|
*/
|
|
42
42
|
original?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Array of attachment URLs to include with the request.
|
|
45
|
+
*/
|
|
46
|
+
attachments?: string[];
|
|
43
47
|
}
|
|
44
48
|
declare function interpolatePrompt(prompt?: string, variables?: Record<string, string | number | undefined | null>): string;
|
|
45
49
|
/**
|
|
@@ -104,6 +108,10 @@ interface SlopVideoOptions {
|
|
|
104
108
|
* Defaults to false.
|
|
105
109
|
*/
|
|
106
110
|
original?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Array of attachment URLs to include with the request.
|
|
113
|
+
*/
|
|
114
|
+
attachments?: string[];
|
|
107
115
|
}
|
|
108
116
|
/**
|
|
109
117
|
* Builds a URL to render or retrieve a video from Slop Machine.
|
|
@@ -145,6 +153,10 @@ interface SlopTextOptions {
|
|
|
145
153
|
* Defaults to the production URL. Useful for testing against local deployments.
|
|
146
154
|
*/
|
|
147
155
|
baseUrl?: string;
|
|
156
|
+
/**
|
|
157
|
+
* Array of attachment URLs to include with the request.
|
|
158
|
+
*/
|
|
159
|
+
attachments?: string[];
|
|
148
160
|
}
|
|
149
161
|
/**
|
|
150
162
|
* Builds a URL to render or retrieve text from Slop Machine.
|
|
@@ -161,5 +173,15 @@ declare function buildTextUrl(options: SlopTextOptions): string;
|
|
|
161
173
|
* @returns A promise that resolves when the text preload request has been initiated.
|
|
162
174
|
*/
|
|
163
175
|
declare function preloadText(options: SlopTextOptions): Promise<void>;
|
|
176
|
+
/**
|
|
177
|
+
* Uploads a base64 encoded file as a temporary attachment to be used in generation requests.
|
|
178
|
+
*
|
|
179
|
+
* @param base64 - The base64 encoded file data (without the data:mime/type;base64, prefix).
|
|
180
|
+
* @param mimeType - The MIME type of the file.
|
|
181
|
+
* @returns A promise that resolves to an object containing the URL of the uploaded attachment.
|
|
182
|
+
*/
|
|
183
|
+
declare function uploadTempAttachment(base64: string, mimeType: string): Promise<{
|
|
184
|
+
url: string;
|
|
185
|
+
}>;
|
|
164
186
|
|
|
165
|
-
export { type ImageAspectRatio, type SlopImageOptions, type SlopTextOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildTextUrl, buildVideoUrl, interpolatePrompt, preloadImage, preloadText, preloadVideo };
|
|
187
|
+
export { type ImageAspectRatio, type SlopImageOptions, type SlopTextOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildTextUrl, buildVideoUrl, interpolatePrompt, preloadImage, preloadText, preloadVideo, uploadTempAttachment };
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,8 @@ __export(index_exports, {
|
|
|
26
26
|
interpolatePrompt: () => interpolatePrompt,
|
|
27
27
|
preloadImage: () => preloadImage,
|
|
28
28
|
preloadText: () => preloadText,
|
|
29
|
-
preloadVideo: () => preloadVideo
|
|
29
|
+
preloadVideo: () => preloadVideo,
|
|
30
|
+
uploadTempAttachment: () => uploadTempAttachment
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(index_exports);
|
|
32
33
|
function interpolatePrompt(prompt, variables) {
|
|
@@ -50,7 +51,8 @@ function buildImageUrl(options) {
|
|
|
50
51
|
quality = "fast",
|
|
51
52
|
variables = {},
|
|
52
53
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage",
|
|
53
|
-
original
|
|
54
|
+
original,
|
|
55
|
+
attachments
|
|
54
56
|
} = options;
|
|
55
57
|
const params = new URLSearchParams();
|
|
56
58
|
params.set("bucketId", bucketId);
|
|
@@ -72,6 +74,9 @@ function buildImageUrl(options) {
|
|
|
72
74
|
if (Object.keys(variables).length > 0) {
|
|
73
75
|
params.set("variables", JSON.stringify(variables));
|
|
74
76
|
}
|
|
77
|
+
if (attachments && attachments.length > 0) {
|
|
78
|
+
params.set("attachments", JSON.stringify(attachments));
|
|
79
|
+
}
|
|
75
80
|
} else {
|
|
76
81
|
params.set("resultId", resultId);
|
|
77
82
|
}
|
|
@@ -99,7 +104,8 @@ function buildVideoUrl(options) {
|
|
|
99
104
|
variables = {},
|
|
100
105
|
duration = 4,
|
|
101
106
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo",
|
|
102
|
-
original
|
|
107
|
+
original,
|
|
108
|
+
attachments
|
|
103
109
|
} = options;
|
|
104
110
|
const params = new URLSearchParams();
|
|
105
111
|
params.set("bucketId", bucketId);
|
|
@@ -122,6 +128,9 @@ function buildVideoUrl(options) {
|
|
|
122
128
|
if (Object.keys(variables).length > 0) {
|
|
123
129
|
params.set("variables", JSON.stringify(variables));
|
|
124
130
|
}
|
|
131
|
+
if (attachments && attachments.length > 0) {
|
|
132
|
+
params.set("attachments", JSON.stringify(attachments));
|
|
133
|
+
}
|
|
125
134
|
} else {
|
|
126
135
|
params.set("resultId", resultId);
|
|
127
136
|
}
|
|
@@ -142,7 +151,8 @@ function buildTextUrl(options) {
|
|
|
142
151
|
version,
|
|
143
152
|
resultId,
|
|
144
153
|
variables = {},
|
|
145
|
-
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText"
|
|
154
|
+
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText",
|
|
155
|
+
attachments
|
|
146
156
|
} = options;
|
|
147
157
|
const params = new URLSearchParams();
|
|
148
158
|
params.set("bucketId", bucketId);
|
|
@@ -156,6 +166,9 @@ function buildTextUrl(options) {
|
|
|
156
166
|
if (Object.keys(variables).length > 0) {
|
|
157
167
|
params.set("variables", JSON.stringify(variables));
|
|
158
168
|
}
|
|
169
|
+
if (attachments && attachments.length > 0) {
|
|
170
|
+
params.set("attachments", JSON.stringify(attachments));
|
|
171
|
+
}
|
|
159
172
|
} else {
|
|
160
173
|
params.set("resultId", resultId);
|
|
161
174
|
}
|
|
@@ -170,6 +183,28 @@ function preloadText(options) {
|
|
|
170
183
|
fetch(buildTextUrl(options), { mode: "no-cors" }).then(() => resolve()).catch((err) => reject(err));
|
|
171
184
|
});
|
|
172
185
|
}
|
|
186
|
+
async function uploadTempAttachment(base64, mimeType) {
|
|
187
|
+
const response = await fetch(
|
|
188
|
+
"https://us-central1-slopmachine-12bfb.cloudfunctions.net/uploadTempAttachment",
|
|
189
|
+
{
|
|
190
|
+
method: "POST",
|
|
191
|
+
headers: {
|
|
192
|
+
"Content-Type": "application/json"
|
|
193
|
+
},
|
|
194
|
+
body: JSON.stringify({ data: { base64, mimeType } })
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
if (!response.ok) {
|
|
198
|
+
throw new Error(`Failed to upload attachment: ${response.statusText}`);
|
|
199
|
+
}
|
|
200
|
+
const json = await response.json();
|
|
201
|
+
if (json.error) {
|
|
202
|
+
throw new Error(
|
|
203
|
+
`Failed to upload attachment: ${json.error.message || JSON.stringify(json.error)}`
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return { url: json.result.url };
|
|
207
|
+
}
|
|
173
208
|
// Annotate the CommonJS export names for ESM import in node:
|
|
174
209
|
0 && (module.exports = {
|
|
175
210
|
buildImageUrl,
|
|
@@ -178,6 +213,7 @@ function preloadText(options) {
|
|
|
178
213
|
interpolatePrompt,
|
|
179
214
|
preloadImage,
|
|
180
215
|
preloadText,
|
|
181
|
-
preloadVideo
|
|
216
|
+
preloadVideo,
|
|
217
|
+
uploadTempAttachment
|
|
182
218
|
});
|
|
183
219
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type ImageAspectRatio =\n | \"1:1\"\n | \"2:3\"\n | \"3:2\"\n | \"3:4\"\n | \"4:3\"\n | \"4:5\"\n | \"5:4\"\n | \"9:16\"\n | \"16:9\"\n | \"21:9\";\n\nexport interface SlopImageOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated image\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated image. Defaults to \"1:1\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: ImageAspectRatio;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A photo of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n /**\n * If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file (e.g., PNG/JPEG).\n * Defaults to false.\n */\n original?: boolean;\n}\n\nexport function interpolatePrompt(\n prompt?: string,\n variables?: Record<string, string | number | undefined | null>,\n): string {\n if (!prompt) return \"\";\n let text = prompt;\n if (!variables) return text;\n\n Object.keys(variables).forEach((key) => {\n const value = variables[key];\n if (value !== undefined && value !== null) {\n text = text.replace(new RegExp(`\\\\{${key}\\\\}`, \"g\"), String(value));\n }\n });\n return text;\n}\n\n/**\n * Builds a URL to render or retrieve an image from Slop Machine.\n *\n * @param options - Configuration options for the image generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildImageUrl(options: SlopImageOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"1:1\",\n quality = \"fast\",\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage\",\n original,\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (quality && quality !== \"fast\") {\n params.set(\"quality\", quality);\n } else if (quality === \"fast\") {\n params.set(\"quality\", \"fast\");\n }\n\n if (original) {\n params.set(\"original\", \"true\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads an image from Slop Machine into the browser's cache.\n * Useful for ensuring images are ready before displaying them.\n *\n * @param options - Configuration options for the image generation.\n * @returns A promise that resolves when the image has been loaded.\n */\nexport function preloadImage(options: SlopImageOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n const img = new Image();\n img.onload = () => resolve();\n img.onerror = (err) => reject(err);\n img.src = buildImageUrl(options);\n });\n}\n\nexport type VideoAspectRatio = \"9:16\" | \"16:9\";\n\nexport interface SlopVideoOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated video\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated video. Defaults to \"16:9\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: VideoAspectRatio;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A video of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The duration of the generated video in seconds.\n * Must be between 4 and 8. Defaults to 4.\n */\n duration?: number;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n /**\n * If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file.\n * Defaults to false.\n */\n original?: boolean;\n}\n\n/**\n * Builds a URL to render or retrieve a video from Slop Machine.\n *\n * @param options - Configuration options for the video generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildVideoUrl(options: SlopVideoOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"16:9\",\n quality = \"fast\",\n variables = {},\n duration = 4,\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo\",\n original,\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (duration) {\n params.set(\"duration\", String(duration));\n }\n if (quality) {\n params.set(\"quality\", quality);\n }\n\n if (original) {\n params.set(\"original\", \"true\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads a video from Slop Machine into the browser's cache.\n * Useful for ensuring videos are ready before displaying them.\n *\n * @param options - Configuration options for the video generation.\n * @returns A promise that resolves when the video preload request has been initiated.\n */\nexport function preloadVideo(options: SlopVideoOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // We can just fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildVideoUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n\nexport interface SlopTextOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated text\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A story about a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\n/**\n * Builds a URL to render or retrieve text from Slop Machine.\n *\n * @param options - Configuration options for the text generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildTextUrl(options: SlopTextOptions): string {\n const {\n bucketId,\n version,\n resultId,\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads text from Slop Machine into the browser's cache.\n * Useful for ensuring text is ready before displaying it.\n *\n * @param options - Configuration options for the text generation.\n * @returns A promise that resolves when the text preload request has been initiated.\n */\nexport function preloadText(options: SlopTextOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // Fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildTextUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuDO,SAAS,kBACd,QACA,WACQ;AACR,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,OAAO;AACX,MAAI,CAAC,UAAW,QAAO;AAEvB,SAAO,KAAK,SAAS,EAAE,QAAQ,CAAC,QAAQ;AACtC,UAAM,QAAQ,UAAU,GAAG;AAC3B,QAAI,UAAU,UAAa,UAAU,MAAM;AACzC,aAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,GAAG,OAAO,GAAG,GAAG,OAAO,KAAK,CAAC;AAAA,IACpE;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAQO,SAAS,cAAc,SAAmC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,UAAU;AAAA,IACV,YAAY,CAAC;AAAA,IACb,UAAU;AAAA,IACV;AAAA,EACF,IAAI;AAEJ,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,YAAY,QAAQ;AAE/B,MAAI,CAAC,UAAU;AACb,QAAI,aAAa;AACf,aAAO,IAAI,eAAe,WAAW;AAAA,IACvC;AACA,QAAI,SAAS;AACX,aAAO,IAAI,WAAW,OAAO,OAAO,CAAC;AAAA,IACvC;AACA,QAAI,WAAW,YAAY,QAAQ;AACjC,aAAO,IAAI,WAAW,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,aAAa,OAAO,GAAG,EAAE,MAAM,UAAU,CAAC,EAC7C,KAAK,MAAM,QAAQ,CAAC,EACpB,MAAM,CAAC,QAAQ,OAAO,GAAG,CAAC;AAAA,EAC/B,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type ImageAspectRatio =\n | \"1:1\"\n | \"2:3\"\n | \"3:2\"\n | \"3:4\"\n | \"4:3\"\n | \"4:5\"\n | \"5:4\"\n | \"9:16\"\n | \"16:9\"\n | \"21:9\";\n\nexport interface SlopImageOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated image\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated image. Defaults to \"1:1\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: ImageAspectRatio;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A photo of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n /**\n * If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file (e.g., PNG/JPEG).\n * Defaults to false.\n */\n original?: boolean;\n /**\n * Array of attachment URLs to include with the request.\n */\n attachments?: string[];\n}\n\nexport function interpolatePrompt(\n prompt?: string,\n variables?: Record<string, string | number | undefined | null>,\n): string {\n if (!prompt) return \"\";\n let text = prompt;\n if (!variables) return text;\n\n Object.keys(variables).forEach((key) => {\n const value = variables[key];\n if (value !== undefined && value !== null) {\n text = text.replace(new RegExp(`\\\\{${key}\\\\}`, \"g\"), String(value));\n }\n });\n return text;\n}\n\n/**\n * Builds a URL to render or retrieve an image from Slop Machine.\n *\n * @param options - Configuration options for the image generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildImageUrl(options: SlopImageOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"1:1\",\n quality = \"fast\",\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage\",\n original,\n attachments,\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (quality && quality !== \"fast\") {\n params.set(\"quality\", quality);\n } else if (quality === \"fast\") {\n params.set(\"quality\", \"fast\");\n }\n\n if (original) {\n params.set(\"original\", \"true\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n if (attachments && attachments.length > 0) {\n params.set(\"attachments\", JSON.stringify(attachments));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads an image from Slop Machine into the browser's cache.\n * Useful for ensuring images are ready before displaying them.\n *\n * @param options - Configuration options for the image generation.\n * @returns A promise that resolves when the image has been loaded.\n */\nexport function preloadImage(options: SlopImageOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n const img = new Image();\n img.onload = () => resolve();\n img.onerror = (err) => reject(err);\n img.src = buildImageUrl(options);\n });\n}\n\nexport type VideoAspectRatio = \"9:16\" | \"16:9\";\n\nexport interface SlopVideoOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated video\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated video. Defaults to \"16:9\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: VideoAspectRatio;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A video of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The duration of the generated video in seconds.\n * Must be between 4 and 8. Defaults to 4.\n */\n duration?: number;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n /**\n * If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file.\n * Defaults to false.\n */\n original?: boolean;\n /**\n * Array of attachment URLs to include with the request.\n */\n attachments?: string[];\n}\n\n/**\n * Builds a URL to render or retrieve a video from Slop Machine.\n *\n * @param options - Configuration options for the video generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildVideoUrl(options: SlopVideoOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"16:9\",\n quality = \"fast\",\n variables = {},\n duration = 4,\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo\",\n original,\n attachments,\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (duration) {\n params.set(\"duration\", String(duration));\n }\n if (quality) {\n params.set(\"quality\", quality);\n }\n\n if (original) {\n params.set(\"original\", \"true\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n if (attachments && attachments.length > 0) {\n params.set(\"attachments\", JSON.stringify(attachments));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads a video from Slop Machine into the browser's cache.\n * Useful for ensuring videos are ready before displaying them.\n *\n * @param options - Configuration options for the video generation.\n * @returns A promise that resolves when the video preload request has been initiated.\n */\nexport function preloadVideo(options: SlopVideoOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // We can just fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildVideoUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n\nexport interface SlopTextOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated text\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A story about a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n /**\n * Array of attachment URLs to include with the request.\n */\n attachments?: string[];\n}\n\n/**\n * Builds a URL to render or retrieve text from Slop Machine.\n *\n * @param options - Configuration options for the text generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildTextUrl(options: SlopTextOptions): string {\n const {\n bucketId,\n version,\n resultId,\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText\",\n attachments,\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n if (attachments && attachments.length > 0) {\n params.set(\"attachments\", JSON.stringify(attachments));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads text from Slop Machine into the browser's cache.\n * Useful for ensuring text is ready before displaying it.\n *\n * @param options - Configuration options for the text generation.\n * @returns A promise that resolves when the text preload request has been initiated.\n */\nexport function preloadText(options: SlopTextOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // Fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildTextUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n\n/**\n * Uploads a base64 encoded file as a temporary attachment to be used in generation requests.\n *\n * @param base64 - The base64 encoded file data (without the data:mime/type;base64, prefix).\n * @param mimeType - The MIME type of the file.\n * @returns A promise that resolves to an object containing the URL of the uploaded attachment.\n */\nexport async function uploadTempAttachment(\n base64: string,\n mimeType: string,\n): Promise<{ url: string }> {\n const response = await fetch(\n \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/uploadTempAttachment\",\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({ data: { base64, mimeType } }),\n },\n );\n if (!response.ok) {\n throw new Error(`Failed to upload attachment: ${response.statusText}`);\n }\n const json = await response.json();\n if (json.error) {\n throw new Error(\n `Failed to upload attachment: ${json.error.message || JSON.stringify(json.error)}`,\n );\n }\n return { url: json.result.url };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2DO,SAAS,kBACd,QACA,WACQ;AACR,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,OAAO;AACX,MAAI,CAAC,UAAW,QAAO;AAEvB,SAAO,KAAK,SAAS,EAAE,QAAQ,CAAC,QAAQ;AACtC,UAAM,QAAQ,UAAU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A,MACA,MAAM,KAAK,UAAU,EAAE,MAAM,EAAE,QAAQ,SAAS,EAAE,CAAC;AAAA,IACrD;AAAA,EACF;AACA,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,IAAI,MAAM,gCAAgC,SAAS,UAAU,EAAE;AAAA,EACvE;AACA,QAAM,OAAO,MAAM,SAAS,KAAK;AACjC,MAAI,KAAK,OAAO;AACd,UAAM,IAAI;AAAA,MACR,gCAAgC,KAAK,MAAM,WAAW,KAAK,UAAU,KAAK,KAAK,CAAC;AAAA,IAClF;AAAA,EACF;AACA,SAAO,EAAE,KAAK,KAAK,OAAO,IAAI;AAChC;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -20,7 +20,8 @@ function buildImageUrl(options) {
|
|
|
20
20
|
quality = "fast",
|
|
21
21
|
variables = {},
|
|
22
22
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage",
|
|
23
|
-
original
|
|
23
|
+
original,
|
|
24
|
+
attachments
|
|
24
25
|
} = options;
|
|
25
26
|
const params = new URLSearchParams();
|
|
26
27
|
params.set("bucketId", bucketId);
|
|
@@ -42,6 +43,9 @@ function buildImageUrl(options) {
|
|
|
42
43
|
if (Object.keys(variables).length > 0) {
|
|
43
44
|
params.set("variables", JSON.stringify(variables));
|
|
44
45
|
}
|
|
46
|
+
if (attachments && attachments.length > 0) {
|
|
47
|
+
params.set("attachments", JSON.stringify(attachments));
|
|
48
|
+
}
|
|
45
49
|
} else {
|
|
46
50
|
params.set("resultId", resultId);
|
|
47
51
|
}
|
|
@@ -69,7 +73,8 @@ function buildVideoUrl(options) {
|
|
|
69
73
|
variables = {},
|
|
70
74
|
duration = 4,
|
|
71
75
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo",
|
|
72
|
-
original
|
|
76
|
+
original,
|
|
77
|
+
attachments
|
|
73
78
|
} = options;
|
|
74
79
|
const params = new URLSearchParams();
|
|
75
80
|
params.set("bucketId", bucketId);
|
|
@@ -92,6 +97,9 @@ function buildVideoUrl(options) {
|
|
|
92
97
|
if (Object.keys(variables).length > 0) {
|
|
93
98
|
params.set("variables", JSON.stringify(variables));
|
|
94
99
|
}
|
|
100
|
+
if (attachments && attachments.length > 0) {
|
|
101
|
+
params.set("attachments", JSON.stringify(attachments));
|
|
102
|
+
}
|
|
95
103
|
} else {
|
|
96
104
|
params.set("resultId", resultId);
|
|
97
105
|
}
|
|
@@ -112,7 +120,8 @@ function buildTextUrl(options) {
|
|
|
112
120
|
version,
|
|
113
121
|
resultId,
|
|
114
122
|
variables = {},
|
|
115
|
-
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText"
|
|
123
|
+
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText",
|
|
124
|
+
attachments
|
|
116
125
|
} = options;
|
|
117
126
|
const params = new URLSearchParams();
|
|
118
127
|
params.set("bucketId", bucketId);
|
|
@@ -126,6 +135,9 @@ function buildTextUrl(options) {
|
|
|
126
135
|
if (Object.keys(variables).length > 0) {
|
|
127
136
|
params.set("variables", JSON.stringify(variables));
|
|
128
137
|
}
|
|
138
|
+
if (attachments && attachments.length > 0) {
|
|
139
|
+
params.set("attachments", JSON.stringify(attachments));
|
|
140
|
+
}
|
|
129
141
|
} else {
|
|
130
142
|
params.set("resultId", resultId);
|
|
131
143
|
}
|
|
@@ -140,6 +152,28 @@ function preloadText(options) {
|
|
|
140
152
|
fetch(buildTextUrl(options), { mode: "no-cors" }).then(() => resolve()).catch((err) => reject(err));
|
|
141
153
|
});
|
|
142
154
|
}
|
|
155
|
+
async function uploadTempAttachment(base64, mimeType) {
|
|
156
|
+
const response = await fetch(
|
|
157
|
+
"https://us-central1-slopmachine-12bfb.cloudfunctions.net/uploadTempAttachment",
|
|
158
|
+
{
|
|
159
|
+
method: "POST",
|
|
160
|
+
headers: {
|
|
161
|
+
"Content-Type": "application/json"
|
|
162
|
+
},
|
|
163
|
+
body: JSON.stringify({ data: { base64, mimeType } })
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
if (!response.ok) {
|
|
167
|
+
throw new Error(`Failed to upload attachment: ${response.statusText}`);
|
|
168
|
+
}
|
|
169
|
+
const json = await response.json();
|
|
170
|
+
if (json.error) {
|
|
171
|
+
throw new Error(
|
|
172
|
+
`Failed to upload attachment: ${json.error.message || JSON.stringify(json.error)}`
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
return { url: json.result.url };
|
|
176
|
+
}
|
|
143
177
|
export {
|
|
144
178
|
buildImageUrl,
|
|
145
179
|
buildTextUrl,
|
|
@@ -147,6 +181,7 @@ export {
|
|
|
147
181
|
interpolatePrompt,
|
|
148
182
|
preloadImage,
|
|
149
183
|
preloadText,
|
|
150
|
-
preloadVideo
|
|
184
|
+
preloadVideo,
|
|
185
|
+
uploadTempAttachment
|
|
151
186
|
};
|
|
152
187
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type ImageAspectRatio =\n | \"1:1\"\n | \"2:3\"\n | \"3:2\"\n | \"3:4\"\n | \"4:3\"\n | \"4:5\"\n | \"5:4\"\n | \"9:16\"\n | \"16:9\"\n | \"21:9\";\n\nexport interface SlopImageOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated image\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated image. Defaults to \"1:1\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: ImageAspectRatio;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A photo of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n /**\n * If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file (e.g., PNG/JPEG).\n * Defaults to false.\n */\n original?: boolean;\n}\n\nexport function interpolatePrompt(\n prompt?: string,\n variables?: Record<string, string | number | undefined | null>,\n): string {\n if (!prompt) return \"\";\n let text = prompt;\n if (!variables) return text;\n\n Object.keys(variables).forEach((key) => {\n const value = variables[key];\n if (value !== undefined && value !== null) {\n text = text.replace(new RegExp(`\\\\{${key}\\\\}`, \"g\"), String(value));\n }\n });\n return text;\n}\n\n/**\n * Builds a URL to render or retrieve an image from Slop Machine.\n *\n * @param options - Configuration options for the image generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildImageUrl(options: SlopImageOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"1:1\",\n quality = \"fast\",\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage\",\n original,\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (quality && quality !== \"fast\") {\n params.set(\"quality\", quality);\n } else if (quality === \"fast\") {\n params.set(\"quality\", \"fast\");\n }\n\n if (original) {\n params.set(\"original\", \"true\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads an image from Slop Machine into the browser's cache.\n * Useful for ensuring images are ready before displaying them.\n *\n * @param options - Configuration options for the image generation.\n * @returns A promise that resolves when the image has been loaded.\n */\nexport function preloadImage(options: SlopImageOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n const img = new Image();\n img.onload = () => resolve();\n img.onerror = (err) => reject(err);\n img.src = buildImageUrl(options);\n });\n}\n\nexport type VideoAspectRatio = \"9:16\" | \"16:9\";\n\nexport interface SlopVideoOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated video\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated video. Defaults to \"16:9\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: VideoAspectRatio;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A video of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The duration of the generated video in seconds.\n * Must be between 4 and 8. Defaults to 4.\n */\n duration?: number;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n /**\n * If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file.\n * Defaults to false.\n */\n original?: boolean;\n}\n\n/**\n * Builds a URL to render or retrieve a video from Slop Machine.\n *\n * @param options - Configuration options for the video generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildVideoUrl(options: SlopVideoOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"16:9\",\n quality = \"fast\",\n variables = {},\n duration = 4,\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo\",\n original,\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (duration) {\n params.set(\"duration\", String(duration));\n }\n if (quality) {\n params.set(\"quality\", quality);\n }\n\n if (original) {\n params.set(\"original\", \"true\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads a video from Slop Machine into the browser's cache.\n * Useful for ensuring videos are ready before displaying them.\n *\n * @param options - Configuration options for the video generation.\n * @returns A promise that resolves when the video preload request has been initiated.\n */\nexport function preloadVideo(options: SlopVideoOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // We can just fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildVideoUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n\nexport interface SlopTextOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated text\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A story about a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\n/**\n * Builds a URL to render or retrieve text from Slop Machine.\n *\n * @param options - Configuration options for the text generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildTextUrl(options: SlopTextOptions): string {\n const {\n bucketId,\n version,\n resultId,\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads text from Slop Machine into the browser's cache.\n * Useful for ensuring text is ready before displaying it.\n *\n * @param options - Configuration options for the text generation.\n * @returns A promise that resolves when the text preload request has been initiated.\n */\nexport function preloadText(options: SlopTextOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // Fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildTextUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n"],"mappings":";AAuDO,SAAS,kBACd,QACA,WACQ;AACR,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,OAAO;AACX,MAAI,CAAC,UAAW,QAAO;AAEvB,SAAO,KAAK,SAAS,EAAE,QAAQ,CAAC,QAAQ;AACtC,UAAM,QAAQ,UAAU,GAAG;AAC3B,QAAI,UAAU,UAAa,UAAU,MAAM;AACzC,aAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,GAAG,OAAO,GAAG,GAAG,OAAO,KAAK,CAAC;AAAA,IACpE;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAQO,SAAS,cAAc,SAAmC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,UAAU;AAAA,IACV,YAAY,CAAC;AAAA,IACb,UAAU;AAAA,IACV;AAAA,EACF,IAAI;AAEJ,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,YAAY,QAAQ;AAE/B,MAAI,CAAC,UAAU;AACb,QAAI,aAAa;AACf,aAAO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SAAS,CAAC;AACxC;AASO,SAAS,YAAY,SAAyC;AACnE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI,OAAO,WAAW,aAAa;AACjC,cAAQ;AACR;AAAA,IACF;AAIA,UAAM,aAAa,OAAO,GAAG,EAAE,MAAM,UAAU,CAAC,EAC7C,KAAK,MAAM,QAAQ,CAAC,EACpB,MAAM,CAAC,QAAQ,OAAO,GAAG,CAAC;AAAA,EAC/B,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type ImageAspectRatio =\n | \"1:1\"\n | \"2:3\"\n | \"3:2\"\n | \"3:4\"\n | \"4:3\"\n | \"4:5\"\n | \"5:4\"\n | \"9:16\"\n | \"16:9\"\n | \"21:9\";\n\nexport interface SlopImageOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated image\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated image. Defaults to \"1:1\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: ImageAspectRatio;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A photo of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n /**\n * If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file (e.g., PNG/JPEG).\n * Defaults to false.\n */\n original?: boolean;\n /**\n * Array of attachment URLs to include with the request.\n */\n attachments?: string[];\n}\n\nexport function interpolatePrompt(\n prompt?: string,\n variables?: Record<string, string | number | undefined | null>,\n): string {\n if (!prompt) return \"\";\n let text = prompt;\n if (!variables) return text;\n\n Object.keys(variables).forEach((key) => {\n const value = variables[key];\n if (value !== undefined && value !== null) {\n text = text.replace(new RegExp(`\\\\{${key}\\\\}`, \"g\"), String(value));\n }\n });\n return text;\n}\n\n/**\n * Builds a URL to render or retrieve an image from Slop Machine.\n *\n * @param options - Configuration options for the image generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildImageUrl(options: SlopImageOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"1:1\",\n quality = \"fast\",\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage\",\n original,\n attachments,\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (quality && quality !== \"fast\") {\n params.set(\"quality\", quality);\n } else if (quality === \"fast\") {\n params.set(\"quality\", \"fast\");\n }\n\n if (original) {\n params.set(\"original\", \"true\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n if (attachments && attachments.length > 0) {\n params.set(\"attachments\", JSON.stringify(attachments));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads an image from Slop Machine into the browser's cache.\n * Useful for ensuring images are ready before displaying them.\n *\n * @param options - Configuration options for the image generation.\n * @returns A promise that resolves when the image has been loaded.\n */\nexport function preloadImage(options: SlopImageOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n const img = new Image();\n img.onload = () => resolve();\n img.onerror = (err) => reject(err);\n img.src = buildImageUrl(options);\n });\n}\n\nexport type VideoAspectRatio = \"9:16\" | \"16:9\";\n\nexport interface SlopVideoOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated video\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated video. Defaults to \"16:9\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: VideoAspectRatio;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A video of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The duration of the generated video in seconds.\n * Must be between 4 and 8. Defaults to 4.\n */\n duration?: number;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n /**\n * If `true` (or `?raw=true`), bypasses the WebP optimized media and returns the original generated file.\n * Defaults to false.\n */\n original?: boolean;\n /**\n * Array of attachment URLs to include with the request.\n */\n attachments?: string[];\n}\n\n/**\n * Builds a URL to render or retrieve a video from Slop Machine.\n *\n * @param options - Configuration options for the video generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildVideoUrl(options: SlopVideoOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"16:9\",\n quality = \"fast\",\n variables = {},\n duration = 4,\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo\",\n original,\n attachments,\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (duration) {\n params.set(\"duration\", String(duration));\n }\n if (quality) {\n params.set(\"quality\", quality);\n }\n\n if (original) {\n params.set(\"original\", \"true\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n if (attachments && attachments.length > 0) {\n params.set(\"attachments\", JSON.stringify(attachments));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads a video from Slop Machine into the browser's cache.\n * Useful for ensuring videos are ready before displaying them.\n *\n * @param options - Configuration options for the video generation.\n * @returns A promise that resolves when the video preload request has been initiated.\n */\nexport function preloadVideo(options: SlopVideoOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // We can just fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildVideoUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n\nexport interface SlopTextOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated text\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A story about a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n /**\n * Array of attachment URLs to include with the request.\n */\n attachments?: string[];\n}\n\n/**\n * Builds a URL to render or retrieve text from Slop Machine.\n *\n * @param options - Configuration options for the text generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildTextUrl(options: SlopTextOptions): string {\n const {\n bucketId,\n version,\n resultId,\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText\",\n attachments,\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n if (attachments && attachments.length > 0) {\n params.set(\"attachments\", JSON.stringify(attachments));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads text from Slop Machine into the browser's cache.\n * Useful for ensuring text is ready before displaying it.\n *\n * @param options - Configuration options for the text generation.\n * @returns A promise that resolves when the text preload request has been initiated.\n */\nexport function preloadText(options: SlopTextOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // Fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildTextUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n\n/**\n * Uploads a base64 encoded file as a temporary attachment to be used in generation requests.\n *\n * @param base64 - The base64 encoded file data (without the data:mime/type;base64, prefix).\n * @param mimeType - The MIME type of the file.\n * @returns A promise that resolves to an object containing the URL of the uploaded attachment.\n */\nexport async function uploadTempAttachment(\n base64: string,\n mimeType: string,\n): Promise<{ url: string }> {\n const response = await fetch(\n \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/uploadTempAttachment\",\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({ data: { base64, mimeType } }),\n },\n );\n if (!response.ok) {\n throw new Error(`Failed to upload attachment: ${response.statusText}`);\n }\n const json = await response.json();\n if (json.error) {\n throw new Error(\n `Failed to upload attachment: ${json.error.message || JSON.stringify(json.error)}`,\n );\n }\n return { url: json.result.url };\n}\n"],"mappings":";AA2DO,SAAS,kBACd,QACA,WACQ;AACR,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,OAAO;AACX,MAAI,CAAC,UAAW,QAAO;AAEvB,SAAO,KA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,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,MAClB;AAAA,MACA,MAAM,KAAK,UAAU,EAAE,MAAM,EAAE,QAAQ,SAAS,EAAE,CAAC;AAAA,IACrD;AAAA,EACF;AACA,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,IAAI,MAAM,gCAAgC,SAAS,UAAU,EAAE;AAAA,EACvE;AACA,QAAM,OAAO,MAAM,SAAS,KAAK;AACjC,MAAI,KAAK,OAAO;AACd,UAAM,IAAI;AAAA,MACR,gCAAgC,KAAK,MAAM,WAAW,KAAK,UAAU,KAAK,KAAK,CAAC;AAAA,IAClF;AAAA,EACF;AACA,SAAO,EAAE,KAAK,KAAK,OAAO,IAAI;AAChC;","names":[]}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -51,6 +51,10 @@ export interface SlopImageOptions {
|
|
|
51
51
|
* Defaults to false.
|
|
52
52
|
*/
|
|
53
53
|
original?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Array of attachment URLs to include with the request.
|
|
56
|
+
*/
|
|
57
|
+
attachments?: string[];
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
export function interpolatePrompt(
|
|
@@ -86,6 +90,7 @@ export function buildImageUrl(options: SlopImageOptions): string {
|
|
|
86
90
|
variables = {},
|
|
87
91
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage",
|
|
88
92
|
original,
|
|
93
|
+
attachments,
|
|
89
94
|
} = options;
|
|
90
95
|
|
|
91
96
|
const params = new URLSearchParams();
|
|
@@ -111,6 +116,10 @@ export function buildImageUrl(options: SlopImageOptions): string {
|
|
|
111
116
|
if (Object.keys(variables).length > 0) {
|
|
112
117
|
params.set("variables", JSON.stringify(variables));
|
|
113
118
|
}
|
|
119
|
+
|
|
120
|
+
if (attachments && attachments.length > 0) {
|
|
121
|
+
params.set("attachments", JSON.stringify(attachments));
|
|
122
|
+
}
|
|
114
123
|
} else {
|
|
115
124
|
params.set("resultId", resultId);
|
|
116
125
|
}
|
|
@@ -187,6 +196,10 @@ export interface SlopVideoOptions {
|
|
|
187
196
|
* Defaults to false.
|
|
188
197
|
*/
|
|
189
198
|
original?: boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Array of attachment URLs to include with the request.
|
|
201
|
+
*/
|
|
202
|
+
attachments?: string[];
|
|
190
203
|
}
|
|
191
204
|
|
|
192
205
|
/**
|
|
@@ -206,6 +219,7 @@ export function buildVideoUrl(options: SlopVideoOptions): string {
|
|
|
206
219
|
duration = 4,
|
|
207
220
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo",
|
|
208
221
|
original,
|
|
222
|
+
attachments,
|
|
209
223
|
} = options;
|
|
210
224
|
|
|
211
225
|
const params = new URLSearchParams();
|
|
@@ -232,6 +246,10 @@ export function buildVideoUrl(options: SlopVideoOptions): string {
|
|
|
232
246
|
if (Object.keys(variables).length > 0) {
|
|
233
247
|
params.set("variables", JSON.stringify(variables));
|
|
234
248
|
}
|
|
249
|
+
|
|
250
|
+
if (attachments && attachments.length > 0) {
|
|
251
|
+
params.set("attachments", JSON.stringify(attachments));
|
|
252
|
+
}
|
|
235
253
|
} else {
|
|
236
254
|
params.set("resultId", resultId);
|
|
237
255
|
}
|
|
@@ -286,6 +304,10 @@ export interface SlopTextOptions {
|
|
|
286
304
|
* Defaults to the production URL. Useful for testing against local deployments.
|
|
287
305
|
*/
|
|
288
306
|
baseUrl?: string;
|
|
307
|
+
/**
|
|
308
|
+
* Array of attachment URLs to include with the request.
|
|
309
|
+
*/
|
|
310
|
+
attachments?: string[];
|
|
289
311
|
}
|
|
290
312
|
|
|
291
313
|
/**
|
|
@@ -301,6 +323,7 @@ export function buildTextUrl(options: SlopTextOptions): string {
|
|
|
301
323
|
resultId,
|
|
302
324
|
variables = {},
|
|
303
325
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText",
|
|
326
|
+
attachments,
|
|
304
327
|
} = options;
|
|
305
328
|
|
|
306
329
|
const params = new URLSearchParams();
|
|
@@ -317,6 +340,10 @@ export function buildTextUrl(options: SlopTextOptions): string {
|
|
|
317
340
|
if (Object.keys(variables).length > 0) {
|
|
318
341
|
params.set("variables", JSON.stringify(variables));
|
|
319
342
|
}
|
|
343
|
+
|
|
344
|
+
if (attachments && attachments.length > 0) {
|
|
345
|
+
params.set("attachments", JSON.stringify(attachments));
|
|
346
|
+
}
|
|
320
347
|
} else {
|
|
321
348
|
params.set("resultId", resultId);
|
|
322
349
|
}
|
|
@@ -345,3 +372,36 @@ export function preloadText(options: SlopTextOptions): Promise<void> {
|
|
|
345
372
|
.catch((err) => reject(err));
|
|
346
373
|
});
|
|
347
374
|
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Uploads a base64 encoded file as a temporary attachment to be used in generation requests.
|
|
378
|
+
*
|
|
379
|
+
* @param base64 - The base64 encoded file data (without the data:mime/type;base64, prefix).
|
|
380
|
+
* @param mimeType - The MIME type of the file.
|
|
381
|
+
* @returns A promise that resolves to an object containing the URL of the uploaded attachment.
|
|
382
|
+
*/
|
|
383
|
+
export async function uploadTempAttachment(
|
|
384
|
+
base64: string,
|
|
385
|
+
mimeType: string,
|
|
386
|
+
): Promise<{ url: string }> {
|
|
387
|
+
const response = await fetch(
|
|
388
|
+
"https://us-central1-slopmachine-12bfb.cloudfunctions.net/uploadTempAttachment",
|
|
389
|
+
{
|
|
390
|
+
method: "POST",
|
|
391
|
+
headers: {
|
|
392
|
+
"Content-Type": "application/json",
|
|
393
|
+
},
|
|
394
|
+
body: JSON.stringify({ data: { base64, mimeType } }),
|
|
395
|
+
},
|
|
396
|
+
);
|
|
397
|
+
if (!response.ok) {
|
|
398
|
+
throw new Error(`Failed to upload attachment: ${response.statusText}`);
|
|
399
|
+
}
|
|
400
|
+
const json = await response.json();
|
|
401
|
+
if (json.error) {
|
|
402
|
+
throw new Error(
|
|
403
|
+
`Failed to upload attachment: ${json.error.message || JSON.stringify(json.error)}`,
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
return { url: json.result.url };
|
|
407
|
+
}
|