Skip to content

Commit 3a0b129

Browse files
feat: update publish command to use named File for ZIP and icon uploads (#12)
* feat: update publish command to use named File for ZIP and icon uploads * feat: update changelog --------- Co-authored-by: smoratino-apogea <>
1 parent 0646326 commit 3a0b129

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

.changeset/violet-moments-poke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'thatopen-services': minor
3+
---
4+
5+
Send named File (with filename and mimetype) for bundle and icon uploads in the publish command.

src/cli/commands/publish.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ export const publishCommand = new Command('publish')
103103
process.exit(1);
104104
}
105105

106-
// Read ZIP as Blob for the client
106+
// Read ZIP as a named File for the client
107107
const zipBuffer = readFileSync(zipPath);
108-
const zipBlob = new Blob([zipBuffer]);
108+
const zipFile = new File([zipBuffer], 'bundle.zip', {
109+
type: 'application/zip',
110+
});
109111

110112
// Resolve icon: CLI flag > local config
111113
const iconPath = opts.icon || localConfig?.iconPath;
@@ -123,7 +125,7 @@ export const publishCommand = new Command('publish')
123125
itemId = await publishComponent(
124126
client,
125127
existingId,
126-
zipBlob,
128+
zipFile,
127129
projectName,
128130
versionTag,
129131
cwd,
@@ -132,7 +134,7 @@ export const publishCommand = new Command('publish')
132134
itemId = await publishApp(
133135
client,
134136
existingId,
135-
zipBlob,
137+
zipFile,
136138
projectName,
137139
versionTag,
138140
cwd,
@@ -174,7 +176,7 @@ export const publishCommand = new Command('publish')
174176
async function publishApp(
175177
client: EngineServicesClient,
176178
appId: string | undefined,
177-
zipBlob: Blob,
179+
zipFile: File,
178180
name: string,
179181
versionTag: string,
180182
cwd: string,
@@ -192,7 +194,7 @@ async function publishApp(
192194
);
193195
const result = await client.createVersion(
194196
appId,
195-
zipBlob,
197+
zipFile,
196198
versionTag,
197199
{}, // extraProps required by backend for APP items
198200
);
@@ -201,7 +203,7 @@ async function publishApp(
201203
} else {
202204
console.log(`Publishing new app "${name}" (${versionTag})...`);
203205
const result = await client.createApp({
204-
file: zipBlob,
206+
file: zipFile,
205207
name,
206208
versionTag,
207209
});
@@ -224,7 +226,7 @@ async function publishApp(
224226
async function publishComponent(
225227
client: EngineServicesClient,
226228
componentId: string | undefined,
227-
zipBlob: Blob,
229+
zipFile: File,
228230
name: string,
229231
versionTag: string,
230232
cwd: string,
@@ -247,7 +249,7 @@ async function publishComponent(
247249
`Publishing new version (${versionTag}) for component ${componentId}...`,
248250
);
249251
const result = await client.updateComponent(componentId, {
250-
file: zipBlob,
252+
file: zipFile,
251253
versionTag,
252254
componentProps,
253255
});
@@ -258,7 +260,7 @@ async function publishComponent(
258260
`Publishing new cloud component "${name}" (${versionTag})...`,
259261
);
260262
const result = await client.createComponent({
261-
file: zipBlob,
263+
file: zipFile,
262264
name,
263265
versionTag,
264266
componentProps,
@@ -279,7 +281,12 @@ async function publishComponent(
279281
// Icon upload helper
280282
// ---------------------------------------------------------------------------
281283

282-
const ALLOWED_ICON_EXTENSIONS = ['.png', '.webp', '.ico'];
284+
const ICON_MIME_TYPES: Record<string, string> = {
285+
'.png': 'image/png',
286+
'.webp': 'image/webp',
287+
'.ico': 'image/x-icon',
288+
};
289+
const ALLOWED_ICON_EXTENSIONS = Object.keys(ICON_MIME_TYPES);
283290
const MAX_ICON_SIZE = 512 * 1024; // 512 KB
284291

285292
async function uploadIcon(
@@ -310,8 +317,10 @@ async function uploadIcon(
310317

311318
console.log('Uploading icon...');
312319
const iconBuffer = readFileSync(resolvedPath);
313-
const iconBlob = new Blob([iconBuffer]);
314-
await client.uploadItemIcon(itemId, iconBlob);
320+
const iconFile = new File([iconBuffer], basename(resolvedPath), {
321+
type: ICON_MIME_TYPES[ext],
322+
});
323+
await client.uploadItemIcon(itemId, iconFile);
315324
console.log('Icon uploaded.');
316325

317326
// Save icon path to local config if provided via CLI flag

0 commit comments

Comments
 (0)