qarpeo 0.1.22 → 0.1.24
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/chunks/wrangler.mjs +1 -1
- package/dist/cli/index.mjs +54 -10
- package/dist/module.mjs +2 -2
- package/dist/runtime/app/components/BlobImage.vue +1 -3
- package/dist/runtime/app/components/CMSImage.vue +1 -3
- package/dist/runtime/app/components/FileUpload.vue +2 -2
- package/dist/runtime/app/composables/storage.d.ts +13 -93
- package/dist/runtime/app/composables/storage.mjs +50 -379
- package/dist/runtime/blob.d.ts +2 -2
- package/dist/runtime/blob.mjs +1 -1
- package/package.json +1 -1
package/dist/chunks/wrangler.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
9
9
|
import { mkdir, writeFile, readFile } from 'node:fs/promises';
|
|
10
10
|
import { defu } from 'defu';
|
|
11
11
|
|
|
12
|
-
const version = "0.1.
|
|
12
|
+
const version = "0.1.24";
|
|
13
13
|
|
|
14
14
|
function scanSchemaExports(schemaFiles) {
|
|
15
15
|
const types = [];
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1428,6 +1428,48 @@ const deploy = defineCommand({
|
|
|
1428
1428
|
config = JSON.parse(readFileSync(wranglerConfigPath, "utf8"));
|
|
1429
1429
|
} catch {
|
|
1430
1430
|
}
|
|
1431
|
+
const rootConfigPath = [resolve(cwd, "wrangler.json"), resolve(cwd, "wrangler.jsonc")].find(
|
|
1432
|
+
(p) => existsSync(p)
|
|
1433
|
+
);
|
|
1434
|
+
let rootConfig = {};
|
|
1435
|
+
if (rootConfigPath) {
|
|
1436
|
+
try {
|
|
1437
|
+
rootConfig = JSON.parse(readFileSync(rootConfigPath, "utf8"));
|
|
1438
|
+
} catch {
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
if (rootConfigPath && wranglerConfigPath !== rootConfigPath) {
|
|
1442
|
+
let reconciled = false;
|
|
1443
|
+
if (!rootConfig.durable_objects && config.durable_objects) {
|
|
1444
|
+
delete config.durable_objects;
|
|
1445
|
+
delete config.migrations;
|
|
1446
|
+
reconciled = true;
|
|
1447
|
+
}
|
|
1448
|
+
if (!rootConfig.kv_namespaces && config.kv_namespaces) {
|
|
1449
|
+
delete config.kv_namespaces;
|
|
1450
|
+
reconciled = true;
|
|
1451
|
+
}
|
|
1452
|
+
if (!rootConfig.r2_buckets && config.r2_buckets) {
|
|
1453
|
+
delete config.r2_buckets;
|
|
1454
|
+
reconciled = true;
|
|
1455
|
+
}
|
|
1456
|
+
if (!rootConfig.d1_databases && config.d1_databases) {
|
|
1457
|
+
delete config.d1_databases;
|
|
1458
|
+
reconciled = true;
|
|
1459
|
+
}
|
|
1460
|
+
if (!rootConfig.ai && config.ai) {
|
|
1461
|
+
delete config.ai;
|
|
1462
|
+
delete config.vectorize;
|
|
1463
|
+
reconciled = true;
|
|
1464
|
+
}
|
|
1465
|
+
if (!rootConfig.queues && config.queues) {
|
|
1466
|
+
delete config.queues;
|
|
1467
|
+
reconciled = true;
|
|
1468
|
+
}
|
|
1469
|
+
if (reconciled) {
|
|
1470
|
+
writeFileSync(wranglerConfigPath, JSON.stringify(config, null, 2), "utf8");
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1431
1473
|
const defaultName = config.name || "qarpeo";
|
|
1432
1474
|
const baseWorkerName = args.name || process.env.QARPEO_WORKER_NAME || process.env.WORKER_NAME || defaultName;
|
|
1433
1475
|
const originalName = baseWorkerName;
|
|
@@ -1588,6 +1630,7 @@ const deploy = defineCommand({
|
|
|
1588
1630
|
`
|
|
1589
1631
|
\u26A1 [qarpeo] Applying D1 migrations for ${d1.database_name} (${isPreview ? "preview" : "remote"})...`
|
|
1590
1632
|
);
|
|
1633
|
+
const migConfigPath = rootConfigPath || wranglerConfigPath;
|
|
1591
1634
|
const migArgs = [
|
|
1592
1635
|
"d1",
|
|
1593
1636
|
"migrations",
|
|
@@ -1595,7 +1638,7 @@ const deploy = defineCommand({
|
|
|
1595
1638
|
d1.database_name,
|
|
1596
1639
|
"--remote",
|
|
1597
1640
|
"-c",
|
|
1598
|
-
|
|
1641
|
+
migConfigPath
|
|
1599
1642
|
];
|
|
1600
1643
|
spawnBinSync(wranglerBin, migArgs, {
|
|
1601
1644
|
cwd,
|
|
@@ -2404,28 +2447,29 @@ const init = defineCommand({
|
|
|
2404
2447
|
}
|
|
2405
2448
|
}
|
|
2406
2449
|
}
|
|
2407
|
-
|
|
2450
|
+
const cleanNuxtConfig = nuxtConfigRaw.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
|
|
2451
|
+
if (existsSync(join(cwd, "server/db")) || existsSync(join(cwd, "server/database")) || existsSync(join(cwd, "migrations")) || /db:\s*true|d1:\s*true/i.test(cleanNuxtConfig)) {
|
|
2408
2452
|
detectedFeatures.db = true;
|
|
2409
2453
|
}
|
|
2410
|
-
if (existsSync(join(cwd, "server/api/storage")) || existsSync(join(cwd, "server/api/blob")) || existsSync(join(cwd, "server/api/upload")) || /blob:\s*true|r2:\s*true|storage:\s*true/i.test(
|
|
2454
|
+
if (existsSync(join(cwd, "server/api/storage")) || existsSync(join(cwd, "server/api/blob")) || existsSync(join(cwd, "server/api/upload")) || /blob:\s*true|r2:\s*true|storage:\s*true/i.test(cleanNuxtConfig)) {
|
|
2411
2455
|
detectedFeatures.blob = true;
|
|
2412
2456
|
}
|
|
2413
|
-
if (/kv:\s*true/i.test(
|
|
2457
|
+
if (/kv:\s*true/i.test(cleanNuxtConfig)) {
|
|
2414
2458
|
detectedFeatures.kv = true;
|
|
2415
2459
|
}
|
|
2416
|
-
if (existsSync(join(cwd, "server/realtime")) || existsSync(join(cwd, "server/durable-objects")) || /realtime:\s*true|durableObjects:\s*true/i.test(
|
|
2460
|
+
if (existsSync(join(cwd, "server/realtime")) || existsSync(join(cwd, "server/durable-objects")) || /realtime:\s*true|durableObjects:\s*true/i.test(cleanNuxtConfig)) {
|
|
2417
2461
|
detectedFeatures.realtime = true;
|
|
2418
2462
|
}
|
|
2419
|
-
if (/ai:\s*true|vectorize:\s*true/i.test(
|
|
2463
|
+
if (/ai:\s*true|vectorize:\s*true/i.test(cleanNuxtConfig)) {
|
|
2420
2464
|
detectedFeatures.ai = true;
|
|
2421
2465
|
}
|
|
2422
|
-
if (/queue:\s*true/i.test(
|
|
2466
|
+
if (/queue:\s*true/i.test(cleanNuxtConfig)) {
|
|
2423
2467
|
detectedFeatures.queue = true;
|
|
2424
2468
|
}
|
|
2425
|
-
if (existsSync(join(cwd, "server/auth")) || /auth:\s*true/i.test(
|
|
2469
|
+
if (existsSync(join(cwd, "server/auth")) || /auth:\s*true/i.test(cleanNuxtConfig) || /better-auth/i.test(cleanNuxtConfig)) {
|
|
2426
2470
|
detectedFeatures.auth = true;
|
|
2427
2471
|
}
|
|
2428
|
-
if (/cms:\s*true|cms:\s*\{/i.test(
|
|
2472
|
+
if (/cms:\s*true|cms:\s*\{/i.test(cleanNuxtConfig) || existsSync(join(cwd, "content"))) {
|
|
2429
2473
|
detectedFeatures.cms = true;
|
|
2430
2474
|
}
|
|
2431
2475
|
const selectedFeatures = { ...detectedFeatures };
|
|
@@ -2462,7 +2506,7 @@ const init = defineCommand({
|
|
|
2462
2506
|
} else {
|
|
2463
2507
|
for (const feat of AVAILABLE_FEATURES) {
|
|
2464
2508
|
if (selectedFeatures[feat.key] === void 0) {
|
|
2465
|
-
selectedFeatures[feat.key] = feat.default;
|
|
2509
|
+
selectedFeatures[feat.key] = detectedKeys.length === 0 ? feat.default : false;
|
|
2466
2510
|
}
|
|
2467
2511
|
}
|
|
2468
2512
|
}
|
package/dist/module.mjs
CHANGED
|
@@ -2571,7 +2571,7 @@ export default async function (batch: any, env?: any, ctx?: any) {
|
|
|
2571
2571
|
from: "qarpeo/runtime"
|
|
2572
2572
|
},
|
|
2573
2573
|
{
|
|
2574
|
-
name: "
|
|
2574
|
+
name: "handleBlob",
|
|
2575
2575
|
from: "qarpeo/runtime"
|
|
2576
2576
|
},
|
|
2577
2577
|
{
|
|
@@ -3517,7 +3517,7 @@ export default async function (batch: any, env?: any, ctx?: any) {
|
|
|
3517
3517
|
}
|
|
3518
3518
|
addImports([
|
|
3519
3519
|
{
|
|
3520
|
-
name: "
|
|
3520
|
+
name: "useBlob",
|
|
3521
3521
|
from: resolver.resolve("./runtime/app/composables/storage")
|
|
3522
3522
|
},
|
|
3523
3523
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { computed } from "vue"
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { getOptimizedImageUrl } from "../composables/storage"
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* `<BlobImage>` — Renders an optimized image stored in Qarpeo R2 blob storage. Supports named
|
|
@@ -39,8 +39,6 @@ const props = withDefaults(
|
|
|
39
39
|
},
|
|
40
40
|
)
|
|
41
41
|
|
|
42
|
-
const { getOptimizedImageUrl } = useStorage()
|
|
43
|
-
|
|
44
42
|
const resolvedSrc = computed(() => {
|
|
45
43
|
if (!props.src) return ""
|
|
46
44
|
if ((props.src.startsWith("http://") || props.src.startsWith("https://")) && !props.preset) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { computed } from "vue"
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { getOptimizedImageUrl } from "../composables/storage"
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* `<CMSImage>` — Renders an optimized CMS-managed image via Qarpeo blob storage. Similar to
|
|
@@ -26,8 +26,6 @@ const props = withDefaults(
|
|
|
26
26
|
},
|
|
27
27
|
)
|
|
28
28
|
|
|
29
|
-
const { getOptimizedImageUrl } = useStorage()
|
|
30
|
-
|
|
31
29
|
const resolvedUrl = computed(() => {
|
|
32
30
|
if (!props.src) return ""
|
|
33
31
|
if ((props.src.startsWith("http://") || props.src.startsWith("https://")) && !props.preset) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { ref, computed } from "vue"
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { useBlob, type UploadedFile } from "../composables/storage"
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* `<FileUpload>` — Drag-and-drop file upload dropzone with progress and v-model support. Supports
|
|
@@ -49,7 +49,7 @@ const inputRef = ref<HTMLInputElement | null>(null)
|
|
|
49
49
|
const isDragging = ref(false)
|
|
50
50
|
const clientError = ref<string | null>(null)
|
|
51
51
|
|
|
52
|
-
const { isUploading, progress, error, upload, uploadMultiple, reset } =
|
|
52
|
+
const { isUploading, progress, error, upload, uploadMultiple, reset } = useBlob(() => props.url)
|
|
53
53
|
|
|
54
54
|
function open() {
|
|
55
55
|
if (props.disabled || isUploading.value) return
|
|
@@ -28,98 +28,11 @@ export interface OpenFileDialogOptions {
|
|
|
28
28
|
/** Automatically trigger upload immediately after user selects file(s) */
|
|
29
29
|
upload?: boolean;
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/** File dialog accept attribute (e.g. 'image/*', '.pdf') */
|
|
37
|
-
accept?: string;
|
|
38
|
-
/** Allow multiple files selection */
|
|
39
|
-
multiple?: boolean;
|
|
40
|
-
/** Camera capture mode (e.g. 'user', 'environment') */
|
|
41
|
-
capture?: string;
|
|
42
|
-
/** Automatically trigger upload immediately after picking a file */
|
|
43
|
-
autoUpload?: boolean;
|
|
44
|
-
}
|
|
45
|
-
export declare function useStorage(endpointOrOptions?: string | Ref<string> | (() => string) | UseStorageOptions): {
|
|
46
|
-
file: Ref<{
|
|
47
|
-
readonly lastModified: number;
|
|
48
|
-
readonly name: string;
|
|
49
|
-
readonly webkitRelativePath: string;
|
|
50
|
-
readonly size: number;
|
|
51
|
-
readonly type: string;
|
|
52
|
-
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
53
|
-
bytes: () => Promise<Uint8Array<ArrayBuffer>>;
|
|
54
|
-
slice: (start?: number, end?: number, contentType?: string) => Blob;
|
|
55
|
-
stream: () => ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
56
|
-
text: () => Promise<string>;
|
|
57
|
-
} | null, File | {
|
|
58
|
-
readonly lastModified: number;
|
|
59
|
-
readonly name: string;
|
|
60
|
-
readonly webkitRelativePath: string;
|
|
61
|
-
readonly size: number;
|
|
62
|
-
readonly type: string;
|
|
63
|
-
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
64
|
-
bytes: () => Promise<Uint8Array<ArrayBuffer>>;
|
|
65
|
-
slice: (start?: number, end?: number, contentType?: string) => Blob;
|
|
66
|
-
stream: () => ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
67
|
-
text: () => Promise<string>;
|
|
68
|
-
} | null>;
|
|
69
|
-
files: Ref<{
|
|
70
|
-
readonly lastModified: number;
|
|
71
|
-
readonly name: string;
|
|
72
|
-
readonly webkitRelativePath: string;
|
|
73
|
-
readonly size: number;
|
|
74
|
-
readonly type: string;
|
|
75
|
-
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
76
|
-
bytes: () => Promise<Uint8Array<ArrayBuffer>>;
|
|
77
|
-
slice: (start?: number, end?: number, contentType?: string) => Blob;
|
|
78
|
-
stream: () => ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
79
|
-
text: () => Promise<string>;
|
|
80
|
-
}[], File[] | {
|
|
81
|
-
readonly lastModified: number;
|
|
82
|
-
readonly name: string;
|
|
83
|
-
readonly webkitRelativePath: string;
|
|
84
|
-
readonly size: number;
|
|
85
|
-
readonly type: string;
|
|
86
|
-
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
87
|
-
bytes: () => Promise<Uint8Array<ArrayBuffer>>;
|
|
88
|
-
slice: (start?: number, end?: number, contentType?: string) => Blob;
|
|
89
|
-
stream: () => ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
90
|
-
text: () => Promise<string>;
|
|
91
|
-
}[]>;
|
|
92
|
-
preview: Ref<string | null, string | null>;
|
|
93
|
-
open: <T extends OpenFileDialogOptions>(opts?: T) => Promise<T extends {
|
|
94
|
-
upload: true;
|
|
95
|
-
} ? UploadedFile | UploadedFile[] | null : T extends {
|
|
96
|
-
multiple: true;
|
|
97
|
-
} ? File[] | null : File | null>;
|
|
98
|
-
isUploading: Ref<boolean, boolean>;
|
|
99
|
-
progress: Ref<number, number>;
|
|
100
|
-
error: Ref<Error | null, Error | null>;
|
|
101
|
-
upload: (fileOrOptions?: File | Blob | UploadOptions, maybeOptions?: UploadOptions) => Promise<UploadedFile>;
|
|
102
|
-
uploadMultiple: (filesOrOptions?: FileList | File[] | {
|
|
103
|
-
customMetadata?: Record<string, string>;
|
|
104
|
-
access?: BlobAccessTier;
|
|
105
|
-
}, maybeOptions?: {
|
|
106
|
-
customMetadata?: Record<string, string>;
|
|
107
|
-
access?: BlobAccessTier;
|
|
108
|
-
}) => Promise<UploadedFile[]>;
|
|
109
|
-
deleteFile: (key: string) => Promise<{
|
|
110
|
-
success: boolean;
|
|
111
|
-
}>;
|
|
112
|
-
getDownloadUrl: (key: string, options?: {
|
|
113
|
-
expiresIn?: string | number;
|
|
114
|
-
download?: boolean;
|
|
115
|
-
filename?: string;
|
|
116
|
-
}) => Promise<string>;
|
|
117
|
-
getOptimizedImageUrl: (key: string, transform?: StorageImagePreset & {
|
|
118
|
-
preset?: string;
|
|
119
|
-
}) => string;
|
|
120
|
-
reset: () => void;
|
|
121
|
-
abort: () => void;
|
|
122
|
-
};
|
|
31
|
+
/** Builds an optimized image URL with Cloudflare Edge Image Resizing or query fallback. */
|
|
32
|
+
export declare function getOptimizedImageUrl(key: string, transform?: StorageImagePreset & {
|
|
33
|
+
preset?: string;
|
|
34
|
+
}): string;
|
|
35
|
+
export type UseBlobOptions = UseUploadOptions;
|
|
123
36
|
export interface UseUploadOptions {
|
|
124
37
|
/** Upload endpoint URL (e.g. '/api/avatars', '/api/upload'). Defaults to '/api/upload'. */
|
|
125
38
|
url?: string | Ref<string> | (() => string);
|
|
@@ -167,7 +80,7 @@ export interface UploadFileOptions {
|
|
|
167
80
|
* useUpload("/api/avatars")
|
|
168
81
|
* ```
|
|
169
82
|
*/
|
|
170
|
-
export declare function
|
|
83
|
+
export declare function useBlob(endpointOrOptions?: string | Ref<string> | (() => string) | UseUploadOptions, initialOptions?: UseUploadOptions): {
|
|
171
84
|
file: Ref<{
|
|
172
85
|
readonly lastModified: number;
|
|
173
86
|
readonly name: string;
|
|
@@ -222,12 +135,19 @@ export declare function useUpload(endpointOrOptions?: string | Ref<string> | (()
|
|
|
222
135
|
} ? File[] | null : File | null>;
|
|
223
136
|
upload: (fileOrOpts?: File | Blob | UploadFileOptions, maybeOpts?: UploadFileOptions) => Promise<UploadedFile>;
|
|
224
137
|
uploadMultiple: (filesOrOpts?: FileList | File[] | UploadFileOptions, maybeOpts?: UploadFileOptions) => Promise<UploadedFile[]>;
|
|
138
|
+
delete: (key: string) => Promise<{
|
|
139
|
+
success: boolean;
|
|
140
|
+
}>;
|
|
141
|
+
deleteFile: (key: string) => Promise<{
|
|
142
|
+
success: boolean;
|
|
143
|
+
}>;
|
|
225
144
|
isUploading: Ref<boolean, boolean>;
|
|
226
145
|
progress: Ref<number, number>;
|
|
227
146
|
error: Ref<Error | null, Error | null>;
|
|
228
147
|
abort: () => void;
|
|
229
148
|
reset: () => void;
|
|
230
149
|
};
|
|
150
|
+
export declare const useUpload: typeof useBlob;
|
|
231
151
|
/**
|
|
232
152
|
* Composable to resolve an R2 blob URL with optional image transforms or presets. Accepts string,
|
|
233
153
|
* ref, or getter for full Vue reactivity.
|
|
@@ -67,385 +67,48 @@ function openFileDialog(options = {}) {
|
|
|
67
67
|
input.click();
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
|
-
export function
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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;
|
|
76
|
-
const isUploading = ref(false);
|
|
77
|
-
const progress = ref(0);
|
|
78
|
-
const error = ref(null);
|
|
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
|
-
};
|
|
125
|
-
const reset = () => {
|
|
126
|
-
isUploading.value = false;
|
|
127
|
-
progress.value = 0;
|
|
128
|
-
error.value = null;
|
|
129
|
-
activeXhr = null;
|
|
130
|
-
file.value = null;
|
|
131
|
-
files.value = [];
|
|
132
|
-
revokePreviewUrl(preview.value);
|
|
133
|
-
preview.value = null;
|
|
134
|
-
};
|
|
135
|
-
const abort = () => {
|
|
136
|
-
if (activeXhr) {
|
|
137
|
-
activeXhr.abort();
|
|
138
|
-
activeXhr = null;
|
|
139
|
-
}
|
|
140
|
-
isUploading.value = false;
|
|
141
|
-
};
|
|
142
|
-
if (getCurrentScope()) {
|
|
143
|
-
onScopeDispose(() => {
|
|
144
|
-
if (activeXhr) {
|
|
145
|
-
activeXhr.abort();
|
|
146
|
-
activeXhr = null;
|
|
147
|
-
}
|
|
148
|
-
revokePreviewUrl(preview.value);
|
|
149
|
-
});
|
|
70
|
+
export function getOptimizedImageUrl(key, transform) {
|
|
71
|
+
if (!key) return "";
|
|
72
|
+
if (key.startsWith("http://") || key.startsWith("https://")) {
|
|
73
|
+
return key;
|
|
150
74
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
credentials: "include"
|
|
187
|
-
});
|
|
188
|
-
return new Promise((resolve, reject) => {
|
|
189
|
-
const xhr = new XMLHttpRequest();
|
|
190
|
-
activeXhr = xhr;
|
|
191
|
-
xhr.upload.addEventListener("progress", (event) => {
|
|
192
|
-
if (event.lengthComputable) {
|
|
193
|
-
progress.value = Math.round(event.loaded / event.total * 100);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
xhr.addEventListener("load", () => {
|
|
197
|
-
isUploading.value = false;
|
|
198
|
-
activeXhr = null;
|
|
199
|
-
if (xhr.status >= 200 && xhr.status < 300) {
|
|
200
|
-
const fileUrl = cdnUrl ? `${cdnUrl.replace(/\/$/, "")}/${ticket.key}` : `${prefix}/file/${ticket.key}`;
|
|
201
|
-
resolve({
|
|
202
|
-
key: ticket.key,
|
|
203
|
-
pathname: ticket.key,
|
|
204
|
-
url: fileUrl,
|
|
205
|
-
size: targetFile.size || 0,
|
|
206
|
-
type: mimeType,
|
|
207
|
-
etag: xhr.getResponseHeader("etag") || "",
|
|
208
|
-
access: ticket.access || options.access || "public",
|
|
209
|
-
customMetadata: options.customMetadata
|
|
210
|
-
});
|
|
211
|
-
} else {
|
|
212
|
-
const err = new Error(xhr.responseText || `Upload failed with HTTP ${xhr.status}`);
|
|
213
|
-
error.value = err;
|
|
214
|
-
reject(err);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
xhr.addEventListener("error", () => {
|
|
218
|
-
isUploading.value = false;
|
|
219
|
-
activeXhr = null;
|
|
220
|
-
const err = new Error("Network error during presigned file upload");
|
|
221
|
-
error.value = err;
|
|
222
|
-
reject(err);
|
|
223
|
-
});
|
|
224
|
-
xhr.addEventListener("abort", () => {
|
|
225
|
-
isUploading.value = false;
|
|
226
|
-
activeXhr = null;
|
|
227
|
-
const err = new Error("File upload aborted");
|
|
228
|
-
error.value = err;
|
|
229
|
-
reject(err);
|
|
230
|
-
});
|
|
231
|
-
xhr.open("PUT", ticket.uploadUrl);
|
|
232
|
-
xhr.setRequestHeader("Content-Type", mimeType);
|
|
233
|
-
xhr.send(targetFile);
|
|
234
|
-
});
|
|
235
|
-
} catch (err) {
|
|
236
|
-
isUploading.value = false;
|
|
237
|
-
error.value = err;
|
|
238
|
-
throw err;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return new Promise((resolve, reject) => {
|
|
242
|
-
const xhr = new XMLHttpRequest();
|
|
243
|
-
activeXhr = xhr;
|
|
244
|
-
const formData = new FormData();
|
|
245
|
-
formData.append("file", targetFile, filename);
|
|
246
|
-
if (options.customMetadata) {
|
|
247
|
-
formData.append("metadata", JSON.stringify(options.customMetadata));
|
|
248
|
-
}
|
|
249
|
-
xhr.upload.addEventListener("progress", (event) => {
|
|
250
|
-
if (event.lengthComputable) {
|
|
251
|
-
progress.value = Math.round(event.loaded / event.total * 100);
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
xhr.addEventListener("load", () => {
|
|
255
|
-
isUploading.value = false;
|
|
256
|
-
activeXhr = null;
|
|
257
|
-
if (xhr.status >= 200 && xhr.status < 300) {
|
|
258
|
-
try {
|
|
259
|
-
const data = JSON.parse(xhr.responseText);
|
|
260
|
-
const result = data.files ? data.files[0] : data;
|
|
261
|
-
resolve(result);
|
|
262
|
-
} catch (err) {
|
|
263
|
-
error.value = err;
|
|
264
|
-
reject(err);
|
|
265
|
-
}
|
|
266
|
-
} else {
|
|
267
|
-
const err = new Error(xhr.responseText || `Upload failed with HTTP ${xhr.status}`);
|
|
268
|
-
error.value = err;
|
|
269
|
-
reject(err);
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
xhr.addEventListener("error", () => {
|
|
273
|
-
isUploading.value = false;
|
|
274
|
-
activeXhr = null;
|
|
275
|
-
const err = new Error("Network error during file upload");
|
|
276
|
-
error.value = err;
|
|
277
|
-
reject(err);
|
|
278
|
-
});
|
|
279
|
-
xhr.addEventListener("abort", () => {
|
|
280
|
-
isUploading.value = false;
|
|
281
|
-
activeXhr = null;
|
|
282
|
-
const err = new Error("File upload aborted");
|
|
283
|
-
error.value = err;
|
|
284
|
-
reject(err);
|
|
285
|
-
});
|
|
286
|
-
const uploadBase = customEndpoint || `${prefix}/upload`;
|
|
287
|
-
const uploadUrl = options.access ? `${uploadBase}${uploadBase.includes("?") ? "&" : "?"}access=${options.access}` : uploadBase;
|
|
288
|
-
xhr.open("POST", uploadUrl);
|
|
289
|
-
xhr.withCredentials = true;
|
|
290
|
-
xhr.send(formData);
|
|
291
|
-
});
|
|
292
|
-
};
|
|
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) {
|
|
305
|
-
isUploading.value = false;
|
|
306
|
-
return [];
|
|
307
|
-
}
|
|
308
|
-
isUploading.value = true;
|
|
309
|
-
progress.value = 0;
|
|
310
|
-
error.value = null;
|
|
311
|
-
const fileArray = targetFiles;
|
|
312
|
-
const formData = new FormData();
|
|
313
|
-
for (const file2 of fileArray) {
|
|
314
|
-
formData.append("files", file2, file2.name);
|
|
315
|
-
}
|
|
316
|
-
if (options.customMetadata) {
|
|
317
|
-
formData.append("metadata", JSON.stringify(options.customMetadata));
|
|
318
|
-
}
|
|
319
|
-
return new Promise((resolve, reject) => {
|
|
320
|
-
const xhr = new XMLHttpRequest();
|
|
321
|
-
activeXhr = xhr;
|
|
322
|
-
xhr.upload.addEventListener("progress", (event) => {
|
|
323
|
-
if (event.lengthComputable) {
|
|
324
|
-
progress.value = Math.round(event.loaded / event.total * 100);
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
xhr.addEventListener("load", () => {
|
|
328
|
-
isUploading.value = false;
|
|
329
|
-
activeXhr = null;
|
|
330
|
-
if (xhr.status >= 200 && xhr.status < 300) {
|
|
331
|
-
try {
|
|
332
|
-
const data = JSON.parse(xhr.responseText);
|
|
333
|
-
const result = Array.isArray(data) ? data : data.files || [data];
|
|
334
|
-
resolve(result);
|
|
335
|
-
} catch (err) {
|
|
336
|
-
error.value = err;
|
|
337
|
-
reject(err);
|
|
338
|
-
}
|
|
339
|
-
} else {
|
|
340
|
-
const err = new Error(xhr.responseText || `Upload failed with HTTP ${xhr.status}`);
|
|
341
|
-
error.value = err;
|
|
342
|
-
reject(err);
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
xhr.addEventListener("error", () => {
|
|
346
|
-
isUploading.value = false;
|
|
347
|
-
activeXhr = null;
|
|
348
|
-
const err = new Error("Network error during multi-file upload");
|
|
349
|
-
error.value = err;
|
|
350
|
-
reject(err);
|
|
351
|
-
});
|
|
352
|
-
xhr.addEventListener("abort", () => {
|
|
353
|
-
isUploading.value = false;
|
|
354
|
-
activeXhr = null;
|
|
355
|
-
const err = new Error("Multi-file upload aborted");
|
|
356
|
-
error.value = err;
|
|
357
|
-
reject(err);
|
|
358
|
-
});
|
|
359
|
-
const uploadBase = customEndpoint || `${prefix}/upload`;
|
|
360
|
-
const uploadUrl = options.access ? `${uploadBase}${uploadBase.includes("?") ? "&" : "?"}access=${options.access}` : uploadBase;
|
|
361
|
-
xhr.open("POST", uploadUrl);
|
|
362
|
-
xhr.withCredentials = true;
|
|
363
|
-
xhr.send(formData);
|
|
364
|
-
});
|
|
365
|
-
};
|
|
366
|
-
const deleteFile = async (key) => {
|
|
367
|
-
const cleanKey = key.replace(/^\/+/, "");
|
|
368
|
-
return await $fetch(`${prefix}/file/${cleanKey}`, {
|
|
369
|
-
method: "DELETE",
|
|
370
|
-
credentials: "include"
|
|
371
|
-
});
|
|
372
|
-
};
|
|
373
|
-
const getDownloadUrl = async (key, options) => {
|
|
374
|
-
const cleanKey = key.replace(/^\/+/, "");
|
|
375
|
-
const res = await $fetch(`${prefix}/sign`, {
|
|
376
|
-
method: "POST",
|
|
377
|
-
body: {
|
|
378
|
-
key: cleanKey,
|
|
379
|
-
expiresIn: options?.expiresIn,
|
|
380
|
-
download: options?.download,
|
|
381
|
-
filename: options?.filename
|
|
382
|
-
},
|
|
383
|
-
credentials: "include"
|
|
384
|
-
});
|
|
385
|
-
return res.url;
|
|
386
|
-
};
|
|
387
|
-
const getOptimizedImageUrl = (key, transform) => {
|
|
388
|
-
if (!key) return "";
|
|
389
|
-
if (key.startsWith("http://") || key.startsWith("https://")) {
|
|
390
|
-
return key;
|
|
391
|
-
}
|
|
392
|
-
const cleanKey = key.replace(/^\/+/, "");
|
|
393
|
-
const baseUrl = cdnUrl ? `${cdnUrl.replace(/\/$/, "")}/${cleanKey}` : `${prefix}/file/${cleanKey}`;
|
|
394
|
-
if (!transform) return baseUrl;
|
|
395
|
-
let appliedTransform = { ...transform };
|
|
396
|
-
if (transform.preset && storageConfig.images?.presets?.[transform.preset]) {
|
|
397
|
-
appliedTransform = {
|
|
398
|
-
...storageConfig.images.presets[transform.preset],
|
|
399
|
-
...transform
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
const cfOpts = [];
|
|
403
|
-
if (appliedTransform.width) cfOpts.push(`width=${appliedTransform.width}`);
|
|
404
|
-
if (appliedTransform.height) cfOpts.push(`height=${appliedTransform.height}`);
|
|
405
|
-
if (appliedTransform.quality) cfOpts.push(`quality=${appliedTransform.quality}`);
|
|
406
|
-
if (appliedTransform.format) cfOpts.push(`format=${appliedTransform.format}`);
|
|
407
|
-
if (appliedTransform.fit) cfOpts.push(`fit=${appliedTransform.fit}`);
|
|
408
|
-
if (cfOpts.length === 0) return baseUrl;
|
|
409
|
-
const useCfResizing = storageConfig.images?.resizing !== false;
|
|
410
|
-
if (useCfResizing) {
|
|
411
|
-
const cfParamStr = cfOpts.join(",");
|
|
412
|
-
try {
|
|
413
|
-
const parsed = new URL(baseUrl);
|
|
414
|
-
return `${parsed.origin}/cdn-cgi/image/${cfParamStr}${parsed.pathname}${parsed.search}`;
|
|
415
|
-
} catch {
|
|
416
|
-
const cleanPath = baseUrl.startsWith("/") ? baseUrl : `/${baseUrl}`;
|
|
417
|
-
return `/cdn-cgi/image/${cfParamStr}${cleanPath}`;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
const params = new URLSearchParams();
|
|
421
|
-
const presetName = transform.preset || appliedTransform.preset;
|
|
422
|
-
if (presetName) params.set("preset", presetName);
|
|
423
|
-
if (appliedTransform.width) params.set("w", String(appliedTransform.width));
|
|
424
|
-
if (appliedTransform.height) params.set("h", String(appliedTransform.height));
|
|
425
|
-
if (appliedTransform.quality) params.set("q", String(appliedTransform.quality));
|
|
426
|
-
if (appliedTransform.format) params.set("f", appliedTransform.format);
|
|
427
|
-
if (appliedTransform.fit) params.set("fit", appliedTransform.fit);
|
|
428
|
-
const qs = params.toString();
|
|
429
|
-
return qs ? `${baseUrl}?${qs}` : baseUrl;
|
|
430
|
-
};
|
|
431
|
-
return {
|
|
432
|
-
file,
|
|
433
|
-
files,
|
|
434
|
-
preview,
|
|
435
|
-
open,
|
|
436
|
-
isUploading,
|
|
437
|
-
progress,
|
|
438
|
-
error,
|
|
439
|
-
upload,
|
|
440
|
-
uploadMultiple,
|
|
441
|
-
deleteFile,
|
|
442
|
-
getDownloadUrl,
|
|
443
|
-
getOptimizedImageUrl,
|
|
444
|
-
reset,
|
|
445
|
-
abort
|
|
446
|
-
};
|
|
75
|
+
let storageConfig = {};
|
|
76
|
+
try {
|
|
77
|
+
const runtimeConfig = useRuntimeConfig();
|
|
78
|
+
storageConfig = runtimeConfig.public?.qarpeo?.storage || runtimeConfig.public?.qarpeo?.blob || {};
|
|
79
|
+
} catch {
|
|
80
|
+
}
|
|
81
|
+
const prefix = storageConfig.prefix || "/api/storage";
|
|
82
|
+
const cdnUrl = storageConfig.cdnUrl;
|
|
83
|
+
const cleanKey = key.replace(/^\/+/, "");
|
|
84
|
+
const baseUrl = cdnUrl ? `${cdnUrl.replace(/\/$/, "")}/${cleanKey}` : `${prefix}/file/${cleanKey}`;
|
|
85
|
+
if (!transform) return baseUrl;
|
|
86
|
+
let appliedTransform = { ...transform };
|
|
87
|
+
if (transform.preset && storageConfig.images?.presets?.[transform.preset]) {
|
|
88
|
+
appliedTransform = {
|
|
89
|
+
...storageConfig.images.presets[transform.preset],
|
|
90
|
+
...transform
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const cfOpts = [];
|
|
94
|
+
if (appliedTransform.width) cfOpts.push(`width=${appliedTransform.width}`);
|
|
95
|
+
if (appliedTransform.height) cfOpts.push(`height=${appliedTransform.height}`);
|
|
96
|
+
if (appliedTransform.quality) cfOpts.push(`quality=${appliedTransform.quality}`);
|
|
97
|
+
if (appliedTransform.format) cfOpts.push(`format=${appliedTransform.format}`);
|
|
98
|
+
if (appliedTransform.fit) cfOpts.push(`fit=${appliedTransform.fit}`);
|
|
99
|
+
if (cdnUrl && cfOpts.length > 0) {
|
|
100
|
+
return `${baseUrl}/cdn-cgi/image/${cfOpts.join(",")}/${cleanKey}`;
|
|
101
|
+
}
|
|
102
|
+
const params = new URLSearchParams();
|
|
103
|
+
if (appliedTransform.width) params.set("w", String(appliedTransform.width));
|
|
104
|
+
if (appliedTransform.height) params.set("h", String(appliedTransform.height));
|
|
105
|
+
if (appliedTransform.quality) params.set("q", String(appliedTransform.quality));
|
|
106
|
+
if (appliedTransform.format) params.set("f", appliedTransform.format);
|
|
107
|
+
if (appliedTransform.fit) params.set("fit", appliedTransform.fit);
|
|
108
|
+
const qs = params.toString();
|
|
109
|
+
return qs ? `${baseUrl}?${qs}` : baseUrl;
|
|
447
110
|
}
|
|
448
|
-
export function
|
|
111
|
+
export function useBlob(endpointOrOptions, initialOptions = {}) {
|
|
449
112
|
const isUploading = ref(false);
|
|
450
113
|
const progress = ref(0);
|
|
451
114
|
const error = ref(null);
|
|
@@ -727,6 +390,13 @@ export function useUpload(endpointOrOptions, initialOptions = {}) {
|
|
|
727
390
|
xhr.send(formData);
|
|
728
391
|
});
|
|
729
392
|
};
|
|
393
|
+
const deleteFile = async (key) => {
|
|
394
|
+
const cleanKey = key.replace(/^\/+/, "");
|
|
395
|
+
return await $fetch(`/api/storage/file/${cleanKey}`, {
|
|
396
|
+
method: "DELETE",
|
|
397
|
+
credentials: "include"
|
|
398
|
+
});
|
|
399
|
+
};
|
|
730
400
|
return {
|
|
731
401
|
file,
|
|
732
402
|
files,
|
|
@@ -734,6 +404,8 @@ export function useUpload(endpointOrOptions, initialOptions = {}) {
|
|
|
734
404
|
open,
|
|
735
405
|
upload,
|
|
736
406
|
uploadMultiple,
|
|
407
|
+
delete: deleteFile,
|
|
408
|
+
deleteFile,
|
|
737
409
|
isUploading,
|
|
738
410
|
progress,
|
|
739
411
|
error,
|
|
@@ -741,8 +413,8 @@ export function useUpload(endpointOrOptions, initialOptions = {}) {
|
|
|
741
413
|
reset
|
|
742
414
|
};
|
|
743
415
|
}
|
|
416
|
+
export const useUpload = useBlob;
|
|
744
417
|
export function useBlobUrl(key, transform) {
|
|
745
|
-
const { getOptimizedImageUrl } = useStorage();
|
|
746
418
|
return computed(() => {
|
|
747
419
|
const rawKey = toValue(key);
|
|
748
420
|
if (!rawKey) return "";
|
|
@@ -751,7 +423,6 @@ export function useBlobUrl(key, transform) {
|
|
|
751
423
|
});
|
|
752
424
|
}
|
|
753
425
|
export function getBlobUrl(key, transform) {
|
|
754
|
-
const { getOptimizedImageUrl } = useStorage();
|
|
755
426
|
return getOptimizedImageUrl(key, transform);
|
|
756
427
|
}
|
|
757
428
|
export { useResumableUpload } from "./resumable-upload.mjs";
|
package/dist/runtime/blob.d.ts
CHANGED
|
@@ -16,11 +16,11 @@ export declare function ensureBlob(file: {
|
|
|
16
16
|
/** Creates a typed Blob/R2 interface for a specific binding and optional event. */
|
|
17
17
|
export declare function createBlob(bindingName?: string, event?: CFEvent): QarpeoBlob;
|
|
18
18
|
/**
|
|
19
|
-
* Access a typed Cloudflare R2 Blob instance.
|
|
19
|
+
* Access a typed Cloudflare R2 Blob instance in server routes and handlers.
|
|
20
20
|
*
|
|
21
21
|
* @param bindingName Optional R2 binding name (defaults to configured binding or 'BLOB')
|
|
22
22
|
* @param event Optional event context
|
|
23
23
|
*/
|
|
24
|
-
export declare const
|
|
24
|
+
export declare const handleBlob: (bindingName?: string, event?: CFEvent) => QarpeoBlob;
|
|
25
25
|
/** Auto-imported `blob` instance for direct Cloudflare R2 Blob operations. */
|
|
26
26
|
export declare const blob: QarpeoBlob;
|
package/dist/runtime/blob.mjs
CHANGED