@useupup/core 3.3.0
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/LICENSE +21 -0
- package/NOTICE +8 -0
- package/README.md +75 -0
- package/dist/browser-SXR426OQ.cjs +10 -0
- package/dist/browser-WD6T5ABJ.js +1 -0
- package/dist/chunk-2H5ICKFT.cjs +122 -0
- package/dist/chunk-6HF3I2JS.cjs +39 -0
- package/dist/chunk-6S5DQDQH.js +212 -0
- package/dist/chunk-BMQC27OE.cjs +92 -0
- package/dist/chunk-BSGQGINR.cjs +219 -0
- package/dist/chunk-CPKZ2CXD.cjs +179 -0
- package/dist/chunk-DTKDIMKT.cjs +573 -0
- package/dist/chunk-DYE5XJ6Z.cjs +2134 -0
- package/dist/chunk-E3ZCNOXG.cjs +74 -0
- package/dist/chunk-FEQY2WYY.cjs +2377 -0
- package/dist/chunk-FMURBCZ7.js +120 -0
- package/dist/chunk-FYQQRULL.js +37 -0
- package/dist/chunk-GE4LIVXP.js +133 -0
- package/dist/chunk-HFR5HZJZ.js +56 -0
- package/dist/chunk-I7ULPCA2.js +72 -0
- package/dist/chunk-MHYXDLZR.js +569 -0
- package/dist/chunk-N2SLHVAW.cjs +61 -0
- package/dist/chunk-OOPDEOTM.js +169 -0
- package/dist/chunk-PMBR3OUW.js +2359 -0
- package/dist/chunk-QK7HZIVY.cjs +144 -0
- package/dist/chunk-T2AQHY7V.cjs +59 -0
- package/dist/chunk-TRCP5FUR.js +90 -0
- package/dist/chunk-U7KL5M2H.cjs +374 -0
- package/dist/chunk-UXNPM54W.js +2108 -0
- package/dist/chunk-VV6QCQLL.js +365 -0
- package/dist/chunk-ZMS2HXLB.js +56 -0
- package/dist/context-shapes-123dd3b6.d.cts +207 -0
- package/dist/context-shapes-27b24c8f.d.ts +207 -0
- package/dist/contracts-pipeline-cf177270.d.cts +78 -0
- package/dist/contracts-pipeline-cf177270.d.ts +78 -0
- package/dist/contracts-strategies-378a16b7.d.cts +168 -0
- package/dist/contracts-strategies-378a16b7.d.ts +168 -0
- package/dist/contracts.cjs +181 -0
- package/dist/contracts.d.cts +11 -0
- package/dist/contracts.d.ts +11 -0
- package/dist/contracts.js +4 -0
- package/dist/core-141335ac.d.ts +651 -0
- package/dist/core-bea2ceca.d.cts +651 -0
- package/dist/create-worker-provider-AA5SRII6.js +58 -0
- package/dist/create-worker-provider-KJNUSSTW.cjs +60 -0
- package/dist/eligibility-ONLNJ6FB.cjs +10 -0
- package/dist/eligibility-ULFC3E4G.js +8 -0
- package/dist/error-code-map-9c44a425.d.ts +62 -0
- package/dist/error-code-map-dd5becfa.d.cts +62 -0
- package/dist/i18n/index.cjs +90 -0
- package/dist/i18n/index.d.cts +3 -0
- package/dist/i18n/index.d.ts +3 -0
- package/dist/i18n/index.js +1 -0
- package/dist/index.cjs +1770 -0
- package/dist/index.d.cts +280 -0
- package/dist/index.d.ts +280 -0
- package/dist/index.js +1589 -0
- package/dist/internal.cjs +2407 -0
- package/dist/internal.d.cts +595 -0
- package/dist/internal.d.ts +595 -0
- package/dist/internal.js +2275 -0
- package/dist/pipeline/index.cjs +10 -0
- package/dist/pipeline/index.d.cts +11 -0
- package/dist/pipeline/index.d.ts +11 -0
- package/dist/pipeline/index.js +1 -0
- package/dist/pipeline-worker.cjs +199 -0
- package/dist/pipeline-worker.d.cts +2 -0
- package/dist/pipeline-worker.d.ts +2 -0
- package/dist/pipeline-worker.js +197 -0
- package/dist/resolve-locale-81feef21.d.ts +20 -0
- package/dist/resolve-locale-9cb63600.d.cts +20 -0
- package/dist/resolve-theme-01758105.d.ts +53 -0
- package/dist/resolve-theme-66cf8d98.d.cts +53 -0
- package/dist/server-mode-drive-controller-b5f8ee12.d.cts +180 -0
- package/dist/server-mode-drive-controller-b5f8ee12.d.ts +180 -0
- package/dist/steps/compress.cjs +66 -0
- package/dist/steps/compress.d.cts +10 -0
- package/dist/steps/compress.d.ts +10 -0
- package/dist/steps/compress.js +64 -0
- package/dist/steps/exif.cjs +44 -0
- package/dist/steps/exif.d.cts +5 -0
- package/dist/steps/exif.d.ts +5 -0
- package/dist/steps/exif.js +42 -0
- package/dist/steps/hash.cjs +44 -0
- package/dist/steps/hash.d.cts +5 -0
- package/dist/steps/hash.d.ts +5 -0
- package/dist/steps/hash.js +42 -0
- package/dist/steps/heic.cjs +59 -0
- package/dist/steps/heic.d.cts +5 -0
- package/dist/steps/heic.d.ts +5 -0
- package/dist/steps/heic.js +57 -0
- package/dist/steps/thumbnail.cjs +54 -0
- package/dist/steps/thumbnail.d.cts +10 -0
- package/dist/steps/thumbnail.d.ts +10 -0
- package/dist/steps/thumbnail.js +52 -0
- package/dist/strategies/index.cjs +82 -0
- package/dist/strategies/index.d.cts +187 -0
- package/dist/strategies/index.d.ts +187 -0
- package/dist/strategies/index.js +60 -0
- package/dist/strategies/tus-upload.cjs +14 -0
- package/dist/strategies/tus-upload.d.cts +15 -0
- package/dist/strategies/tus-upload.d.ts +15 -0
- package/dist/strategies/tus-upload.js +5 -0
- package/dist/theme/index.cjs +38 -0
- package/dist/theme/index.d.cts +3 -0
- package/dist/theme/index.d.ts +3 -0
- package/dist/theme/index.js +1 -0
- package/dist/theme-store-2e56a674.d.cts +39 -0
- package/dist/theme-store-f13e0315.d.ts +39 -0
- package/dist/token-endpoint-5fdb4a35.d.ts +20 -0
- package/dist/token-endpoint-a7d15ab6.d.cts +20 -0
- package/dist/ui-translations-c5d00392.d.cts +455 -0
- package/dist/ui-translations-c5d00392.d.ts +455 -0
- package/dist/uploader-props-72242002.d.ts +340 -0
- package/dist/uploader-props-7f956e60.d.cts +340 -0
- package/dist/vars-d3421f6c.d.cts +240 -0
- package/dist/vars-d3421f6c.d.ts +240 -0
- package/package.json +182 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { uploadErrorFromResponse, parseErrorBody, UpupNetworkError } from './chunk-GE4LIVXP.js';
|
|
2
|
+
|
|
3
|
+
// src/strategies/token-endpoint.ts
|
|
4
|
+
async function readErrorBody(response) {
|
|
5
|
+
try {
|
|
6
|
+
return await response.text();
|
|
7
|
+
} catch {
|
|
8
|
+
return void 0;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
var TokenEndpointCredentials = class {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.url = options.url;
|
|
14
|
+
this.headers = options.headers ?? {};
|
|
15
|
+
}
|
|
16
|
+
async getPresignedUrl(file) {
|
|
17
|
+
const response = await fetch(this.url, {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers: {
|
|
20
|
+
"Content-Type": "application/json",
|
|
21
|
+
...this.headers
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify({
|
|
24
|
+
name: file.name,
|
|
25
|
+
size: file.size,
|
|
26
|
+
type: file.type,
|
|
27
|
+
metadata: file.metadata ?? {}
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
const body = await readErrorBody(response);
|
|
32
|
+
const error = uploadErrorFromResponse({
|
|
33
|
+
status: response.status,
|
|
34
|
+
statusText: response.statusText,
|
|
35
|
+
...body !== void 0 ? { body } : {},
|
|
36
|
+
kind: "network"
|
|
37
|
+
});
|
|
38
|
+
if (!parseErrorBody(body).message.trim()) {
|
|
39
|
+
error.message = `Presign request failed: ${response.status} ${response.statusText}`;
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
return response.json();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/strategies/direct-upload.ts
|
|
48
|
+
var DirectUpload = class {
|
|
49
|
+
async upload(file, credentials, options) {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
const xhr = new XMLHttpRequest();
|
|
52
|
+
xhr.upload.addEventListener("progress", (e) => {
|
|
53
|
+
if (e.lengthComputable) {
|
|
54
|
+
options.onProgress(e.loaded, e.total);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
xhr.addEventListener("load", () => {
|
|
58
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
59
|
+
resolve({
|
|
60
|
+
key: credentials.key,
|
|
61
|
+
publicUrl: credentials.publicUrl,
|
|
62
|
+
downloadUrl: credentials.downloadUrl
|
|
63
|
+
});
|
|
64
|
+
} else {
|
|
65
|
+
reject(
|
|
66
|
+
uploadErrorFromResponse({
|
|
67
|
+
status: xhr.status,
|
|
68
|
+
statusText: xhr.statusText,
|
|
69
|
+
body: xhr.responseText,
|
|
70
|
+
kind: "storage",
|
|
71
|
+
operation: "upload"
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
xhr.addEventListener("error", () => {
|
|
77
|
+
reject(new UpupNetworkError("Network error during upload"));
|
|
78
|
+
});
|
|
79
|
+
xhr.addEventListener("abort", () => {
|
|
80
|
+
reject(new UpupNetworkError("Upload aborted"));
|
|
81
|
+
});
|
|
82
|
+
options.signal.addEventListener("abort", () => {
|
|
83
|
+
xhr.abort();
|
|
84
|
+
});
|
|
85
|
+
xhr.open("PUT", credentials.uploadUrl);
|
|
86
|
+
for (const [key, value] of Object.entries(
|
|
87
|
+
credentials.uploadHeaders ?? {}
|
|
88
|
+
)) {
|
|
89
|
+
xhr.setRequestHeader(key, value);
|
|
90
|
+
}
|
|
91
|
+
xhr.send(file);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// src/utils/multipart-session-store.ts
|
|
97
|
+
var STORAGE_PREFIX = "upup_mp_";
|
|
98
|
+
var SESSION_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
99
|
+
function fileFingerprint(file) {
|
|
100
|
+
return `${file.name}:${file.size}:${file.lastModified}:${file.type}`;
|
|
101
|
+
}
|
|
102
|
+
function storageKey(fingerprint) {
|
|
103
|
+
return `${STORAGE_PREFIX}${fingerprint}`;
|
|
104
|
+
}
|
|
105
|
+
function saveSession(fingerprint, session) {
|
|
106
|
+
try {
|
|
107
|
+
localStorage.setItem(storageKey(fingerprint), JSON.stringify(session));
|
|
108
|
+
} catch {
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function loadSession(fingerprint) {
|
|
112
|
+
try {
|
|
113
|
+
const raw = localStorage.getItem(storageKey(fingerprint));
|
|
114
|
+
if (!raw) return null;
|
|
115
|
+
const session = JSON.parse(raw);
|
|
116
|
+
if (Date.now() - session.updatedAt > SESSION_TTL_MS) {
|
|
117
|
+
removeSession(fingerprint);
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
return session;
|
|
121
|
+
} catch {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function updateSessionProgress(fingerprint, uploadedBytes) {
|
|
126
|
+
try {
|
|
127
|
+
const raw = localStorage.getItem(storageKey(fingerprint));
|
|
128
|
+
if (!raw) return;
|
|
129
|
+
const session = JSON.parse(raw);
|
|
130
|
+
session.uploadedBytes = uploadedBytes;
|
|
131
|
+
session.updatedAt = Date.now();
|
|
132
|
+
localStorage.setItem(storageKey(fingerprint), JSON.stringify(session));
|
|
133
|
+
} catch {
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function updateSessionToken(fingerprint, token) {
|
|
137
|
+
try {
|
|
138
|
+
const raw = localStorage.getItem(storageKey(fingerprint));
|
|
139
|
+
if (!raw) return;
|
|
140
|
+
const session = JSON.parse(raw);
|
|
141
|
+
session.token = token;
|
|
142
|
+
session.updatedAt = Date.now();
|
|
143
|
+
localStorage.setItem(storageKey(fingerprint), JSON.stringify(session));
|
|
144
|
+
} catch {
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function removeSession(fingerprint) {
|
|
148
|
+
try {
|
|
149
|
+
localStorage.removeItem(storageKey(fingerprint));
|
|
150
|
+
} catch {
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function clearAllSessions() {
|
|
154
|
+
try {
|
|
155
|
+
const keysToRemove = [];
|
|
156
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
157
|
+
const key = localStorage.key(i);
|
|
158
|
+
if (key?.startsWith(STORAGE_PREFIX)) {
|
|
159
|
+
keysToRemove.push(key);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
keysToRemove.forEach((k) => {
|
|
163
|
+
localStorage.removeItem(k);
|
|
164
|
+
});
|
|
165
|
+
} catch {
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export { DirectUpload, TokenEndpointCredentials, clearAllSessions, fileFingerprint, loadSession, removeSession, saveSession, updateSessionProgress, updateSessionToken };
|