@life-palette/uploader 0.2.1 → 0.2.2
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.cjs +9 -5
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +9 -5
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -138,9 +138,9 @@ function detectLivePhotoPairs(files) {
|
|
|
138
138
|
* Lightweight replacement for `p-limit` (≈ 30 lines, no dependency).
|
|
139
139
|
*/
|
|
140
140
|
var PromisePool = class {
|
|
141
|
-
limit;
|
|
142
141
|
active = 0;
|
|
143
142
|
queue = [];
|
|
143
|
+
limit;
|
|
144
144
|
constructor(limit) {
|
|
145
145
|
this.limit = limit;
|
|
146
146
|
}
|
|
@@ -255,12 +255,15 @@ function createOssUploader(config) {
|
|
|
255
255
|
}
|
|
256
256
|
async function uploadPart(part) {
|
|
257
257
|
return withRetry(async () => {
|
|
258
|
+
const body = new Blob([part.blob], { type: "" });
|
|
258
259
|
const res = await fetch(part.url, {
|
|
259
|
-
body
|
|
260
|
-
headers: { "Content-Type": "application/octet-stream" },
|
|
260
|
+
body,
|
|
261
261
|
method: "PUT"
|
|
262
262
|
});
|
|
263
|
-
if (!res.ok)
|
|
263
|
+
if (!res.ok) {
|
|
264
|
+
const detail = await res.text().catch(() => "");
|
|
265
|
+
throw new Error(`Failed to upload part ${part.partNumber}: ${res.status}${detail ? ` - ${detail}` : ""}`);
|
|
266
|
+
}
|
|
264
267
|
return {
|
|
265
268
|
etag: (res.headers.get("ETag") || "").replace(/"/g, ""),
|
|
266
269
|
part_number: part.partNumber
|
|
@@ -277,7 +280,7 @@ function createOssUploader(config) {
|
|
|
277
280
|
const { upload_id: uid, key, uploaded_parts: done = [], uploaded_part_etags: existingParts = [], total_parts: total } = init;
|
|
278
281
|
const doneSet = new Set(done);
|
|
279
282
|
const pending = Array.from({ length: total }, (_, i) => i + 1).filter((n) => !doneSet.has(n));
|
|
280
|
-
const parts = [...existingParts];
|
|
283
|
+
const parts = [...existingParts ?? []];
|
|
281
284
|
let uploaded = 0;
|
|
282
285
|
if (pending.length > 0) {
|
|
283
286
|
const { urls } = await getPartUrls(key, uid, pending);
|
|
@@ -329,6 +332,7 @@ function createOssUploader(config) {
|
|
|
329
332
|
stage: "compress"
|
|
330
333
|
});
|
|
331
334
|
processed = await compress(file, maxSizeMB);
|
|
335
|
+
if (processed.size === 0) processed = file;
|
|
332
336
|
onProgress?.({
|
|
333
337
|
percent: 100,
|
|
334
338
|
stage: "compress"
|
package/dist/index.d.cts
CHANGED
|
@@ -88,9 +88,9 @@ export declare function detectLivePhotoPairs<T extends {
|
|
|
88
88
|
* Lightweight replacement for `p-limit` (≈ 30 lines, no dependency).
|
|
89
89
|
*/
|
|
90
90
|
export declare class PromisePool {
|
|
91
|
-
private readonly limit;
|
|
92
91
|
private active;
|
|
93
92
|
private readonly queue;
|
|
93
|
+
private readonly limit;
|
|
94
94
|
constructor(limit: number);
|
|
95
95
|
run<T>(task: () => Promise<T>): Promise<T>;
|
|
96
96
|
private next;
|
package/dist/index.d.mts
CHANGED
|
@@ -88,9 +88,9 @@ export declare function detectLivePhotoPairs<T extends {
|
|
|
88
88
|
* Lightweight replacement for `p-limit` (≈ 30 lines, no dependency).
|
|
89
89
|
*/
|
|
90
90
|
export declare class PromisePool {
|
|
91
|
-
private readonly limit;
|
|
92
91
|
private active;
|
|
93
92
|
private readonly queue;
|
|
93
|
+
private readonly limit;
|
|
94
94
|
constructor(limit: number);
|
|
95
95
|
run<T>(task: () => Promise<T>): Promise<T>;
|
|
96
96
|
private next;
|
package/dist/index.mjs
CHANGED
|
@@ -137,9 +137,9 @@ function detectLivePhotoPairs(files) {
|
|
|
137
137
|
* Lightweight replacement for `p-limit` (≈ 30 lines, no dependency).
|
|
138
138
|
*/
|
|
139
139
|
var PromisePool = class {
|
|
140
|
-
limit;
|
|
141
140
|
active = 0;
|
|
142
141
|
queue = [];
|
|
142
|
+
limit;
|
|
143
143
|
constructor(limit) {
|
|
144
144
|
this.limit = limit;
|
|
145
145
|
}
|
|
@@ -254,12 +254,15 @@ function createOssUploader(config) {
|
|
|
254
254
|
}
|
|
255
255
|
async function uploadPart(part) {
|
|
256
256
|
return withRetry(async () => {
|
|
257
|
+
const body = new Blob([part.blob], { type: "" });
|
|
257
258
|
const res = await fetch(part.url, {
|
|
258
|
-
body
|
|
259
|
-
headers: { "Content-Type": "application/octet-stream" },
|
|
259
|
+
body,
|
|
260
260
|
method: "PUT"
|
|
261
261
|
});
|
|
262
|
-
if (!res.ok)
|
|
262
|
+
if (!res.ok) {
|
|
263
|
+
const detail = await res.text().catch(() => "");
|
|
264
|
+
throw new Error(`Failed to upload part ${part.partNumber}: ${res.status}${detail ? ` - ${detail}` : ""}`);
|
|
265
|
+
}
|
|
263
266
|
return {
|
|
264
267
|
etag: (res.headers.get("ETag") || "").replace(/"/g, ""),
|
|
265
268
|
part_number: part.partNumber
|
|
@@ -276,7 +279,7 @@ function createOssUploader(config) {
|
|
|
276
279
|
const { upload_id: uid, key, uploaded_parts: done = [], uploaded_part_etags: existingParts = [], total_parts: total } = init;
|
|
277
280
|
const doneSet = new Set(done);
|
|
278
281
|
const pending = Array.from({ length: total }, (_, i) => i + 1).filter((n) => !doneSet.has(n));
|
|
279
|
-
const parts = [...existingParts];
|
|
282
|
+
const parts = [...existingParts ?? []];
|
|
280
283
|
let uploaded = 0;
|
|
281
284
|
if (pending.length > 0) {
|
|
282
285
|
const { urls } = await getPartUrls(key, uid, pending);
|
|
@@ -328,6 +331,7 @@ function createOssUploader(config) {
|
|
|
328
331
|
stage: "compress"
|
|
329
332
|
});
|
|
330
333
|
processed = await compress(file, maxSizeMB);
|
|
334
|
+
if (processed.size === 0) processed = file;
|
|
331
335
|
onProgress?.({
|
|
332
336
|
percent: 100,
|
|
333
337
|
stage: "compress"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@life-palette/uploader",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "OSS uploader for Life Palette: compress → analyze → multipart upload (concurrent, retryable) → complete. Browser-only, framework-agnostic.",
|
|
5
5
|
"homepage": "https://github.com/Life-Palette/packages/tree/main/packages/uploader#readme",
|
|
6
6
|
"bugs": "https://github.com/Life-Palette/packages/issues",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"README.md"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@life-palette/media": "0.2.
|
|
35
|
+
"@life-palette/media": "0.2.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@vitest/coverage-v8": "^5.0.0",
|