qarpeo 0.1.18 → 0.1.21
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 +96 -96
- package/dist/chunks/auth-schema.mjs +3 -1
- package/dist/chunks/wrangler.mjs +22 -3
- package/dist/cli/index.mjs +448 -221
- package/dist/fate/index.d.ts +29 -22
- package/dist/fate/index.mjs +1 -3
- package/dist/module.d.ts +1 -1
- package/dist/module.mjs +103 -82
- package/dist/runtime/ai.d.ts +2 -2
- package/dist/runtime/app/components/BlobImage.vue +119 -107
- package/dist/runtime/app/components/CMSBlocks.vue +104 -93
- package/dist/runtime/app/components/CMSContent.vue +24 -23
- package/dist/runtime/app/components/CMSImage.vue +49 -49
- package/dist/runtime/app/components/CMSLocaleSwitcher.vue +110 -110
- package/dist/runtime/app/components/CMSPreviewBanner.vue +83 -79
- package/dist/runtime/app/components/CMSVersionBanner.vue +53 -49
- package/dist/runtime/app/components/CMSVersionSwitcher.vue +140 -140
- package/dist/runtime/app/components/ContentRenderer.vue +83 -80
- package/dist/runtime/app/components/FileUpload.vue +200 -196
- package/dist/runtime/app/components/ImpersonationBanner.vue +61 -57
- package/dist/runtime/app/components/QarpeoWelcome.vue +84 -84
- package/dist/runtime/app/components/SignedIn.vue +13 -13
- package/dist/runtime/app/components/SignedOut.vue +13 -13
- package/dist/runtime/app/components/shiki.css +34 -34
- package/dist/runtime/app/composables/ai.d.ts +22 -22
- package/dist/runtime/app/composables/ai.mjs +3 -7
- package/dist/runtime/app/composables/analytics.mjs +1 -1
- package/dist/runtime/app/composables/api-tokens.mjs +1 -1
- package/dist/runtime/app/composables/auth.d.ts +6 -7
- package/dist/runtime/app/composables/auth.mjs +6 -3
- package/dist/runtime/app/composables/chat.mjs +3 -7
- package/dist/runtime/app/composables/cms-preview.d.ts +3 -3
- package/dist/runtime/app/composables/cms-preview.mjs +1 -1
- package/dist/runtime/app/composables/cms.d.ts +3 -5
- package/dist/runtime/app/composables/cms.mjs +2 -2
- package/dist/runtime/app/composables/docs-version.d.ts +8 -7
- package/dist/runtime/app/composables/docs-version.mjs +3 -3
- package/dist/runtime/app/composables/impersonation.mjs +1 -1
- package/dist/runtime/app/composables/notifications.d.ts +5 -5
- package/dist/runtime/app/composables/notifications.mjs +4 -5
- package/dist/runtime/app/composables/organization.mjs +1 -1
- package/dist/runtime/app/composables/passkey.mjs +1 -1
- package/dist/runtime/app/composables/passwordless.mjs +1 -1
- package/dist/runtime/app/composables/payments.d.ts +2 -1
- package/dist/runtime/app/composables/payments.mjs +1 -1
- package/dist/runtime/app/composables/realtime.d.ts +13 -13
- package/dist/runtime/app/composables/realtime.mjs +2 -2
- package/dist/runtime/app/composables/resumable-upload.d.ts +11 -11
- package/dist/runtime/app/composables/resumable-upload.mjs +1 -1
- package/dist/runtime/app/composables/site.mjs +1 -1
- package/dist/runtime/app/composables/storage.d.ts +151 -11
- package/dist/runtime/app/composables/storage.mjs +291 -33
- package/dist/runtime/app/composables/turnstile.mjs +1 -1
- package/dist/runtime/app/composables/two-factor.mjs +1 -1
- package/dist/runtime/app/pages/devtools/agents.vue +716 -716
- package/dist/runtime/app/pages/devtools/analytics.vue +616 -616
- package/dist/runtime/app/pages/devtools/auth.vue +381 -350
- package/dist/runtime/app/pages/devtools/blob.vue +743 -744
- package/dist/runtime/app/pages/devtools/db.vue +545 -545
- package/dist/runtime/app/pages/devtools/domains.vue +771 -771
- package/dist/runtime/app/pages/devtools/kv.vue +827 -828
- package/dist/runtime/app/pages/devtools/logs.vue +649 -653
- package/dist/runtime/app/pages/devtools/mail.vue +388 -388
- package/dist/runtime/app/pages/devtools/overview.vue +391 -389
- package/dist/runtime/app/pages/devtools/realtime.vue +89 -27
- package/dist/runtime/app/pages/devtools/security.vue +20 -5
- package/dist/runtime/app/pages/devtools/settings.vue +559 -559
- package/dist/runtime/app/pages/devtools/tasks.vue +26 -10
- package/dist/runtime/app/pages/devtools.vue +176 -176
- package/dist/runtime/app/plugins/seo.mjs +1 -1
- package/dist/runtime/app/plugins/shortcuts.client.d.ts +1 -4
- package/dist/runtime/app/public/sw-notifications.mjs +47 -52
- package/dist/runtime/blob.mjs +11 -4
- package/dist/runtime/browser.d.ts +1 -1
- package/dist/runtime/browser.mjs +12 -2
- package/dist/runtime/cache.d.ts +2 -1
- package/dist/runtime/kv.mjs +4 -1
- package/dist/runtime/providers/qarpeo.d.ts +3 -3
- package/dist/runtime/server/durable-objects/agent.mjs +1 -1
- package/dist/runtime/server/durable-objects/room.d.ts +2 -2
- package/dist/runtime/server/durable-objects/room.mjs +5 -5
- package/dist/runtime/server/middleware/devtools.mjs +6 -2
- package/dist/runtime/server/plugins/cms.d.ts +4 -2
- package/dist/runtime/server/plugins/dev-proxy.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/agents/chat.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/agents/chat.post.mjs +4 -1
- package/dist/runtime/server/routes/__qarpeo/analytics/events.get.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.mjs +5 -1
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/logs.get.d.ts +4 -1
- package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/mail/track/open/[id].get.mjs +2 -2
- package/dist/runtime/server/routes/__qarpeo/overview.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/realtime/room.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/realtime/rooms.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/security/analytics.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/security/ban.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/security/clear.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/security/unban.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/settings.get.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/tasks/run.post.mjs +3 -1
- package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +8 -2
- package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -2
- package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -2
- package/dist/runtime/server/routes/ai/embed.post.d.ts +1 -4
- package/dist/runtime/server/routes/ai/search.post.d.ts +2 -2
- package/dist/runtime/server/routes/auth/account.delete.mjs +1 -1
- package/dist/runtime/server/routes/auth/handler.mjs +6 -1
- package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +1 -1
- package/dist/runtime/server/routes/auth/organization/members/[id].delete.mjs +7 -1
- package/dist/runtime/server/routes/auth/otp/verify.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/sso/login.get.mjs +7 -1
- package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +8 -2
- package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +7 -2
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +7 -2
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +6 -1
- package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +6 -1
- package/dist/runtime/server/routes/browser/crawl.post.d.ts +1 -2
- package/dist/runtime/server/routes/browser/invoice.post.d.ts +1 -2
- package/dist/runtime/server/routes/browser/og-image.post.d.ts +2 -2
- package/dist/runtime/server/routes/browser/pdf.post.d.ts +1 -2
- package/dist/runtime/server/routes/browser/pdf.post.mjs +6 -1
- package/dist/runtime/server/routes/browser/screenshot.post.d.ts +2 -2
- package/dist/runtime/server/routes/browser/screenshot.post.mjs +5 -1
- package/dist/runtime/server/routes/cms/components/index.get.d.ts +2 -2
- package/dist/runtime/server/routes/cms/preview/disable.get.d.ts +4 -3
- package/dist/runtime/server/routes/cms/preview/enable.get.d.ts +8 -8
- package/dist/runtime/server/routes/cms/search.get.mjs +1 -1
- package/dist/runtime/server/routes/cms/webhooks/[provider].post.d.ts +7 -7
- package/dist/runtime/server/routes/cms/webhooks/[provider].post.mjs +9 -2
- package/dist/runtime/server/routes/docs/search.get.d.ts +9 -9
- package/dist/runtime/server/routes/fate.mjs +5 -8
- package/dist/runtime/server/routes/mail/bounce.post.d.ts +2 -2
- package/dist/runtime/server/routes/mail/unsubscribe.d.ts +2 -2
- package/dist/runtime/server/routes/mail/webhooks.post.d.ts +2 -2
- package/dist/runtime/server/routes/mail/webhooks.post.mjs +7 -1
- package/dist/runtime/server/routes/payments/usage.get.d.ts +8 -8
- package/dist/runtime/server/routes/payments/usage.post.d.ts +2 -2
- package/dist/runtime/server/routes/realtime/history.delete.d.ts +4 -3
- package/dist/runtime/server/routes/realtime/history.get.d.ts +7 -6
- package/dist/runtime/server/routes/realtime/ws.get.mjs +6 -1
- package/dist/runtime/server/routes/robots.txt.get.mjs +1 -1
- package/dist/runtime/server/routes/sitemap.xml.get.mjs +2 -1
- package/dist/runtime/server/routes/storage/multipart/abort.post.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +2 -2
- package/dist/runtime/server/routes/storage/multipart/create.post.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -3
- package/dist/runtime/server/routes/storage/multipart/part.put.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/part.put.mjs +1 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +2 -4
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +2 -4
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.mjs +1 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +2 -4
- package/dist/runtime/server/tasks/cms/publish.mjs +1 -1
- package/dist/runtime/server/utils/ai.d.ts +9 -9
- package/dist/runtime/server/utils/ai.mjs +3 -3
- package/dist/runtime/server/utils/auth.d.ts +12 -16
- package/dist/runtime/server/utils/auth.mjs +15 -9
- package/dist/runtime/server/utils/bots.mjs +21 -7
- package/dist/runtime/server/utils/browser-utils.d.ts +44 -41
- package/dist/runtime/server/utils/browser-utils.mjs +14 -4
- package/dist/runtime/server/utils/cache.d.ts +5 -5
- package/dist/runtime/server/utils/cms/common.d.ts +26 -0
- package/dist/runtime/server/utils/cms/common.mjs +68 -0
- package/dist/runtime/server/utils/cms/git.d.ts +24 -0
- package/dist/runtime/server/utils/cms/git.mjs +240 -0
- package/dist/runtime/server/utils/cms/markdown.d.ts +22 -0
- package/dist/runtime/server/utils/cms/markdown.mjs +92 -0
- package/dist/runtime/server/utils/cms/path.d.ts +51 -0
- package/dist/runtime/server/utils/cms/path.mjs +127 -0
- package/dist/runtime/server/utils/cms/search.d.ts +22 -0
- package/dist/runtime/server/utils/cms/search.mjs +221 -0
- package/dist/runtime/server/utils/cms-events.d.ts +1 -1
- package/dist/runtime/server/utils/cms-events.mjs +2 -2
- package/dist/runtime/server/utils/cms-filter.mjs +2 -2
- package/dist/runtime/server/utils/cms.d.ts +17 -149
- package/dist/runtime/server/utils/cms.mjs +52 -761
- package/dist/runtime/server/utils/config.d.ts +5 -4
- package/dist/runtime/server/utils/domains.mjs +7 -4
- package/dist/runtime/server/utils/email-templates.d.ts +10 -7
- package/dist/runtime/server/utils/email-templates.mjs +20 -5
- package/dist/runtime/server/utils/feed.d.ts +2 -2
- package/dist/runtime/server/utils/feed.mjs +3 -1
- package/dist/runtime/server/utils/mail-suppression.d.ts +8 -24
- package/dist/runtime/server/utils/mail-suppression.mjs +2 -2
- package/dist/runtime/server/utils/mail.d.ts +7 -8
- package/dist/runtime/server/utils/mail.mjs +17 -12
- package/dist/runtime/server/utils/multipart-store.d.ts +2 -2
- package/dist/runtime/server/utils/notifications.d.ts +9 -23
- package/dist/runtime/server/utils/organization.mjs +4 -12
- package/dist/runtime/server/utils/passwordless.mjs +1 -1
- package/dist/runtime/server/utils/payments.d.ts +2 -6
- package/dist/runtime/server/utils/payments.mjs +1 -1
- package/dist/runtime/server/utils/queue.d.ts +21 -31
- package/dist/runtime/server/utils/rag.d.ts +4 -4
- package/dist/runtime/server/utils/rag.mjs +8 -8
- package/dist/runtime/server/utils/realtime-store.d.ts +2 -2
- package/dist/runtime/server/utils/realtime.d.ts +26 -28
- package/dist/runtime/server/utils/scheduled-task.d.ts +1 -3
- package/dist/runtime/server/utils/security-store.d.ts +2 -2
- package/dist/runtime/server/utils/session.d.ts +9 -11
- package/dist/runtime/server/utils/sso.d.ts +9 -15
- package/dist/runtime/server/utils/sso.mjs +4 -8
- package/dist/runtime/server/utils/storage.d.ts +19 -2
- package/dist/runtime/server/utils/storage.mjs +36 -7
- package/dist/runtime/server/utils/tenant.mjs +3 -1
- package/dist/runtime/server/utils/turnstile.d.ts +3 -5
- package/dist/runtime/server/utils/vapid.d.ts +5 -8
- package/dist/runtime/server/utils/vapid.mjs +26 -13
- package/dist/runtime/service.d.ts +13 -13
- package/dist/runtime/service.mjs +4 -2
- package/dist/runtime/test-utils.d.ts +20 -30
- package/dist/runtime/test-utils.mjs +5 -4
- package/dist/runtime/types/auth-globals.d.ts +14 -14
- package/dist/runtime/types/imports.d.ts +82 -82
- package/dist/runtime/types/index.d.ts +2 -2
- package/dist/runtime/types/r2.d.ts +5 -0
- package/dist/runtime/types/service.d.ts +11 -18
- package/dist/types.d.ts +100 -107
- package/dist/utils/auth-schema.d.ts +2 -2
- package/dist/utils/cms-sources.d.ts +3 -3
- package/dist/utils/local-db.d.ts +3 -3
- package/dist/utils/notifications-schema.d.ts +1 -3
- package/dist/utils/pkg.d.ts +7 -0
- package/dist/utils/queue.d.ts +3 -3
- package/dist/utils/tasks.d.ts +3 -2
- package/package.json +11 -8
|
@@ -1,19 +1,136 @@
|
|
|
1
|
-
import { ref, computed, toValue } from "vue";
|
|
2
1
|
import { useRuntimeConfig } from "nuxt/app";
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
ref,
|
|
4
|
+
computed,
|
|
5
|
+
toValue,
|
|
6
|
+
onScopeDispose,
|
|
7
|
+
getCurrentScope
|
|
8
|
+
} from "vue";
|
|
9
|
+
function createPreviewUrl(file) {
|
|
10
|
+
if (typeof window !== "undefined" && window.URL && file.type.startsWith("image/")) {
|
|
11
|
+
try {
|
|
12
|
+
return window.URL.createObjectURL(file);
|
|
13
|
+
} catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
function revokePreviewUrl(url) {
|
|
20
|
+
if (url && url.startsWith("blob:") && typeof window !== "undefined" && window.URL) {
|
|
21
|
+
try {
|
|
22
|
+
window.URL.revokeObjectURL(url);
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function openFileDialog(options = {}) {
|
|
28
|
+
if (typeof document === "undefined") return Promise.resolve(null);
|
|
29
|
+
return new Promise((resolve) => {
|
|
30
|
+
const input = document.createElement("input");
|
|
31
|
+
input.type = "file";
|
|
32
|
+
if (options.accept) input.accept = options.accept;
|
|
33
|
+
if (options.multiple) input.multiple = options.multiple;
|
|
34
|
+
if (options.capture) input.capture = options.capture;
|
|
35
|
+
input.style.display = "none";
|
|
36
|
+
let resolved = false;
|
|
37
|
+
const cleanup = () => {
|
|
38
|
+
input.remove();
|
|
39
|
+
window.removeEventListener("focus", handleWindowFocus);
|
|
40
|
+
};
|
|
41
|
+
const handleChange = () => {
|
|
42
|
+
if (resolved) return;
|
|
43
|
+
resolved = true;
|
|
44
|
+
const files = input.files ? Array.from(input.files) : [];
|
|
45
|
+
cleanup();
|
|
46
|
+
resolve(files.length > 0 ? files : null);
|
|
47
|
+
};
|
|
48
|
+
const handleCancel = () => {
|
|
49
|
+
if (resolved) return;
|
|
50
|
+
resolved = true;
|
|
51
|
+
cleanup();
|
|
52
|
+
resolve(null);
|
|
53
|
+
};
|
|
54
|
+
const handleWindowFocus = () => {
|
|
55
|
+
setTimeout(() => {
|
|
56
|
+
if (!resolved && (!input.files || input.files.length === 0)) {
|
|
57
|
+
resolved = true;
|
|
58
|
+
cleanup();
|
|
59
|
+
resolve(null);
|
|
60
|
+
}
|
|
61
|
+
}, 500);
|
|
62
|
+
};
|
|
63
|
+
input.addEventListener("change", handleChange, { once: true });
|
|
64
|
+
input.addEventListener("cancel", handleCancel, { once: true });
|
|
65
|
+
window.addEventListener("focus", handleWindowFocus, { once: true });
|
|
66
|
+
document.body.append(input);
|
|
67
|
+
input.click();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
export function useStorage(endpointOrOptions) {
|
|
4
71
|
const runtimeConfig = useRuntimeConfig();
|
|
5
72
|
const storageConfig = runtimeConfig.public?.qarpeo?.storage || runtimeConfig.public?.qarpeo?.blob || {};
|
|
6
|
-
const
|
|
7
|
-
const
|
|
73
|
+
const customEndpoint = typeof endpointOrOptions === "string" ? endpointOrOptions : typeof endpointOrOptions === "function" ? endpointOrOptions() : endpointOrOptions && typeof endpointOrOptions === "object" && "value" in endpointOrOptions ? toValue(endpointOrOptions) : endpointOrOptions && typeof endpointOrOptions === "object" && "endpoint" in endpointOrOptions ? toValue(endpointOrOptions.endpoint) : void 0;
|
|
74
|
+
const prefix = (endpointOrOptions && typeof endpointOrOptions === "object" && "prefix" in endpointOrOptions ? endpointOrOptions.prefix : void 0) || storageConfig.prefix || "/api/storage";
|
|
75
|
+
const cdnUrl = (endpointOrOptions && typeof endpointOrOptions === "object" && "cdnUrl" in endpointOrOptions ? endpointOrOptions.cdnUrl : void 0) || storageConfig.cdnUrl;
|
|
8
76
|
const isUploading = ref(false);
|
|
9
77
|
const progress = ref(0);
|
|
10
78
|
const error = ref(null);
|
|
11
79
|
let activeXhr = null;
|
|
80
|
+
const dialogOptions = {
|
|
81
|
+
accept: typeof endpointOrOptions === "object" && "accept" in endpointOrOptions ? endpointOrOptions.accept : void 0,
|
|
82
|
+
multiple: typeof endpointOrOptions === "object" && "multiple" in endpointOrOptions ? endpointOrOptions.multiple : void 0,
|
|
83
|
+
capture: typeof endpointOrOptions === "object" && "capture" in endpointOrOptions ? endpointOrOptions.capture : void 0,
|
|
84
|
+
autoUpload: typeof endpointOrOptions === "object" && "autoUpload" in endpointOrOptions ? endpointOrOptions.autoUpload : void 0
|
|
85
|
+
};
|
|
86
|
+
const file = ref(null);
|
|
87
|
+
const files = ref([]);
|
|
88
|
+
const preview = ref(null);
|
|
89
|
+
const updateSelectedFiles = (selected) => {
|
|
90
|
+
revokePreviewUrl(preview.value);
|
|
91
|
+
if (!selected || selected.length === 0) {
|
|
92
|
+
file.value = null;
|
|
93
|
+
files.value = [];
|
|
94
|
+
preview.value = null;
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
files.value = selected;
|
|
98
|
+
file.value = selected[0];
|
|
99
|
+
preview.value = createPreviewUrl(selected[0]);
|
|
100
|
+
return selected;
|
|
101
|
+
};
|
|
102
|
+
const open = async (opts = {}) => {
|
|
103
|
+
const dialogAccept = opts.accept ?? dialogOptions.accept;
|
|
104
|
+
const dialogMultiple = opts.multiple ?? dialogOptions.multiple ?? false;
|
|
105
|
+
const dialogCapture = opts.capture ?? dialogOptions.capture;
|
|
106
|
+
const picked = await openFileDialog({
|
|
107
|
+
accept: dialogAccept,
|
|
108
|
+
multiple: dialogMultiple,
|
|
109
|
+
capture: dialogCapture
|
|
110
|
+
});
|
|
111
|
+
if (!picked || picked.length === 0) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
updateSelectedFiles(picked);
|
|
115
|
+
if (opts.upload || dialogOptions.autoUpload) {
|
|
116
|
+
if (dialogMultiple) {
|
|
117
|
+
const res2 = await uploadMultiple();
|
|
118
|
+
return res2;
|
|
119
|
+
}
|
|
120
|
+
const res = await upload();
|
|
121
|
+
return res;
|
|
122
|
+
}
|
|
123
|
+
return dialogMultiple ? picked : picked[0];
|
|
124
|
+
};
|
|
12
125
|
const reset = () => {
|
|
13
126
|
isUploading.value = false;
|
|
14
127
|
progress.value = 0;
|
|
15
128
|
error.value = null;
|
|
16
129
|
activeXhr = null;
|
|
130
|
+
file.value = null;
|
|
131
|
+
files.value = [];
|
|
132
|
+
revokePreviewUrl(preview.value);
|
|
133
|
+
preview.value = null;
|
|
17
134
|
};
|
|
18
135
|
const abort = () => {
|
|
19
136
|
if (activeXhr) {
|
|
@@ -22,17 +139,50 @@ export function useStorage() {
|
|
|
22
139
|
}
|
|
23
140
|
isUploading.value = false;
|
|
24
141
|
};
|
|
25
|
-
|
|
142
|
+
if (getCurrentScope()) {
|
|
143
|
+
onScopeDispose(() => {
|
|
144
|
+
if (activeXhr) {
|
|
145
|
+
activeXhr.abort();
|
|
146
|
+
activeXhr = null;
|
|
147
|
+
}
|
|
148
|
+
revokePreviewUrl(preview.value);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
const upload = async (fileOrOptions, maybeOptions = {}) => {
|
|
152
|
+
let targetFile = null;
|
|
153
|
+
let options = {};
|
|
154
|
+
if (fileOrOptions instanceof Blob || typeof File !== "undefined" && fileOrOptions instanceof File) {
|
|
155
|
+
targetFile = fileOrOptions;
|
|
156
|
+
options = maybeOptions;
|
|
157
|
+
} else if (fileOrOptions && typeof fileOrOptions === "object") {
|
|
158
|
+
options = fileOrOptions;
|
|
159
|
+
targetFile = file.value;
|
|
160
|
+
} else {
|
|
161
|
+
targetFile = file.value;
|
|
162
|
+
options = maybeOptions;
|
|
163
|
+
}
|
|
164
|
+
if (!targetFile) {
|
|
165
|
+
const err = new Error(
|
|
166
|
+
"No file selected for upload. Call open() first or pass a file to upload()."
|
|
167
|
+
);
|
|
168
|
+
error.value = err;
|
|
169
|
+
throw err;
|
|
170
|
+
}
|
|
26
171
|
isUploading.value = true;
|
|
27
172
|
progress.value = 0;
|
|
28
173
|
error.value = null;
|
|
29
|
-
const filename = options.filename || (
|
|
30
|
-
const mimeType =
|
|
174
|
+
const filename = options.filename || (targetFile instanceof File ? targetFile.name : "upload");
|
|
175
|
+
const mimeType = targetFile.type || "application/octet-stream";
|
|
31
176
|
if (options.presigned) {
|
|
32
177
|
try {
|
|
33
178
|
const ticket = await $fetch(`${prefix}/presigned`, {
|
|
34
179
|
method: "POST",
|
|
35
|
-
body: {
|
|
180
|
+
body: {
|
|
181
|
+
filename,
|
|
182
|
+
type: mimeType,
|
|
183
|
+
size: targetFile.size,
|
|
184
|
+
access: options.access
|
|
185
|
+
},
|
|
36
186
|
credentials: "include"
|
|
37
187
|
});
|
|
38
188
|
return new Promise((resolve, reject) => {
|
|
@@ -52,7 +202,7 @@ export function useStorage() {
|
|
|
52
202
|
key: ticket.key,
|
|
53
203
|
pathname: ticket.key,
|
|
54
204
|
url: fileUrl,
|
|
55
|
-
size:
|
|
205
|
+
size: targetFile.size || 0,
|
|
56
206
|
type: mimeType,
|
|
57
207
|
etag: xhr.getResponseHeader("etag") || "",
|
|
58
208
|
access: ticket.access || options.access || "public",
|
|
@@ -80,7 +230,7 @@ export function useStorage() {
|
|
|
80
230
|
});
|
|
81
231
|
xhr.open("PUT", ticket.uploadUrl);
|
|
82
232
|
xhr.setRequestHeader("Content-Type", mimeType);
|
|
83
|
-
xhr.send(
|
|
233
|
+
xhr.send(targetFile);
|
|
84
234
|
});
|
|
85
235
|
} catch (err) {
|
|
86
236
|
isUploading.value = false;
|
|
@@ -92,7 +242,7 @@ export function useStorage() {
|
|
|
92
242
|
const xhr = new XMLHttpRequest();
|
|
93
243
|
activeXhr = xhr;
|
|
94
244
|
const formData = new FormData();
|
|
95
|
-
formData.append("file",
|
|
245
|
+
formData.append("file", targetFile, filename);
|
|
96
246
|
if (options.customMetadata) {
|
|
97
247
|
formData.append("metadata", JSON.stringify(options.customMetadata));
|
|
98
248
|
}
|
|
@@ -133,24 +283,35 @@ export function useStorage() {
|
|
|
133
283
|
error.value = err;
|
|
134
284
|
reject(err);
|
|
135
285
|
});
|
|
136
|
-
const
|
|
286
|
+
const uploadBase = customEndpoint || `${prefix}/upload`;
|
|
287
|
+
const uploadUrl = options.access ? `${uploadBase}${uploadBase.includes("?") ? "&" : "?"}access=${options.access}` : uploadBase;
|
|
137
288
|
xhr.open("POST", uploadUrl);
|
|
138
289
|
xhr.withCredentials = true;
|
|
139
290
|
xhr.send(formData);
|
|
140
291
|
});
|
|
141
292
|
};
|
|
142
|
-
const uploadMultiple = async (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (
|
|
293
|
+
const uploadMultiple = async (filesOrOptions, maybeOptions = {}) => {
|
|
294
|
+
let targetFiles = [];
|
|
295
|
+
let options = maybeOptions;
|
|
296
|
+
if (Array.isArray(filesOrOptions) || typeof FileList !== "undefined" && filesOrOptions instanceof FileList) {
|
|
297
|
+
targetFiles = Array.from(filesOrOptions);
|
|
298
|
+
} else if (filesOrOptions && typeof filesOrOptions === "object") {
|
|
299
|
+
options = filesOrOptions;
|
|
300
|
+
targetFiles = files.value;
|
|
301
|
+
} else {
|
|
302
|
+
targetFiles = files.value;
|
|
303
|
+
}
|
|
304
|
+
if (targetFiles.length === 0) {
|
|
148
305
|
isUploading.value = false;
|
|
149
306
|
return [];
|
|
150
307
|
}
|
|
308
|
+
isUploading.value = true;
|
|
309
|
+
progress.value = 0;
|
|
310
|
+
error.value = null;
|
|
311
|
+
const fileArray = targetFiles;
|
|
151
312
|
const formData = new FormData();
|
|
152
|
-
for (const
|
|
153
|
-
formData.append("files",
|
|
313
|
+
for (const file2 of fileArray) {
|
|
314
|
+
formData.append("files", file2, file2.name);
|
|
154
315
|
}
|
|
155
316
|
if (options.customMetadata) {
|
|
156
317
|
formData.append("metadata", JSON.stringify(options.customMetadata));
|
|
@@ -195,7 +356,8 @@ export function useStorage() {
|
|
|
195
356
|
error.value = err;
|
|
196
357
|
reject(err);
|
|
197
358
|
});
|
|
198
|
-
const
|
|
359
|
+
const uploadBase = customEndpoint || `${prefix}/upload`;
|
|
360
|
+
const uploadUrl = options.access ? `${uploadBase}${uploadBase.includes("?") ? "&" : "?"}access=${options.access}` : uploadBase;
|
|
199
361
|
xhr.open("POST", uploadUrl);
|
|
200
362
|
xhr.withCredentials = true;
|
|
201
363
|
xhr.send(formData);
|
|
@@ -267,6 +429,10 @@ export function useStorage() {
|
|
|
267
429
|
return qs ? `${baseUrl}?${qs}` : baseUrl;
|
|
268
430
|
};
|
|
269
431
|
return {
|
|
432
|
+
file,
|
|
433
|
+
files,
|
|
434
|
+
preview,
|
|
435
|
+
open,
|
|
270
436
|
isUploading,
|
|
271
437
|
progress,
|
|
272
438
|
error,
|
|
@@ -284,10 +450,56 @@ export function useUpload(endpointOrOptions, initialOptions = {}) {
|
|
|
284
450
|
const progress = ref(0);
|
|
285
451
|
const error = ref(null);
|
|
286
452
|
let activeXhr = null;
|
|
453
|
+
const dialogOptions = {
|
|
454
|
+
accept: typeof endpointOrOptions === "object" && "accept" in endpointOrOptions ? endpointOrOptions.accept : initialOptions.accept,
|
|
455
|
+
multiple: typeof endpointOrOptions === "object" && "multiple" in endpointOrOptions ? endpointOrOptions.multiple : initialOptions.multiple,
|
|
456
|
+
capture: typeof endpointOrOptions === "object" && "capture" in endpointOrOptions ? endpointOrOptions.capture : initialOptions.capture,
|
|
457
|
+
autoUpload: typeof endpointOrOptions === "object" && "autoUpload" in endpointOrOptions ? endpointOrOptions.autoUpload : initialOptions.autoUpload
|
|
458
|
+
};
|
|
459
|
+
const file = ref(null);
|
|
460
|
+
const files = ref([]);
|
|
461
|
+
const preview = ref(null);
|
|
462
|
+
const updateSelectedFiles = (selected) => {
|
|
463
|
+
revokePreviewUrl(preview.value);
|
|
464
|
+
if (!selected || selected.length === 0) {
|
|
465
|
+
file.value = null;
|
|
466
|
+
files.value = [];
|
|
467
|
+
preview.value = null;
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
files.value = selected;
|
|
471
|
+
file.value = selected[0];
|
|
472
|
+
preview.value = createPreviewUrl(selected[0]);
|
|
473
|
+
return selected;
|
|
474
|
+
};
|
|
475
|
+
const open = async (opts = {}) => {
|
|
476
|
+
const dialogAccept = opts.accept ?? dialogOptions.accept;
|
|
477
|
+
const dialogMultiple = opts.multiple ?? dialogOptions.multiple ?? false;
|
|
478
|
+
const dialogCapture = opts.capture ?? dialogOptions.capture;
|
|
479
|
+
const picked = await openFileDialog({
|
|
480
|
+
accept: dialogAccept,
|
|
481
|
+
multiple: dialogMultiple,
|
|
482
|
+
capture: dialogCapture
|
|
483
|
+
});
|
|
484
|
+
if (!picked || picked.length === 0) {
|
|
485
|
+
return null;
|
|
486
|
+
}
|
|
487
|
+
updateSelectedFiles(picked);
|
|
488
|
+
if (opts.upload || dialogOptions.autoUpload) {
|
|
489
|
+
if (dialogMultiple) {
|
|
490
|
+
const res2 = await uploadMultiple();
|
|
491
|
+
return res2;
|
|
492
|
+
}
|
|
493
|
+
const res = await upload();
|
|
494
|
+
return res;
|
|
495
|
+
}
|
|
496
|
+
return dialogMultiple ? picked : picked[0];
|
|
497
|
+
};
|
|
287
498
|
const resolveUrl = (overrideUrl) => {
|
|
288
499
|
if (overrideUrl) return overrideUrl;
|
|
289
500
|
if (typeof endpointOrOptions === "string") return endpointOrOptions;
|
|
290
|
-
if (endpointOrOptions && typeof endpointOrOptions === "function")
|
|
501
|
+
if (endpointOrOptions && typeof endpointOrOptions === "function")
|
|
502
|
+
return endpointOrOptions();
|
|
291
503
|
if (endpointOrOptions && typeof endpointOrOptions === "object" && "value" in endpointOrOptions) {
|
|
292
504
|
return toValue(endpointOrOptions);
|
|
293
505
|
}
|
|
@@ -301,6 +513,10 @@ export function useUpload(endpointOrOptions, initialOptions = {}) {
|
|
|
301
513
|
progress.value = 0;
|
|
302
514
|
error.value = null;
|
|
303
515
|
activeXhr = null;
|
|
516
|
+
file.value = null;
|
|
517
|
+
files.value = [];
|
|
518
|
+
revokePreviewUrl(preview.value);
|
|
519
|
+
preview.value = null;
|
|
304
520
|
};
|
|
305
521
|
const abort = () => {
|
|
306
522
|
if (activeXhr) {
|
|
@@ -309,17 +525,45 @@ export function useUpload(endpointOrOptions, initialOptions = {}) {
|
|
|
309
525
|
}
|
|
310
526
|
isUploading.value = false;
|
|
311
527
|
};
|
|
312
|
-
|
|
528
|
+
if (getCurrentScope()) {
|
|
529
|
+
onScopeDispose(() => {
|
|
530
|
+
if (activeXhr) {
|
|
531
|
+
activeXhr.abort();
|
|
532
|
+
activeXhr = null;
|
|
533
|
+
}
|
|
534
|
+
revokePreviewUrl(preview.value);
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
const upload = async (fileOrOpts, maybeOpts = {}) => {
|
|
538
|
+
let targetFile = null;
|
|
539
|
+
let opts = {};
|
|
540
|
+
if (fileOrOpts instanceof Blob || typeof File !== "undefined" && fileOrOpts instanceof File) {
|
|
541
|
+
targetFile = fileOrOpts;
|
|
542
|
+
opts = maybeOpts;
|
|
543
|
+
} else if (fileOrOpts && typeof fileOrOpts === "object") {
|
|
544
|
+
opts = fileOrOpts;
|
|
545
|
+
targetFile = file.value;
|
|
546
|
+
} else {
|
|
547
|
+
targetFile = file.value;
|
|
548
|
+
opts = maybeOpts;
|
|
549
|
+
}
|
|
550
|
+
if (!targetFile) {
|
|
551
|
+
const err = new Error(
|
|
552
|
+
"No file selected for upload. Call open() first or pass a file to upload()."
|
|
553
|
+
);
|
|
554
|
+
error.value = err;
|
|
555
|
+
throw err;
|
|
556
|
+
}
|
|
313
557
|
isUploading.value = true;
|
|
314
558
|
progress.value = 0;
|
|
315
559
|
error.value = null;
|
|
316
560
|
const targetUrl = resolveUrl(opts.url);
|
|
317
|
-
const filename = opts.filename || (
|
|
561
|
+
const filename = opts.filename || (targetFile instanceof File ? targetFile.name : "upload");
|
|
318
562
|
return new Promise((resolve, reject) => {
|
|
319
563
|
const xhr = new XMLHttpRequest();
|
|
320
564
|
activeXhr = xhr;
|
|
321
565
|
const formData = new FormData();
|
|
322
|
-
formData.append("file",
|
|
566
|
+
formData.append("file", targetFile, filename);
|
|
323
567
|
const mergedMeta = {
|
|
324
568
|
...typeof endpointOrOptions === "object" && "customMetadata" in endpointOrOptions ? endpointOrOptions.customMetadata : {},
|
|
325
569
|
...initialOptions.customMetadata,
|
|
@@ -388,22 +632,32 @@ export function useUpload(endpointOrOptions, initialOptions = {}) {
|
|
|
388
632
|
xhr.send(formData);
|
|
389
633
|
});
|
|
390
634
|
};
|
|
391
|
-
const uploadMultiple = async (
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
if (
|
|
635
|
+
const uploadMultiple = async (filesOrOpts, maybeOpts = {}) => {
|
|
636
|
+
let targetFiles = [];
|
|
637
|
+
let opts = maybeOpts;
|
|
638
|
+
if (Array.isArray(filesOrOpts) || typeof FileList !== "undefined" && filesOrOpts instanceof FileList) {
|
|
639
|
+
targetFiles = Array.from(filesOrOpts);
|
|
640
|
+
} else if (filesOrOpts && typeof filesOrOpts === "object") {
|
|
641
|
+
opts = filesOrOpts;
|
|
642
|
+
targetFiles = files.value;
|
|
643
|
+
} else {
|
|
644
|
+
targetFiles = files.value;
|
|
645
|
+
}
|
|
646
|
+
if (targetFiles.length === 0) {
|
|
397
647
|
isUploading.value = false;
|
|
398
648
|
return [];
|
|
399
649
|
}
|
|
650
|
+
isUploading.value = true;
|
|
651
|
+
progress.value = 0;
|
|
652
|
+
error.value = null;
|
|
653
|
+
const fileArray = targetFiles;
|
|
400
654
|
const targetUrl = resolveUrl(opts.url);
|
|
401
655
|
return new Promise((resolve, reject) => {
|
|
402
656
|
const xhr = new XMLHttpRequest();
|
|
403
657
|
activeXhr = xhr;
|
|
404
658
|
const formData = new FormData();
|
|
405
|
-
for (const
|
|
406
|
-
formData.append("files",
|
|
659
|
+
for (const file2 of fileArray) {
|
|
660
|
+
formData.append("files", file2, file2.name);
|
|
407
661
|
}
|
|
408
662
|
const mergedMeta = {
|
|
409
663
|
...typeof endpointOrOptions === "object" && "customMetadata" in endpointOrOptions ? endpointOrOptions.customMetadata : {},
|
|
@@ -474,6 +728,10 @@ export function useUpload(endpointOrOptions, initialOptions = {}) {
|
|
|
474
728
|
});
|
|
475
729
|
};
|
|
476
730
|
return {
|
|
731
|
+
file,
|
|
732
|
+
files,
|
|
733
|
+
preview,
|
|
734
|
+
open,
|
|
477
735
|
upload,
|
|
478
736
|
uploadMultiple,
|
|
479
737
|
isUploading,
|