@thetechfossil/upfiles 1.0.5 → 1.0.7

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 CHANGED
@@ -96,6 +96,13 @@ declare class UpfilesClient {
96
96
  fetchThumbnails?: boolean;
97
97
  }): Promise<UploadedFileResult>;
98
98
  getThumbnails(fileKey: string): Promise<Thumbnail[]>;
99
+ generateThumbnails(fileKey: string): Promise<{
100
+ masterWebp?: {
101
+ key: string;
102
+ url: string;
103
+ };
104
+ thumbnails: Thumbnail[];
105
+ }>;
99
106
  getProjectFiles(params?: {
100
107
  folderPath?: string;
101
108
  }): Promise<FileListItem[]>;
package/dist/index.d.ts CHANGED
@@ -96,6 +96,13 @@ declare class UpfilesClient {
96
96
  fetchThumbnails?: boolean;
97
97
  }): Promise<UploadedFileResult>;
98
98
  getThumbnails(fileKey: string): Promise<Thumbnail[]>;
99
+ generateThumbnails(fileKey: string): Promise<{
100
+ masterWebp?: {
101
+ key: string;
102
+ url: string;
103
+ };
104
+ thumbnails: Thumbnail[];
105
+ }>;
99
106
  getProjectFiles(params?: {
100
107
  folderPath?: string;
101
108
  }): Promise<FileListItem[]>;
package/dist/index.js CHANGED
@@ -161,6 +161,39 @@ var UpfilesClient = class {
161
161
  const data = await res.json();
162
162
  return data?.thumbnails ?? [];
163
163
  }
164
+ async generateThumbnails(fileKey) {
165
+ const target = this.baseUrl ? `${this.baseUrl}${this.thumbnailsPath}` : this.thumbnailsPath;
166
+ const headers = {
167
+ "content-type": "application/json",
168
+ ...this.headers || {}
169
+ };
170
+ if (this.apiKey) {
171
+ if (this.apiKeyHeader === "authorization") {
172
+ headers["authorization"] = this.apiKey.startsWith("upk_") ? `Bearer ${this.apiKey}` : this.apiKey;
173
+ } else if (this.apiKeyHeader === "x-api-key") {
174
+ headers["x-api-key"] = this.apiKey;
175
+ } else {
176
+ headers["x-up-api-key"] = this.apiKey;
177
+ }
178
+ }
179
+ const res = await fetch(target, {
180
+ method: "POST",
181
+ headers,
182
+ credentials: this.withCredentials ? "include" : "same-origin",
183
+ body: JSON.stringify({ fileKey })
184
+ });
185
+ if (!res.ok) {
186
+ let msg = "Failed to generate thumbnails";
187
+ try {
188
+ const data2 = await res.json();
189
+ msg = data2.error || msg;
190
+ } catch {
191
+ }
192
+ throw new Error(msg);
193
+ }
194
+ const data = await res.json();
195
+ return { masterWebp: data.masterWebp, thumbnails: data.thumbnails ?? [] };
196
+ }
164
197
  async getProjectFiles(params) {
165
198
  const basePath = this.thumbnailsPath.replace(/\/thumbnails$/, "");
166
199
  const filesPath = `${basePath}/files`;
@@ -287,11 +320,15 @@ var Uploader = ({
287
320
  xhr.send(item.file);
288
321
  });
289
322
  let thumbs;
323
+ let masterWebp;
290
324
  try {
291
325
  if (fetchThumbnails) {
292
- thumbs = await client.getThumbnails(presign.fileKey);
326
+ const result2 = await client.generateThumbnails(presign.fileKey);
327
+ thumbs = result2.thumbnails;
328
+ masterWebp = result2.masterWebp;
293
329
  }
294
- } catch {
330
+ } catch (e) {
331
+ console.warn("Failed to generate thumbnails:", e);
295
332
  }
296
333
  if (autoRecordToDb && projectId) {
297
334
  try {
@@ -334,7 +371,9 @@ var Uploader = ({
334
371
  projectId: presign.projectId,
335
372
  apiKeyId: presign.apiKeyId,
336
373
  // @ts-ignore - allow downstream to access thumbs if present
337
- thumbnails: thumbs
374
+ thumbnails: thumbs,
375
+ // @ts-ignore - allow downstream to access masterWebp if present
376
+ masterWebp
338
377
  };
339
378
  update({ status: "success", progress: 100, fileKey: presign.fileKey, publicUrl: presign.publicUrl });
340
379
  onClientUploadComplete?.(result);
package/dist/index.mjs CHANGED
@@ -112,6 +112,39 @@ var UpfilesClient = class {
112
112
  const data = await res.json();
113
113
  return data?.thumbnails ?? [];
114
114
  }
115
+ async generateThumbnails(fileKey) {
116
+ const target = this.baseUrl ? `${this.baseUrl}${this.thumbnailsPath}` : this.thumbnailsPath;
117
+ const headers = {
118
+ "content-type": "application/json",
119
+ ...this.headers || {}
120
+ };
121
+ if (this.apiKey) {
122
+ if (this.apiKeyHeader === "authorization") {
123
+ headers["authorization"] = this.apiKey.startsWith("upk_") ? `Bearer ${this.apiKey}` : this.apiKey;
124
+ } else if (this.apiKeyHeader === "x-api-key") {
125
+ headers["x-api-key"] = this.apiKey;
126
+ } else {
127
+ headers["x-up-api-key"] = this.apiKey;
128
+ }
129
+ }
130
+ const res = await fetch(target, {
131
+ method: "POST",
132
+ headers,
133
+ credentials: this.withCredentials ? "include" : "same-origin",
134
+ body: JSON.stringify({ fileKey })
135
+ });
136
+ if (!res.ok) {
137
+ let msg = "Failed to generate thumbnails";
138
+ try {
139
+ const data2 = await res.json();
140
+ msg = data2.error || msg;
141
+ } catch {
142
+ }
143
+ throw new Error(msg);
144
+ }
145
+ const data = await res.json();
146
+ return { masterWebp: data.masterWebp, thumbnails: data.thumbnails ?? [] };
147
+ }
115
148
  async getProjectFiles(params) {
116
149
  const basePath = this.thumbnailsPath.replace(/\/thumbnails$/, "");
117
150
  const filesPath = `${basePath}/files`;
@@ -238,11 +271,15 @@ var Uploader = ({
238
271
  xhr.send(item.file);
239
272
  });
240
273
  let thumbs;
274
+ let masterWebp;
241
275
  try {
242
276
  if (fetchThumbnails) {
243
- thumbs = await client.getThumbnails(presign.fileKey);
277
+ const result2 = await client.generateThumbnails(presign.fileKey);
278
+ thumbs = result2.thumbnails;
279
+ masterWebp = result2.masterWebp;
244
280
  }
245
- } catch {
281
+ } catch (e) {
282
+ console.warn("Failed to generate thumbnails:", e);
246
283
  }
247
284
  if (autoRecordToDb && projectId) {
248
285
  try {
@@ -285,7 +322,9 @@ var Uploader = ({
285
322
  projectId: presign.projectId,
286
323
  apiKeyId: presign.apiKeyId,
287
324
  // @ts-ignore - allow downstream to access thumbs if present
288
- thumbnails: thumbs
325
+ thumbnails: thumbs,
326
+ // @ts-ignore - allow downstream to access masterWebp if present
327
+ masterWebp
289
328
  };
290
329
  update({ status: "success", progress: 100, fileKey: presign.fileKey, publicUrl: presign.publicUrl });
291
330
  onClientUploadComplete?.(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thetechfossil/upfiles",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Lightweight client and React components for Upfiles Plugin API (presigned S3)",
5
5
  "license": "MIT",
6
6
  "author": "UpFiles",