dn-react-router-toolkit 0.1.1 → 0.1.3
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/auth-kit/apple_auth.d.mts +24 -0
- package/dist/{esm/auth-kit → auth-kit}/apple_auth.d.ts +11 -2
- package/dist/auth-kit/apple_auth.js +75 -0
- package/dist/auth-kit/apple_auth.mjs +50 -0
- package/dist/auth-kit/auth_service.d.mts +73 -0
- package/dist/{esm/auth-kit → auth-kit}/auth_service.d.ts +17 -11
- package/dist/auth-kit/auth_service.js +257 -0
- package/dist/auth-kit/auth_service.mjs +218 -0
- package/dist/auth-kit/client/google_login_button.d.mts +9 -0
- package/dist/auth-kit/client/google_login_button.d.ts +9 -0
- package/dist/auth-kit/client/google_login_button.js +67 -0
- package/dist/auth-kit/client/google_login_button.mjs +32 -0
- package/dist/auth-kit/client/redirect_page.d.mts +5 -0
- package/dist/auth-kit/client/redirect_page.d.ts +5 -0
- package/dist/auth-kit/client/redirect_page.js +53 -0
- package/dist/auth-kit/client/redirect_page.mjs +18 -0
- package/dist/auth-kit/google_auth.d.mts +27 -0
- package/dist/{esm/auth-kit → auth-kit}/google_auth.d.ts +11 -2
- package/dist/auth-kit/google_auth.js +144 -0
- package/dist/auth-kit/google_auth.mjs +117 -0
- package/dist/auth-kit/jwt.d.mts +18 -0
- package/dist/{esm/auth-kit → auth-kit}/jwt.d.ts +5 -2
- package/dist/auth-kit/jwt.js +76 -0
- package/dist/auth-kit/jwt.mjs +51 -0
- package/dist/auth-kit/kakao_auth.d.mts +24 -0
- package/dist/{esm/auth-kit → auth-kit}/kakao_auth.d.ts +11 -2
- package/dist/auth-kit/kakao_auth.js +115 -0
- package/dist/auth-kit/kakao_auth.mjs +88 -0
- package/dist/auth-kit/repository.d.mts +42 -0
- package/dist/{esm/auth-kit → auth-kit}/repository.d.ts +3 -1
- package/dist/auth-kit/repository.js +18 -0
- package/dist/auth-kit/repository.mjs +0 -0
- package/dist/auth-kit/with_auth.d.mts +17 -0
- package/dist/auth-kit/with_auth.d.ts +17 -0
- package/dist/auth-kit/with_auth.js +106 -0
- package/dist/auth-kit/with_auth.mjs +69 -0
- package/dist/cn.d.mts +3 -0
- package/dist/cn.d.ts +3 -0
- package/dist/cn.js +32 -0
- package/dist/cn.mjs +7 -0
- package/dist/components/index.d.mts +5 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +261 -0
- package/dist/components/index.mjs +219 -0
- package/dist/components/modal/fullscreen_container.d.mts +7 -0
- package/dist/components/modal/fullscreen_container.d.ts +7 -0
- package/dist/components/modal/fullscreen_container.js +102 -0
- package/dist/components/modal/fullscreen_container.mjs +68 -0
- package/dist/components/modal/hooks.d.mts +18 -0
- package/dist/components/modal/hooks.d.ts +18 -0
- package/dist/components/modal/hooks.js +236 -0
- package/dist/components/modal/hooks.mjs +204 -0
- package/dist/components/modal/index.d.mts +4 -0
- package/dist/components/modal/index.d.ts +4 -0
- package/dist/components/modal/index.js +238 -0
- package/dist/components/modal/index.mjs +203 -0
- package/dist/components/modal/modal.d.mts +13 -0
- package/dist/components/modal/modal.d.ts +13 -0
- package/dist/components/modal/modal.js +155 -0
- package/dist/components/modal/modal.mjs +130 -0
- package/dist/components/styles.d.mts +9 -0
- package/dist/components/styles.d.ts +9 -0
- package/dist/components/styles.js +48 -0
- package/dist/components/styles.mjs +17 -0
- package/dist/date.d.mts +3 -0
- package/dist/date.d.ts +3 -0
- package/dist/date.js +63 -0
- package/dist/date.mjs +28 -0
- package/dist/file-kit/cdn.d.mts +5 -0
- package/dist/file-kit/cdn.d.ts +5 -0
- package/dist/file-kit/cdn.js +34 -0
- package/dist/file-kit/cdn.mjs +9 -0
- package/dist/file-kit/client/drop_file_input.d.mts +33 -0
- package/dist/{esm/file-kit → file-kit}/client/drop_file_input.d.ts +10 -8
- package/dist/file-kit/client/drop_file_input.js +235 -0
- package/dist/file-kit/client/drop_file_input.mjs +205 -0
- package/dist/file-kit/client/file_uploader.d.mts +13 -0
- package/dist/{esm/file-kit → file-kit}/client/file_uploader.d.ts +4 -2
- package/dist/file-kit/client/file_uploader.js +115 -0
- package/dist/file-kit/client/file_uploader.mjs +90 -0
- package/dist/file-kit/file_service.d.mts +26 -0
- package/dist/{esm/file-kit → file-kit}/file_service.d.ts +7 -4
- package/dist/file-kit/file_service.js +60 -0
- package/dist/file-kit/file_service.mjs +35 -0
- package/dist/file-kit/object_storage.d.mts +17 -0
- package/dist/{esm/file-kit → file-kit}/object_storage.d.ts +6 -2
- package/dist/file-kit/object_storage.js +78 -0
- package/dist/file-kit/object_storage.mjs +57 -0
- package/dist/file-kit/repository.d.mts +16 -0
- package/dist/{esm/file-kit → file-kit}/repository.d.ts +3 -1
- package/dist/file-kit/repository.js +18 -0
- package/dist/file-kit/repository.mjs +0 -0
- package/dist/file-kit/responsive_image.d.mts +20 -0
- package/dist/file-kit/responsive_image.d.ts +20 -0
- package/dist/file-kit/responsive_image.js +123 -0
- package/dist/file-kit/responsive_image.mjs +87 -0
- package/dist/http-kit/index.d.mts +1 -0
- package/dist/http-kit/index.d.ts +1 -0
- package/dist/http-kit/index.js +111 -0
- package/dist/http-kit/index.mjs +68 -0
- package/dist/http-kit/response.d.mts +19 -0
- package/dist/http-kit/response.d.ts +19 -0
- package/dist/http-kit/response.js +109 -0
- package/dist/http-kit/response.mjs +68 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +91 -0
- package/dist/index.mjs +51 -0
- package/dist/route/api/auth/login/[provider]/route.js +113 -0
- package/dist/route/api/auth/login/[provider]/route.mjs +86 -0
- package/dist/route/api/auth/login/_provider_/route.d.mts +20 -0
- package/dist/route/api/auth/login/_provider_/route.d.ts +20 -0
- package/dist/route/api/auth/login/route.d.mts +14 -0
- package/dist/route/api/auth/login/route.d.ts +14 -0
- package/dist/route/api/auth/login/route.js +107 -0
- package/dist/route/api/auth/login/route.mjs +80 -0
- package/dist/route/api/auth/logout/route.d.mts +14 -0
- package/dist/route/api/auth/logout/route.d.ts +14 -0
- package/dist/route/api/auth/logout/route.js +98 -0
- package/dist/route/api/auth/logout/route.mjs +71 -0
- package/dist/route/api/auth/refresh/route.d.mts +13 -0
- package/dist/route/api/auth/refresh/route.d.ts +13 -0
- package/dist/route/api/auth/refresh/route.js +92 -0
- package/dist/route/api/auth/refresh/route.mjs +65 -0
- package/dist/route/api/auth/route.d.mts +13 -0
- package/dist/route/api/auth/route.d.ts +13 -0
- package/dist/route/api/auth/route.js +82 -0
- package/dist/route/api/auth/route.mjs +55 -0
- package/dist/route/api/files/[fileId]/route.js +99 -0
- package/dist/route/api/files/[fileId]/route.mjs +72 -0
- package/dist/route/api/files/_fileId_/route.d.mts +17 -0
- package/dist/route/api/files/_fileId_/route.d.ts +17 -0
- package/dist/route/api/files/route.d.mts +16 -0
- package/dist/route/api/files/route.d.ts +16 -0
- package/dist/route/api/files/route.js +106 -0
- package/dist/route/api/files/route.mjs +79 -0
- package/dist/route/api.d.mts +29 -0
- package/dist/route/api.d.ts +29 -0
- package/dist/route/api.js +395 -0
- package/dist/route/api.mjs +368 -0
- package/dist/route/auth/callback/[provider]/route.js +120 -0
- package/dist/route/auth/callback/[provider]/route.mjs +93 -0
- package/dist/route/auth/callback/_provider_/route.d.mts +20 -0
- package/dist/route/auth/callback/_provider_/route.d.ts +20 -0
- package/dist/seo-kit/index.d.mts +6 -0
- package/dist/seo-kit/index.d.ts +6 -0
- package/dist/seo-kit/index.js +321 -0
- package/dist/seo-kit/index.mjs +282 -0
- package/dist/seo-kit/loader.d.mts +7 -0
- package/dist/seo-kit/loader.d.ts +7 -0
- package/dist/seo-kit/loader.js +43 -0
- package/dist/seo-kit/loader.mjs +18 -0
- package/dist/seo-kit/seo.d.mts +103 -0
- package/dist/{esm/seo-kit → seo-kit}/seo.d.ts +10 -6
- package/dist/seo-kit/seo.js +286 -0
- package/dist/seo-kit/seo.mjs +251 -0
- package/dist/seo-kit/seo_loader.d.mts +16 -0
- package/dist/seo-kit/seo_loader.d.ts +16 -0
- package/dist/seo-kit/seo_loader.js +68 -0
- package/dist/seo-kit/seo_loader.mjs +31 -0
- package/dist/singleton.d.mts +3 -0
- package/dist/singleton.d.ts +3 -0
- package/dist/singleton.js +37 -0
- package/dist/singleton.mjs +12 -0
- package/dist/slug.d.mts +3 -0
- package/dist/slug.d.ts +3 -0
- package/dist/slug.js +32 -0
- package/dist/slug.mjs +7 -0
- package/package.json +36 -34
- package/tsup.config.ts +9 -0
- package/dist/cjs/auth-kit/apple_auth.js +0 -61
- package/dist/cjs/auth-kit/auth_service.js +0 -204
- package/dist/cjs/auth-kit/client/google_login_button.js +0 -19
- package/dist/cjs/auth-kit/client/redirect_page.js +0 -18
- package/dist/cjs/auth-kit/google_auth.js +0 -69
- package/dist/cjs/auth-kit/jwt.js +0 -54
- package/dist/cjs/auth-kit/kakao_auth.js +0 -43
- package/dist/cjs/auth-kit/repository.js +0 -2
- package/dist/cjs/auth-kit/with_auth.js +0 -46
- package/dist/cjs/cn.js +0 -6
- package/dist/cjs/components/index.js +0 -18
- package/dist/cjs/components/modal/fullscreen_container.js +0 -49
- package/dist/cjs/components/modal/hooks.js +0 -76
- package/dist/cjs/components/modal/index.js +0 -19
- package/dist/cjs/components/modal/modal.js +0 -79
- package/dist/cjs/components/styles.js +0 -10
- package/dist/cjs/date.js +0 -31
- package/dist/cjs/file-kit/cdn.js +0 -9
- package/dist/cjs/file-kit/client/drop_file_input.js +0 -148
- package/dist/cjs/file-kit/client/file_uploader.js +0 -88
- package/dist/cjs/file-kit/file_service.js +0 -32
- package/dist/cjs/file-kit/object_storage.js +0 -51
- package/dist/cjs/file-kit/repository.js +0 -2
- package/dist/cjs/file-kit/responsive_image.js +0 -63
- package/dist/cjs/http-kit/index.js +0 -17
- package/dist/cjs/http-kit/response.js +0 -37
- package/dist/cjs/index.js +0 -20
- package/dist/cjs/route/api/auth/login/[provider]/route.js +0 -36
- package/dist/cjs/route/api/auth/login/route.js +0 -35
- package/dist/cjs/route/api/auth/logout/route.js +0 -22
- package/dist/cjs/route/api/auth/refresh/route.js +0 -22
- package/dist/cjs/route/api/auth/route.js +0 -12
- package/dist/cjs/route/api/files/[fileId]/route.js +0 -20
- package/dist/cjs/route/api/files/route.js +0 -34
- package/dist/cjs/route/auth/callback/[provider]/route.js +0 -38
- package/dist/cjs/route/index.js +0 -80
- package/dist/cjs/seo-kit/index.js +0 -19
- package/dist/cjs/seo-kit/loader.js +0 -17
- package/dist/cjs/seo-kit/seo.js +0 -278
- package/dist/cjs/seo-kit/seo_loader.js +0 -15
- package/dist/cjs/singleton.js +0 -12
- package/dist/cjs/slug.js +0 -10
- package/dist/esm/auth-kit/apple_auth.js +0 -57
- package/dist/esm/auth-kit/auth_service.js +0 -197
- package/dist/esm/auth-kit/client/google_login_button.d.ts +0 -5
- package/dist/esm/auth-kit/client/google_login_button.js +0 -16
- package/dist/esm/auth-kit/client/redirect_page.d.ts +0 -1
- package/dist/esm/auth-kit/client/redirect_page.js +0 -15
- package/dist/esm/auth-kit/google_auth.js +0 -65
- package/dist/esm/auth-kit/jwt.js +0 -50
- package/dist/esm/auth-kit/kakao_auth.js +0 -39
- package/dist/esm/auth-kit/repository.js +0 -1
- package/dist/esm/auth-kit/with_auth.d.ts +0 -12
- package/dist/esm/auth-kit/with_auth.js +0 -43
- package/dist/esm/cn.d.ts +0 -1
- package/dist/esm/cn.js +0 -3
- package/dist/esm/components/index.d.ts +0 -2
- package/dist/esm/components/index.js +0 -2
- package/dist/esm/components/modal/fullscreen_container.d.ts +0 -5
- package/dist/esm/components/modal/fullscreen_container.js +0 -45
- package/dist/esm/components/modal/hooks.d.ts +0 -15
- package/dist/esm/components/modal/hooks.js +0 -67
- package/dist/esm/components/modal/index.d.ts +0 -3
- package/dist/esm/components/modal/index.js +0 -3
- package/dist/esm/components/modal/modal.d.ts +0 -10
- package/dist/esm/components/modal/modal.js +0 -43
- package/dist/esm/components/styles.d.ts +0 -7
- package/dist/esm/components/styles.js +0 -7
- package/dist/esm/date.d.ts +0 -1
- package/dist/esm/date.js +0 -24
- package/dist/esm/file-kit/cdn.d.ts +0 -3
- package/dist/esm/file-kit/cdn.js +0 -5
- package/dist/esm/file-kit/client/drop_file_input.js +0 -144
- package/dist/esm/file-kit/client/file_uploader.js +0 -84
- package/dist/esm/file-kit/file_service.js +0 -28
- package/dist/esm/file-kit/object_storage.js +0 -47
- package/dist/esm/file-kit/repository.js +0 -1
- package/dist/esm/file-kit/responsive_image.d.ts +0 -17
- package/dist/esm/file-kit/responsive_image.js +0 -58
- package/dist/esm/http-kit/index.d.ts +0 -1
- package/dist/esm/http-kit/index.js +0 -1
- package/dist/esm/http-kit/response.d.ts +0 -17
- package/dist/esm/http-kit/response.js +0 -31
- package/dist/esm/index.d.ts +0 -4
- package/dist/esm/index.js +0 -4
- package/dist/esm/route/api/auth/login/[provider]/route.d.ts +0 -10
- package/dist/esm/route/api/auth/login/[provider]/route.js +0 -32
- package/dist/esm/route/api/auth/login/route.d.ts +0 -6
- package/dist/esm/route/api/auth/login/route.js +0 -31
- package/dist/esm/route/api/auth/logout/route.d.ts +0 -6
- package/dist/esm/route/api/auth/logout/route.js +0 -18
- package/dist/esm/route/api/auth/refresh/route.d.ts +0 -4
- package/dist/esm/route/api/auth/refresh/route.js +0 -18
- package/dist/esm/route/api/auth/route.d.ts +0 -4
- package/dist/esm/route/api/auth/route.js +0 -8
- package/dist/esm/route/api/files/[fileId]/route.d.ts +0 -8
- package/dist/esm/route/api/files/[fileId]/route.js +0 -16
- package/dist/esm/route/api/files/route.d.ts +0 -6
- package/dist/esm/route/api/files/route.js +0 -30
- package/dist/esm/route/auth/callback/[provider]/route.d.ts +0 -11
- package/dist/esm/route/auth/callback/[provider]/route.js +0 -34
- package/dist/esm/route/index.d.ts +0 -22
- package/dist/esm/route/index.js +0 -76
- package/dist/esm/seo-kit/index.d.ts +0 -3
- package/dist/esm/seo-kit/index.js +0 -3
- package/dist/esm/seo-kit/loader.d.ts +0 -5
- package/dist/esm/seo-kit/loader.js +0 -14
- package/dist/esm/seo-kit/seo.js +0 -275
- package/dist/esm/seo-kit/seo_loader.d.ts +0 -12
- package/dist/esm/seo-kit/seo_loader.js +0 -12
- package/dist/esm/singleton.d.ts +0 -1
- package/dist/esm/singleton.js +0 -9
- package/dist/esm/slug.d.ts +0 -1
- package/dist/esm/slug.js +0 -6
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/file-kit/client/drop_file_input.tsx
|
|
31
|
+
var drop_file_input_exports = {};
|
|
32
|
+
__export(drop_file_input_exports, {
|
|
33
|
+
DropFileMessageBox: () => DropFileMessageBox,
|
|
34
|
+
default: () => drop_file_input_default,
|
|
35
|
+
useDropFileInput: () => useDropFileInput
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(drop_file_input_exports);
|
|
38
|
+
var import_react = __toESM(require("react"));
|
|
39
|
+
var import_uuid = require("uuid");
|
|
40
|
+
|
|
41
|
+
// src/cn.ts
|
|
42
|
+
function cn(...classes) {
|
|
43
|
+
return classes.filter(Boolean).join(" ").trim();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/file-kit/client/drop_file_input.tsx
|
|
47
|
+
function useDropFileInput({
|
|
48
|
+
defaultValue,
|
|
49
|
+
options,
|
|
50
|
+
uploadFile,
|
|
51
|
+
onFileInput,
|
|
52
|
+
onFileUploaded,
|
|
53
|
+
limit
|
|
54
|
+
} = {}) {
|
|
55
|
+
const [files, setFiles] = (0, import_react.useState)(
|
|
56
|
+
defaultValue ? (Array.isArray(defaultValue) ? defaultValue : [defaultValue]).map((v) => {
|
|
57
|
+
return {
|
|
58
|
+
key: (0, import_uuid.v4)(),
|
|
59
|
+
item: v
|
|
60
|
+
};
|
|
61
|
+
}).slice(0, limit ? limit : Infinity) : []
|
|
62
|
+
);
|
|
63
|
+
const fileRef = (0, import_react.useRef)([]);
|
|
64
|
+
(0, import_react.useEffect)(() => {
|
|
65
|
+
fileRef.current = files;
|
|
66
|
+
}, [files]);
|
|
67
|
+
const Component = (0, import_react.useCallback)(
|
|
68
|
+
function Component2({
|
|
69
|
+
className,
|
|
70
|
+
container = "border border-dashed border-neutral-300 rounded flex items-center justify-center",
|
|
71
|
+
draggingClassName,
|
|
72
|
+
name,
|
|
73
|
+
hideMessage = false,
|
|
74
|
+
children,
|
|
75
|
+
...props
|
|
76
|
+
}) {
|
|
77
|
+
const [isDragging, setIsDragging] = (0, import_react.useState)(false);
|
|
78
|
+
const handleDragEnter = (0, import_react.useCallback)((e) => {
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
e.stopPropagation();
|
|
81
|
+
setIsDragging(true);
|
|
82
|
+
}, []);
|
|
83
|
+
const handleDragLeave = (0, import_react.useCallback)((e) => {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
e.stopPropagation();
|
|
86
|
+
setIsDragging(false);
|
|
87
|
+
}, []);
|
|
88
|
+
const handleDragOver = (0, import_react.useCallback)((e) => {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
e.stopPropagation();
|
|
91
|
+
}, []);
|
|
92
|
+
const handleFiles = (0, import_react.useCallback)(
|
|
93
|
+
async (files2) => {
|
|
94
|
+
if (limit && fileRef.current.length >= limit) {
|
|
95
|
+
alert(`\uD30C\uC77C\uC740 \uCD5C\uB300 ${limit}\uAC1C \uC5C5\uB85C\uB4DC\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const filteredFiles = files2.filter((file) => {
|
|
99
|
+
return true;
|
|
100
|
+
});
|
|
101
|
+
if (files2.length !== filteredFiles.length) {
|
|
102
|
+
alert(`${props.accept} \uD615\uC2DD\uC758 \uD30C\uC77C\uB9CC \uC5C5\uB85C\uB4DC\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.`);
|
|
103
|
+
}
|
|
104
|
+
const limitedFiles = filteredFiles.slice(
|
|
105
|
+
0,
|
|
106
|
+
limit ? limit - fileRef.current.length : Infinity
|
|
107
|
+
);
|
|
108
|
+
if (limitedFiles.length === 0) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (onFileInput) {
|
|
112
|
+
onFileInput(limitedFiles);
|
|
113
|
+
}
|
|
114
|
+
for (const file of limitedFiles) {
|
|
115
|
+
const fileItem = {
|
|
116
|
+
key: (0, import_uuid.v4)()
|
|
117
|
+
};
|
|
118
|
+
setFiles((prevFiles) => [...prevFiles, fileItem]);
|
|
119
|
+
uploadFile?.(file, options).then(async (item) => {
|
|
120
|
+
await onFileUploaded?.(item);
|
|
121
|
+
setFiles(
|
|
122
|
+
(prevFiles) => prevFiles.map((f) => {
|
|
123
|
+
if (f.key === fileItem.key) {
|
|
124
|
+
return {
|
|
125
|
+
...f,
|
|
126
|
+
item
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return f;
|
|
130
|
+
})
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
[props.accept]
|
|
136
|
+
);
|
|
137
|
+
const handleDrop = (0, import_react.useCallback)(
|
|
138
|
+
(e) => {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
e.stopPropagation();
|
|
141
|
+
setIsDragging(false);
|
|
142
|
+
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
|
|
143
|
+
handleFiles(Array.from(e.dataTransfer.files));
|
|
144
|
+
e.dataTransfer.clearData();
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
[handleFiles]
|
|
148
|
+
);
|
|
149
|
+
const inputRef = (0, import_react.useRef)(null);
|
|
150
|
+
const handleClick = (0, import_react.useCallback)(() => {
|
|
151
|
+
inputRef.current?.click();
|
|
152
|
+
}, []);
|
|
153
|
+
const handleKeyDown = (0, import_react.useCallback)(
|
|
154
|
+
(e) => {
|
|
155
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
156
|
+
handleClick();
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
[handleClick]
|
|
160
|
+
);
|
|
161
|
+
const handleChange = (0, import_react.useCallback)(
|
|
162
|
+
(e) => {
|
|
163
|
+
if (e.target.files && e.target.files.length > 0) {
|
|
164
|
+
handleFiles(Array.from(e.target.files));
|
|
165
|
+
e.target.value = "";
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
[handleFiles]
|
|
169
|
+
);
|
|
170
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
171
|
+
"div",
|
|
172
|
+
{
|
|
173
|
+
className: cn(
|
|
174
|
+
className,
|
|
175
|
+
container,
|
|
176
|
+
draggingClassName?.(isDragging) || (isDragging ? "bg-neutral-300/25" : "hover:bg-neutral-300/25"),
|
|
177
|
+
"transition-colors cursor-pointer"
|
|
178
|
+
),
|
|
179
|
+
onDragEnter: handleDragEnter,
|
|
180
|
+
onDragLeave: handleDragLeave,
|
|
181
|
+
onDragOver: handleDragOver,
|
|
182
|
+
onDrop: handleDrop,
|
|
183
|
+
onClick: handleClick,
|
|
184
|
+
onChange: handleChange,
|
|
185
|
+
onKeyDown: handleKeyDown,
|
|
186
|
+
tabIndex: 0,
|
|
187
|
+
role: "button"
|
|
188
|
+
},
|
|
189
|
+
/* @__PURE__ */ import_react.default.createElement("input", { ...props, defaultValue: "", type: "file", hidden: true, ref: inputRef }),
|
|
190
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
191
|
+
"input",
|
|
192
|
+
{
|
|
193
|
+
name,
|
|
194
|
+
hidden: true,
|
|
195
|
+
readOnly: true,
|
|
196
|
+
value: files.map((file) => {
|
|
197
|
+
if (file.item && typeof file.item === "object" && "id" in file.item) {
|
|
198
|
+
return file.item.id;
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
}).filter(Boolean).join(",")
|
|
202
|
+
}
|
|
203
|
+
),
|
|
204
|
+
children || !(hideMessage && !isDragging) && /* @__PURE__ */ import_react.default.createElement(DropFileMessageBox, null)
|
|
205
|
+
);
|
|
206
|
+
},
|
|
207
|
+
[limit, fileRef, files, options, uploadFile, onFileInput, onFileUploaded]
|
|
208
|
+
);
|
|
209
|
+
const loadedFileIds = files.map((file) => {
|
|
210
|
+
if (file.item && typeof file.item === "object" && "id" in file.item) {
|
|
211
|
+
return file.item.id;
|
|
212
|
+
}
|
|
213
|
+
return null;
|
|
214
|
+
}).filter(Boolean);
|
|
215
|
+
const loadedFileIdsString = loadedFileIds.join(",");
|
|
216
|
+
const fileIds = (0, import_react.useMemo)(
|
|
217
|
+
() => loadedFileIdsString.split(",").filter(Boolean),
|
|
218
|
+
[loadedFileIdsString]
|
|
219
|
+
);
|
|
220
|
+
return {
|
|
221
|
+
fileIds,
|
|
222
|
+
files,
|
|
223
|
+
setFiles,
|
|
224
|
+
Component
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function DropFileMessageBox() {
|
|
228
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { className: "text-sm pointer-events-none flex justify-center items-center" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "flex flex-col items-center" }, /* @__PURE__ */ import_react.default.createElement("span", null, "\uD30C\uC77C\uC744 \uC5EC\uAE30\uB85C \uB04C\uC5B4\uB2E4 \uB193\uAC70\uB098 \uD074\uB9AD\uD574\uC11C \uC120\uD0DD\uD574 \uC8FC\uC138\uC694")));
|
|
229
|
+
}
|
|
230
|
+
var drop_file_input_default = useDropFileInput;
|
|
231
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
232
|
+
0 && (module.exports = {
|
|
233
|
+
DropFileMessageBox,
|
|
234
|
+
useDropFileInput
|
|
235
|
+
});
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// src/file-kit/client/drop_file_input.tsx
|
|
2
|
+
import React, {
|
|
3
|
+
useState,
|
|
4
|
+
useCallback,
|
|
5
|
+
useRef,
|
|
6
|
+
useEffect,
|
|
7
|
+
useMemo
|
|
8
|
+
} from "react";
|
|
9
|
+
import { v4 } from "uuid";
|
|
10
|
+
|
|
11
|
+
// src/cn.ts
|
|
12
|
+
function cn(...classes) {
|
|
13
|
+
return classes.filter(Boolean).join(" ").trim();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/file-kit/client/drop_file_input.tsx
|
|
17
|
+
function useDropFileInput({
|
|
18
|
+
defaultValue,
|
|
19
|
+
options,
|
|
20
|
+
uploadFile,
|
|
21
|
+
onFileInput,
|
|
22
|
+
onFileUploaded,
|
|
23
|
+
limit
|
|
24
|
+
} = {}) {
|
|
25
|
+
const [files, setFiles] = useState(
|
|
26
|
+
defaultValue ? (Array.isArray(defaultValue) ? defaultValue : [defaultValue]).map((v) => {
|
|
27
|
+
return {
|
|
28
|
+
key: v4(),
|
|
29
|
+
item: v
|
|
30
|
+
};
|
|
31
|
+
}).slice(0, limit ? limit : Infinity) : []
|
|
32
|
+
);
|
|
33
|
+
const fileRef = useRef([]);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
fileRef.current = files;
|
|
36
|
+
}, [files]);
|
|
37
|
+
const Component = useCallback(
|
|
38
|
+
function Component2({
|
|
39
|
+
className,
|
|
40
|
+
container = "border border-dashed border-neutral-300 rounded flex items-center justify-center",
|
|
41
|
+
draggingClassName,
|
|
42
|
+
name,
|
|
43
|
+
hideMessage = false,
|
|
44
|
+
children,
|
|
45
|
+
...props
|
|
46
|
+
}) {
|
|
47
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
48
|
+
const handleDragEnter = useCallback((e) => {
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
e.stopPropagation();
|
|
51
|
+
setIsDragging(true);
|
|
52
|
+
}, []);
|
|
53
|
+
const handleDragLeave = useCallback((e) => {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
e.stopPropagation();
|
|
56
|
+
setIsDragging(false);
|
|
57
|
+
}, []);
|
|
58
|
+
const handleDragOver = useCallback((e) => {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
e.stopPropagation();
|
|
61
|
+
}, []);
|
|
62
|
+
const handleFiles = useCallback(
|
|
63
|
+
async (files2) => {
|
|
64
|
+
if (limit && fileRef.current.length >= limit) {
|
|
65
|
+
alert(`\uD30C\uC77C\uC740 \uCD5C\uB300 ${limit}\uAC1C \uC5C5\uB85C\uB4DC\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const filteredFiles = files2.filter((file) => {
|
|
69
|
+
return true;
|
|
70
|
+
});
|
|
71
|
+
if (files2.length !== filteredFiles.length) {
|
|
72
|
+
alert(`${props.accept} \uD615\uC2DD\uC758 \uD30C\uC77C\uB9CC \uC5C5\uB85C\uB4DC\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.`);
|
|
73
|
+
}
|
|
74
|
+
const limitedFiles = filteredFiles.slice(
|
|
75
|
+
0,
|
|
76
|
+
limit ? limit - fileRef.current.length : Infinity
|
|
77
|
+
);
|
|
78
|
+
if (limitedFiles.length === 0) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (onFileInput) {
|
|
82
|
+
onFileInput(limitedFiles);
|
|
83
|
+
}
|
|
84
|
+
for (const file of limitedFiles) {
|
|
85
|
+
const fileItem = {
|
|
86
|
+
key: v4()
|
|
87
|
+
};
|
|
88
|
+
setFiles((prevFiles) => [...prevFiles, fileItem]);
|
|
89
|
+
uploadFile?.(file, options).then(async (item) => {
|
|
90
|
+
await onFileUploaded?.(item);
|
|
91
|
+
setFiles(
|
|
92
|
+
(prevFiles) => prevFiles.map((f) => {
|
|
93
|
+
if (f.key === fileItem.key) {
|
|
94
|
+
return {
|
|
95
|
+
...f,
|
|
96
|
+
item
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return f;
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
[props.accept]
|
|
106
|
+
);
|
|
107
|
+
const handleDrop = useCallback(
|
|
108
|
+
(e) => {
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
e.stopPropagation();
|
|
111
|
+
setIsDragging(false);
|
|
112
|
+
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
|
|
113
|
+
handleFiles(Array.from(e.dataTransfer.files));
|
|
114
|
+
e.dataTransfer.clearData();
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
[handleFiles]
|
|
118
|
+
);
|
|
119
|
+
const inputRef = useRef(null);
|
|
120
|
+
const handleClick = useCallback(() => {
|
|
121
|
+
inputRef.current?.click();
|
|
122
|
+
}, []);
|
|
123
|
+
const handleKeyDown = useCallback(
|
|
124
|
+
(e) => {
|
|
125
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
126
|
+
handleClick();
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
[handleClick]
|
|
130
|
+
);
|
|
131
|
+
const handleChange = useCallback(
|
|
132
|
+
(e) => {
|
|
133
|
+
if (e.target.files && e.target.files.length > 0) {
|
|
134
|
+
handleFiles(Array.from(e.target.files));
|
|
135
|
+
e.target.value = "";
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
[handleFiles]
|
|
139
|
+
);
|
|
140
|
+
return /* @__PURE__ */ React.createElement(
|
|
141
|
+
"div",
|
|
142
|
+
{
|
|
143
|
+
className: cn(
|
|
144
|
+
className,
|
|
145
|
+
container,
|
|
146
|
+
draggingClassName?.(isDragging) || (isDragging ? "bg-neutral-300/25" : "hover:bg-neutral-300/25"),
|
|
147
|
+
"transition-colors cursor-pointer"
|
|
148
|
+
),
|
|
149
|
+
onDragEnter: handleDragEnter,
|
|
150
|
+
onDragLeave: handleDragLeave,
|
|
151
|
+
onDragOver: handleDragOver,
|
|
152
|
+
onDrop: handleDrop,
|
|
153
|
+
onClick: handleClick,
|
|
154
|
+
onChange: handleChange,
|
|
155
|
+
onKeyDown: handleKeyDown,
|
|
156
|
+
tabIndex: 0,
|
|
157
|
+
role: "button"
|
|
158
|
+
},
|
|
159
|
+
/* @__PURE__ */ React.createElement("input", { ...props, defaultValue: "", type: "file", hidden: true, ref: inputRef }),
|
|
160
|
+
/* @__PURE__ */ React.createElement(
|
|
161
|
+
"input",
|
|
162
|
+
{
|
|
163
|
+
name,
|
|
164
|
+
hidden: true,
|
|
165
|
+
readOnly: true,
|
|
166
|
+
value: files.map((file) => {
|
|
167
|
+
if (file.item && typeof file.item === "object" && "id" in file.item) {
|
|
168
|
+
return file.item.id;
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
}).filter(Boolean).join(",")
|
|
172
|
+
}
|
|
173
|
+
),
|
|
174
|
+
children || !(hideMessage && !isDragging) && /* @__PURE__ */ React.createElement(DropFileMessageBox, null)
|
|
175
|
+
);
|
|
176
|
+
},
|
|
177
|
+
[limit, fileRef, files, options, uploadFile, onFileInput, onFileUploaded]
|
|
178
|
+
);
|
|
179
|
+
const loadedFileIds = files.map((file) => {
|
|
180
|
+
if (file.item && typeof file.item === "object" && "id" in file.item) {
|
|
181
|
+
return file.item.id;
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
}).filter(Boolean);
|
|
185
|
+
const loadedFileIdsString = loadedFileIds.join(",");
|
|
186
|
+
const fileIds = useMemo(
|
|
187
|
+
() => loadedFileIdsString.split(",").filter(Boolean),
|
|
188
|
+
[loadedFileIdsString]
|
|
189
|
+
);
|
|
190
|
+
return {
|
|
191
|
+
fileIds,
|
|
192
|
+
files,
|
|
193
|
+
setFiles,
|
|
194
|
+
Component
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function DropFileMessageBox() {
|
|
198
|
+
return /* @__PURE__ */ React.createElement("div", { className: "text-sm pointer-events-none flex justify-center items-center" }, /* @__PURE__ */ React.createElement("div", { className: "flex flex-col items-center" }, /* @__PURE__ */ React.createElement("span", null, "\uD30C\uC77C\uC744 \uC5EC\uAE30\uB85C \uB04C\uC5B4\uB2E4 \uB193\uAC70\uB098 \uD074\uB9AD\uD574\uC11C \uC120\uD0DD\uD574 \uC8FC\uC138\uC694")));
|
|
199
|
+
}
|
|
200
|
+
var drop_file_input_default = useDropFileInput;
|
|
201
|
+
export {
|
|
202
|
+
DropFileMessageBox,
|
|
203
|
+
drop_file_input_default as default,
|
|
204
|
+
useDropFileInput
|
|
205
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type FileUploaderOptions = {
|
|
2
|
+
metadata?: Record<string, unknown>;
|
|
3
|
+
};
|
|
4
|
+
declare class FileUploader {
|
|
5
|
+
endpoint: string;
|
|
6
|
+
constructor(endpoint?: string);
|
|
7
|
+
formatSize: (size: number) => string;
|
|
8
|
+
uploadFile(file: File, options?: FileUploaderOptions): Promise<any>;
|
|
9
|
+
uploadBlob(blob: Blob, name?: string, options?: FileUploaderOptions): Promise<any>;
|
|
10
|
+
deleteFile(fileId: string): Promise<boolean>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { FileUploader, type FileUploaderOptions };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
type FileUploaderOptions = {
|
|
2
2
|
metadata?: Record<string, unknown>;
|
|
3
3
|
};
|
|
4
|
-
|
|
4
|
+
declare class FileUploader {
|
|
5
5
|
endpoint: string;
|
|
6
6
|
constructor(endpoint?: string);
|
|
7
7
|
formatSize: (size: number) => string;
|
|
@@ -9,3 +9,5 @@ export declare class FileUploader {
|
|
|
9
9
|
uploadBlob(blob: Blob, name?: string, options?: FileUploaderOptions): Promise<any>;
|
|
10
10
|
deleteFile(fileId: string): Promise<boolean>;
|
|
11
11
|
}
|
|
12
|
+
|
|
13
|
+
export { FileUploader, type FileUploaderOptions };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/file-kit/client/file_uploader.ts
|
|
21
|
+
var file_uploader_exports = {};
|
|
22
|
+
__export(file_uploader_exports, {
|
|
23
|
+
FileUploader: () => FileUploader
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(file_uploader_exports);
|
|
26
|
+
var FileUploader = class {
|
|
27
|
+
endpoint;
|
|
28
|
+
constructor(endpoint = "/api/files") {
|
|
29
|
+
this.endpoint = endpoint;
|
|
30
|
+
}
|
|
31
|
+
formatSize = (size) => {
|
|
32
|
+
if (size < 1024) {
|
|
33
|
+
return `${size} B`;
|
|
34
|
+
}
|
|
35
|
+
if (size < 1024 * 1024) {
|
|
36
|
+
return `${(size / 1024).toFixed(2)} KB`;
|
|
37
|
+
}
|
|
38
|
+
return `${(size / (1024 * 1024)).toFixed(2)} MB`;
|
|
39
|
+
};
|
|
40
|
+
uploadFile(file, options = {}) {
|
|
41
|
+
return this.uploadBlob(file, file.name, options);
|
|
42
|
+
}
|
|
43
|
+
async uploadBlob(blob, name = "blob", options = {}) {
|
|
44
|
+
const { type, size } = blob;
|
|
45
|
+
const metadataForMedia = await new Promise(
|
|
46
|
+
(resolve, reject) => {
|
|
47
|
+
if (blob.type.startsWith("image/")) {
|
|
48
|
+
const img = new Image();
|
|
49
|
+
img.src = URL.createObjectURL(blob);
|
|
50
|
+
img.onload = () => {
|
|
51
|
+
resolve({
|
|
52
|
+
...options.metadata,
|
|
53
|
+
width: img.width,
|
|
54
|
+
height: img.height
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
img.onerror = reject;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (blob.type.startsWith("video/")) {
|
|
61
|
+
const video = document.createElement("video");
|
|
62
|
+
video.src = URL.createObjectURL(blob);
|
|
63
|
+
video.onloadedmetadata = () => {
|
|
64
|
+
resolve({
|
|
65
|
+
...options.metadata,
|
|
66
|
+
width: video.videoWidth,
|
|
67
|
+
height: video.videoHeight,
|
|
68
|
+
duration: video.duration
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
video.onerror = reject;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
resolve(options.metadata || {});
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
const res1 = await fetch(this.endpoint, {
|
|
78
|
+
method: "POST",
|
|
79
|
+
body: JSON.stringify({
|
|
80
|
+
name: name.replace(/ /g, "_"),
|
|
81
|
+
type,
|
|
82
|
+
size,
|
|
83
|
+
metadata: metadataForMedia
|
|
84
|
+
})
|
|
85
|
+
});
|
|
86
|
+
if (!res1.ok) {
|
|
87
|
+
const message = await res1.json();
|
|
88
|
+
throw new Error(message);
|
|
89
|
+
}
|
|
90
|
+
const result = await res1.json();
|
|
91
|
+
const { signedUrl, file } = result;
|
|
92
|
+
const res2 = await fetch(signedUrl, {
|
|
93
|
+
method: "PUT",
|
|
94
|
+
body: blob
|
|
95
|
+
});
|
|
96
|
+
if (!res2.ok) {
|
|
97
|
+
throw new Error(await res2.text());
|
|
98
|
+
}
|
|
99
|
+
return file;
|
|
100
|
+
}
|
|
101
|
+
async deleteFile(fileId) {
|
|
102
|
+
const res = await fetch(`${this.endpoint}/${fileId}`, {
|
|
103
|
+
method: "DELETE"
|
|
104
|
+
});
|
|
105
|
+
if (!res.ok) {
|
|
106
|
+
const { message } = await res.json();
|
|
107
|
+
throw new Error(message);
|
|
108
|
+
}
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
114
|
+
FileUploader
|
|
115
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/file-kit/client/file_uploader.ts
|
|
2
|
+
var FileUploader = class {
|
|
3
|
+
endpoint;
|
|
4
|
+
constructor(endpoint = "/api/files") {
|
|
5
|
+
this.endpoint = endpoint;
|
|
6
|
+
}
|
|
7
|
+
formatSize = (size) => {
|
|
8
|
+
if (size < 1024) {
|
|
9
|
+
return `${size} B`;
|
|
10
|
+
}
|
|
11
|
+
if (size < 1024 * 1024) {
|
|
12
|
+
return `${(size / 1024).toFixed(2)} KB`;
|
|
13
|
+
}
|
|
14
|
+
return `${(size / (1024 * 1024)).toFixed(2)} MB`;
|
|
15
|
+
};
|
|
16
|
+
uploadFile(file, options = {}) {
|
|
17
|
+
return this.uploadBlob(file, file.name, options);
|
|
18
|
+
}
|
|
19
|
+
async uploadBlob(blob, name = "blob", options = {}) {
|
|
20
|
+
const { type, size } = blob;
|
|
21
|
+
const metadataForMedia = await new Promise(
|
|
22
|
+
(resolve, reject) => {
|
|
23
|
+
if (blob.type.startsWith("image/")) {
|
|
24
|
+
const img = new Image();
|
|
25
|
+
img.src = URL.createObjectURL(blob);
|
|
26
|
+
img.onload = () => {
|
|
27
|
+
resolve({
|
|
28
|
+
...options.metadata,
|
|
29
|
+
width: img.width,
|
|
30
|
+
height: img.height
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
img.onerror = reject;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (blob.type.startsWith("video/")) {
|
|
37
|
+
const video = document.createElement("video");
|
|
38
|
+
video.src = URL.createObjectURL(blob);
|
|
39
|
+
video.onloadedmetadata = () => {
|
|
40
|
+
resolve({
|
|
41
|
+
...options.metadata,
|
|
42
|
+
width: video.videoWidth,
|
|
43
|
+
height: video.videoHeight,
|
|
44
|
+
duration: video.duration
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
video.onerror = reject;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
resolve(options.metadata || {});
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
const res1 = await fetch(this.endpoint, {
|
|
54
|
+
method: "POST",
|
|
55
|
+
body: JSON.stringify({
|
|
56
|
+
name: name.replace(/ /g, "_"),
|
|
57
|
+
type,
|
|
58
|
+
size,
|
|
59
|
+
metadata: metadataForMedia
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
if (!res1.ok) {
|
|
63
|
+
const message = await res1.json();
|
|
64
|
+
throw new Error(message);
|
|
65
|
+
}
|
|
66
|
+
const result = await res1.json();
|
|
67
|
+
const { signedUrl, file } = result;
|
|
68
|
+
const res2 = await fetch(signedUrl, {
|
|
69
|
+
method: "PUT",
|
|
70
|
+
body: blob
|
|
71
|
+
});
|
|
72
|
+
if (!res2.ok) {
|
|
73
|
+
throw new Error(await res2.text());
|
|
74
|
+
}
|
|
75
|
+
return file;
|
|
76
|
+
}
|
|
77
|
+
async deleteFile(fileId) {
|
|
78
|
+
const res = await fetch(`${this.endpoint}/${fileId}`, {
|
|
79
|
+
method: "DELETE"
|
|
80
|
+
});
|
|
81
|
+
if (!res.ok) {
|
|
82
|
+
const { message } = await res.json();
|
|
83
|
+
throw new Error(message);
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
export {
|
|
89
|
+
FileUploader
|
|
90
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ObjectStorage } from './object_storage.mjs';
|
|
2
|
+
import { FileRepository } from './repository.mjs';
|
|
3
|
+
import '@aws-sdk/client-s3';
|
|
4
|
+
|
|
5
|
+
type Params = {
|
|
6
|
+
userId?: string;
|
|
7
|
+
name: string;
|
|
8
|
+
type: string;
|
|
9
|
+
size: number;
|
|
10
|
+
metadata?: Record<string, any>;
|
|
11
|
+
};
|
|
12
|
+
declare class FileService<TFile> {
|
|
13
|
+
prefix: string;
|
|
14
|
+
repository: FileRepository<TFile>;
|
|
15
|
+
OBJECT_STORAGE: ObjectStorage;
|
|
16
|
+
constructor(prefix: string | undefined, { repository, OBJECT_STORAGE, }: {
|
|
17
|
+
repository: FileRepository<TFile>;
|
|
18
|
+
OBJECT_STORAGE: ObjectStorage;
|
|
19
|
+
});
|
|
20
|
+
generateSignedUrl({ userId, name, type, size, metadata }: Params): Promise<{
|
|
21
|
+
file: Awaited<TFile>;
|
|
22
|
+
signedUrl: string;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { FileService };
|