@broberg/s3 0.0.0-stage → 0.1.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/README.md +81 -2
- package/dist/chunk-HBRUN65D.js +144 -0
- package/dist/chunk-HBRUN65D.js.map +1 -0
- package/dist/client.cjs +150 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +53 -0
- package/dist/client.d.ts +53 -0
- package/dist/client.js +3 -0
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +309 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +109 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.js +298 -0
- package/dist/index.js.map +1 -0
- package/dist/preact.cjs +185 -0
- package/dist/preact.cjs.map +1 -0
- package/dist/preact.d.cts +14 -0
- package/dist/preact.d.ts +14 -0
- package/dist/preact.js +44 -0
- package/dist/preact.js.map +1 -0
- package/package.json +40 -4
package/dist/preact.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { uploadFile, cancelUpload } from './chunk-HBRUN65D.js';
|
|
2
|
+
import { useState, useRef, useCallback } from 'preact/hooks';
|
|
3
|
+
|
|
4
|
+
function useUpload(opts) {
|
|
5
|
+
const [status, setStatus] = useState("idle");
|
|
6
|
+
const [progress, setProgress] = useState(null);
|
|
7
|
+
const [error, setError] = useState(null);
|
|
8
|
+
const [result, setResult] = useState(null);
|
|
9
|
+
const ctl = useRef(null);
|
|
10
|
+
const file = useRef(null);
|
|
11
|
+
const start = useCallback(async (f) => {
|
|
12
|
+
file.current = f;
|
|
13
|
+
ctl.current = new AbortController();
|
|
14
|
+
setStatus("uploading");
|
|
15
|
+
setError(null);
|
|
16
|
+
setResult(null);
|
|
17
|
+
try {
|
|
18
|
+
const r = await uploadFile(f, { ...opts, signal: ctl.current.signal, onProgress: setProgress });
|
|
19
|
+
setResult(r);
|
|
20
|
+
setStatus("done");
|
|
21
|
+
return r;
|
|
22
|
+
} catch (e) {
|
|
23
|
+
if (ctl.current.signal.aborted) {
|
|
24
|
+
setStatus("paused");
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
setError(e);
|
|
28
|
+
setStatus("error");
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}, [opts.endpoint]);
|
|
32
|
+
const pause = useCallback(() => ctl.current?.abort(), []);
|
|
33
|
+
const cancel = useCallback(async () => {
|
|
34
|
+
ctl.current?.abort();
|
|
35
|
+
if (file.current) await cancelUpload(file.current, opts);
|
|
36
|
+
setStatus("idle");
|
|
37
|
+
setProgress(null);
|
|
38
|
+
}, [opts.endpoint]);
|
|
39
|
+
return { status, progress, error, result, start, pause, cancel };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { useUpload };
|
|
43
|
+
//# sourceMappingURL=preact.js.map
|
|
44
|
+
//# sourceMappingURL=preact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/preact.ts"],"names":[],"mappings":";;;AAMO,SAAS,UAAU,IAAA,EAAoD;AAC5E,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAI,SAAuB,MAAM,CAAA;AACzD,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAI,SAAgC,IAAI,CAAA;AACpE,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAAuB,IAAI,CAAA;AACrD,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAI,SAA8B,IAAI,CAAA;AAC9D,EAAA,MAAM,GAAA,GAAM,OAA+B,IAAI,CAAA;AAC/C,EAAA,MAAM,IAAA,GAAO,OAAoB,IAAI,CAAA;AAErC,EAAA,MAAM,KAAA,GAAQ,WAAA,CAAY,OAAO,CAAA,KAAY;AAC3C,IAAA,IAAA,CAAK,OAAA,GAAU,CAAA;AACf,IAAA,GAAA,CAAI,OAAA,GAAU,IAAI,eAAA,EAAgB;AAClC,IAAA,SAAA,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ook, deliberately NOT a visual component: the site owns its design.\nimport { useCallback, useRef, useState } from \"preact/hooks\";\nimport { cancelUpload, uploadFile, type UploadOptions, type UploadProgress, type UploadResult } from \"./client\";\n\nexport type UploadStatus = \"idle\" | \"uploading\" | \"paused\" | \"done\" | \"error\";\n\nexport function useUpload(opts: Omit<UploadOptions, \"signal\" | \"onProgress\">) {\n const [status, setStatus] = useState<UploadStatus>(\"idle\");\n const [progress, setProgress] = useState<UploadProgress | null>(null);\n const [error, setError] = useState<Error | null>(null);\n const [result, setResult] = useState<UploadResult | null>(null);\n const ctl = useRef<AbortController | null>(null);\n const file = useRef<Blob | null>(null);\n\n const start = useCallback(async (f: Blob) => {\n file.current = f;\n ctl.current = new AbortController();\n setStatus(\"uploading\"); setError(null); setResult(null);\n try {\n const r = await uploadFile(f, { ...opts, signal: ctl.current.signal, onProgress: setProgress });\n setResult(r); setStatus(\"done\");\n return r;\n } catch (e) {\n if (ctl.current.signal.aborted) { setStatus(\"paused\"); return null; }\n setError(e as Error); setStatus(\"error\");\n return null;\n }\n }, [opts.endpoint]);\n\n /** Stop now; start() with the same file resumes from the finished parts. */\n const pause = useCallback(() => ctl.current?.abort(), []);\n\n /** Stop and discard everything uploaded so far. */\n const cancel = useCallback(async () => {\n ctl.current?.abort();\n if (file.current) await cancelUpload(file.current, opts);\n setStatus(\"idle\"); setProgress(null);\n }, [opts.endpoint]);\n\n return { status, progress, error, result, start, pause, cancel };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@broberg/s3",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Upload and download files of any size DIRECTLY between the browser and S3-compatible storage (Cloudflare R2 in the EU by default; Tigris, AWS, MinIO by endpoint) — the site's server only issues short-lived, one-object signatures, so bytes never pass through it. Multipart upload with parallel parts, retry, progress (%, speed, time left) and resume after a dropped connection; presigned download links. One fetch handler (Request → Response) for Hono/Bun and Next, guarded by the site's own authorize() hook and a per-user object prefix. Preact hook, no visual component.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"files": ["dist", "README.md"],
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": { "types": "./dist/index.d.ts", "import": "./dist/index.js", "require": "./dist/index.cjs" },
|
|
14
|
+
"./client": { "types": "./dist/client.d.ts", "import": "./dist/client.js", "require": "./dist/client.cjs" },
|
|
15
|
+
"./preact": { "types": "./dist/preact.d.ts", "import": "./dist/preact.js", "require": "./dist/preact.cjs" },
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup",
|
|
20
|
+
"test": "vitest run --reporter=default --reporter=json --outputFile.json=.vitest-report/results.json",
|
|
21
|
+
"typecheck": "tsc --noEmit"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"aws4fetch": "^1.0.20"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"preact": ">=10"
|
|
28
|
+
},
|
|
29
|
+
"peerDependenciesMeta": {
|
|
30
|
+
"preact": { "optional": true }
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^22.0.0",
|
|
34
|
+
"preact": "^10.24.0",
|
|
35
|
+
"tsup": "^8.3.0",
|
|
36
|
+
"typescript": "^5.6.0",
|
|
37
|
+
"vitest": "^2.1.0"
|
|
38
|
+
},
|
|
39
|
+
"keywords": ["s3", "r2", "cloudflare", "tigris", "upload", "download", "multipart", "presigned", "large files", "resumable", "store filer", "upload af video", "broberg"],
|
|
40
|
+
"repository": { "type": "git", "url": "https://github.com/broberg-ai/components", "directory": "packages/s3" },
|
|
41
|
+
"publishConfig": { "access": "public" }
|
|
42
|
+
}
|