@axium/storage 0.18.7 → 0.18.8
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/client/api.d.ts +2 -2
- package/dist/client/api.js +2 -2
- package/dist/client/local.d.ts +4 -0
- package/dist/common.d.ts +65 -2
- package/dist/common.js +7 -1
- package/dist/server/api.js +8 -4
- package/dist/server/db.d.ts +4 -0
- package/dist/server/db.js +18 -0
- package/package.json +1 -1
- package/routes/files/[id]/+page.svelte +10 -0
- package/routes/files/[id]/+page.ts +1 -1
package/dist/client/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StorageItemUpdate, UserStorage, UserStorageInfo } from '../common.js';
|
|
1
|
+
import type { GetItemOptions, StorageItemUpdate, UserStorage, UserStorageInfo } from '../common.js';
|
|
2
2
|
import { StorageItemMetadata } from '../common.js';
|
|
3
3
|
import '../polyfills.js';
|
|
4
4
|
export interface UploadOptions {
|
|
@@ -21,7 +21,7 @@ declare global {
|
|
|
21
21
|
}
|
|
22
22
|
export declare function uploadItem(file: Blob | File, opt?: UploadOptions): Promise<StorageItemMetadata>;
|
|
23
23
|
export declare function updateItem(fileId: string, data: Blob): Promise<StorageItemMetadata>;
|
|
24
|
-
export declare function getItemMetadata(fileId: string): Promise<StorageItemMetadata>;
|
|
24
|
+
export declare function getItemMetadata(fileId: string, options?: GetItemOptions): Promise<StorageItemMetadata>;
|
|
25
25
|
/** Gets the metadata for all items in a directory. */
|
|
26
26
|
export declare function getDirectoryMetadata(parentId: string): Promise<StorageItemMetadata[]>;
|
|
27
27
|
export declare function downloadItem(fileId: string): Promise<Blob>;
|
package/dist/client/api.js
CHANGED
|
@@ -122,8 +122,8 @@ export async function updateItem(fileId, data) {
|
|
|
122
122
|
throw prettifyError(e);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
export async function getItemMetadata(fileId) {
|
|
126
|
-
return await fetchAPI('GET', 'storage/item/:id',
|
|
125
|
+
export async function getItemMetadata(fileId, options = {}) {
|
|
126
|
+
return await fetchAPI('GET', 'storage/item/:id', options, fileId);
|
|
127
127
|
}
|
|
128
128
|
/** Gets the metadata for all items in a directory. */
|
|
129
129
|
export async function getDirectoryMetadata(parentId) {
|
package/dist/client/local.d.ts
CHANGED
|
@@ -40,6 +40,10 @@ declare const StorageCache: z.ZodObject<{
|
|
|
40
40
|
}, z.core.$strip>>>;
|
|
41
41
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
42
42
|
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
43
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
44
|
+
id: z.ZodUUID;
|
|
45
|
+
name: z.ZodString;
|
|
46
|
+
}, z.core.$strip>>>;
|
|
43
47
|
}, z.core.$strip>>;
|
|
44
48
|
users: z.ZodRecord<z.ZodUUID, z.ZodObject<{
|
|
45
49
|
id: z.ZodUUID;
|
package/dist/common.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ export declare const StorageItemUpdate: z.ZodObject<{
|
|
|
8
8
|
trash: z.ZodOptional<z.ZodBoolean>;
|
|
9
9
|
}, z.core.$strip>;
|
|
10
10
|
export type StorageItemUpdate = z.infer<typeof StorageItemUpdate>;
|
|
11
|
+
export declare const GetItemOptions: z.ZodObject<{
|
|
12
|
+
parents: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCodec<z.ZodString, z.ZodBoolean>]>>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
export interface GetItemOptions extends z.infer<typeof GetItemOptions> {
|
|
15
|
+
}
|
|
11
16
|
export declare const StorageItemMetadata: z.ZodObject<{
|
|
12
17
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
13
18
|
dataURL: z.ZodString;
|
|
@@ -44,6 +49,10 @@ export declare const StorageItemMetadata: z.ZodObject<{
|
|
|
44
49
|
}, z.core.$strip>>>;
|
|
45
50
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
46
51
|
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
52
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
53
|
+
id: z.ZodUUID;
|
|
54
|
+
name: z.ZodString;
|
|
55
|
+
}, z.core.$strip>>>;
|
|
47
56
|
}, z.core.$strip>;
|
|
48
57
|
export interface StorageItemMetadata<T extends Record<string, unknown> = Record<string, unknown>> extends z.infer<typeof StorageItemMetadata> {
|
|
49
58
|
metadata: T;
|
|
@@ -114,6 +123,10 @@ export declare const UserStorage: z.ZodObject<{
|
|
|
114
123
|
}, z.core.$strip>>>;
|
|
115
124
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
116
125
|
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
126
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
127
|
+
id: z.ZodUUID;
|
|
128
|
+
name: z.ZodString;
|
|
129
|
+
}, z.core.$strip>>>;
|
|
117
130
|
}, z.core.$strip>>;
|
|
118
131
|
limits: z.ZodObject<{
|
|
119
132
|
item_size: z.ZodInt;
|
|
@@ -248,6 +261,10 @@ export declare const UploadInitResult: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
248
261
|
}, z.core.$strip>>>;
|
|
249
262
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
250
263
|
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
264
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
265
|
+
id: z.ZodUUID;
|
|
266
|
+
name: z.ZodString;
|
|
267
|
+
}, z.core.$strip>>>;
|
|
251
268
|
}, z.core.$strip>;
|
|
252
269
|
}, z.core.$strip>], "status">;
|
|
253
270
|
export type UploadInitResult = z.infer<typeof UploadInitResult>;
|
|
@@ -301,6 +318,10 @@ declare const StorageAPI: {
|
|
|
301
318
|
}, z.core.$strip>>>;
|
|
302
319
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
303
320
|
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
321
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
322
|
+
id: z.ZodUUID;
|
|
323
|
+
name: z.ZodString;
|
|
324
|
+
}, z.core.$strip>>>;
|
|
304
325
|
}, z.core.$strip>>;
|
|
305
326
|
limits: z.ZodObject<{
|
|
306
327
|
item_size: z.ZodInt;
|
|
@@ -350,6 +371,10 @@ declare const StorageAPI: {
|
|
|
350
371
|
}, z.core.$strip>>>;
|
|
351
372
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
352
373
|
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
374
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
375
|
+
id: z.ZodUUID;
|
|
376
|
+
name: z.ZodString;
|
|
377
|
+
}, z.core.$strip>>>;
|
|
353
378
|
}, z.core.$strip>>;
|
|
354
379
|
};
|
|
355
380
|
readonly 'users/:id/storage/trash': {
|
|
@@ -389,6 +414,10 @@ declare const StorageAPI: {
|
|
|
389
414
|
}, z.core.$strip>>>;
|
|
390
415
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
391
416
|
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
417
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
418
|
+
id: z.ZodUUID;
|
|
419
|
+
name: z.ZodString;
|
|
420
|
+
}, z.core.$strip>>>;
|
|
392
421
|
}, z.core.$strip>>;
|
|
393
422
|
};
|
|
394
423
|
readonly 'users/:id/storage/shared': {
|
|
@@ -428,6 +457,10 @@ declare const StorageAPI: {
|
|
|
428
457
|
}, z.core.$strip>>>;
|
|
429
458
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
430
459
|
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
460
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
461
|
+
id: z.ZodUUID;
|
|
462
|
+
name: z.ZodString;
|
|
463
|
+
}, z.core.$strip>>>;
|
|
431
464
|
}, z.core.$strip>>;
|
|
432
465
|
};
|
|
433
466
|
readonly storage: {
|
|
@@ -494,6 +527,10 @@ declare const StorageAPI: {
|
|
|
494
527
|
}, z.core.$strip>>>;
|
|
495
528
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
496
529
|
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
530
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
531
|
+
id: z.ZodUUID;
|
|
532
|
+
name: z.ZodString;
|
|
533
|
+
}, z.core.$strip>>>;
|
|
497
534
|
}, z.core.$strip>;
|
|
498
535
|
}, z.core.$strip>], "status">];
|
|
499
536
|
};
|
|
@@ -545,10 +582,16 @@ declare const StorageAPI: {
|
|
|
545
582
|
}, z.core.$strip>>>;
|
|
546
583
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
547
584
|
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
585
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
586
|
+
id: z.ZodUUID;
|
|
587
|
+
name: z.ZodString;
|
|
588
|
+
}, z.core.$strip>>>;
|
|
548
589
|
}, z.core.$strip>>];
|
|
549
590
|
};
|
|
550
591
|
readonly 'storage/item/:id': {
|
|
551
|
-
readonly GET: z.ZodObject<{
|
|
592
|
+
readonly GET: readonly [z.ZodObject<{
|
|
593
|
+
parents: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCodec<z.ZodString, z.ZodBoolean>]>>;
|
|
594
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
552
595
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
553
596
|
dataURL: z.ZodString;
|
|
554
597
|
hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -584,7 +627,11 @@ declare const StorageAPI: {
|
|
|
584
627
|
}, z.core.$strip>>>;
|
|
585
628
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
586
629
|
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
587
|
-
|
|
630
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
631
|
+
id: z.ZodUUID;
|
|
632
|
+
name: z.ZodString;
|
|
633
|
+
}, z.core.$strip>>>;
|
|
634
|
+
}, z.core.$strip>];
|
|
588
635
|
readonly DELETE: z.ZodObject<{
|
|
589
636
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
590
637
|
dataURL: z.ZodString;
|
|
@@ -621,6 +668,10 @@ declare const StorageAPI: {
|
|
|
621
668
|
}, z.core.$strip>>>;
|
|
622
669
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
623
670
|
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
671
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
672
|
+
id: z.ZodUUID;
|
|
673
|
+
name: z.ZodString;
|
|
674
|
+
}, z.core.$strip>>>;
|
|
624
675
|
}, z.core.$strip>;
|
|
625
676
|
readonly PATCH: readonly [z.ZodObject<{
|
|
626
677
|
name: z.ZodOptional<z.ZodString>;
|
|
@@ -662,6 +713,10 @@ declare const StorageAPI: {
|
|
|
662
713
|
}, z.core.$strip>>>;
|
|
663
714
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
664
715
|
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
716
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
717
|
+
id: z.ZodUUID;
|
|
718
|
+
name: z.ZodString;
|
|
719
|
+
}, z.core.$strip>>>;
|
|
665
720
|
}, z.core.$strip>];
|
|
666
721
|
};
|
|
667
722
|
readonly 'storage/directory/:id': {
|
|
@@ -701,6 +756,10 @@ declare const StorageAPI: {
|
|
|
701
756
|
}, z.core.$strip>>>;
|
|
702
757
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
703
758
|
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
759
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
760
|
+
id: z.ZodUUID;
|
|
761
|
+
name: z.ZodString;
|
|
762
|
+
}, z.core.$strip>>>;
|
|
704
763
|
}, z.core.$strip>>;
|
|
705
764
|
};
|
|
706
765
|
readonly 'storage/directory/:id/recursive': {
|
|
@@ -740,6 +799,10 @@ declare const StorageAPI: {
|
|
|
740
799
|
}, z.core.$strip>>>;
|
|
741
800
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
742
801
|
}, z.core.$catchall<z.ZodBoolean>>>>;
|
|
802
|
+
parents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
803
|
+
id: z.ZodUUID;
|
|
804
|
+
name: z.ZodString;
|
|
805
|
+
}, z.core.$strip>>>;
|
|
743
806
|
path: z.ZodString;
|
|
744
807
|
}, z.core.$strip>>;
|
|
745
808
|
};
|
package/dist/common.js
CHANGED
|
@@ -10,6 +10,11 @@ export const StorageItemUpdate = z
|
|
|
10
10
|
trash: z.boolean(),
|
|
11
11
|
})
|
|
12
12
|
.partial();
|
|
13
|
+
export const GetItemOptions = z
|
|
14
|
+
.object({
|
|
15
|
+
parents: z.union([z.boolean(), z.stringbool()]),
|
|
16
|
+
})
|
|
17
|
+
.partial();
|
|
13
18
|
export const StorageItemMetadata = z.object({
|
|
14
19
|
createdAt: z.coerce.date(),
|
|
15
20
|
dataURL: z.string(),
|
|
@@ -26,6 +31,7 @@ export const StorageItemMetadata = z.object({
|
|
|
26
31
|
type: z.string(),
|
|
27
32
|
metadata: z.record(z.string(), z.unknown()),
|
|
28
33
|
acl: AccessControl.array().optional(),
|
|
34
|
+
parents: z.object({ id: z.uuid(), name: z.string() }).array().optional(),
|
|
29
35
|
});
|
|
30
36
|
export const syncProtocolVersion = 0;
|
|
31
37
|
export const StorageLimits = z.object({
|
|
@@ -151,7 +157,7 @@ const StorageAPI = {
|
|
|
151
157
|
POST: [StorageBatchUpdate.array(), StorageItemMetadata.array()],
|
|
152
158
|
},
|
|
153
159
|
'storage/item/:id': {
|
|
154
|
-
GET: StorageItemMetadata,
|
|
160
|
+
GET: [GetItemOptions, StorageItemMetadata],
|
|
155
161
|
DELETE: StorageItemMetadata,
|
|
156
162
|
PATCH: [StorageItemUpdate, StorageItemMetadata],
|
|
157
163
|
},
|
package/dist/server/api.js
CHANGED
|
@@ -2,14 +2,14 @@ import { getConfig } from '@axium/core';
|
|
|
2
2
|
import * as acl from '@axium/server/acl';
|
|
3
3
|
import { authRequestForItem, checkAuthForUser, requireSession } from '@axium/server/auth';
|
|
4
4
|
import { database } from '@axium/server/database';
|
|
5
|
-
import { error, json, parseBody, withError } from '@axium/server/requests';
|
|
5
|
+
import { error, json, parseBody, parseSearch, withError } from '@axium/server/requests';
|
|
6
6
|
import { addRoute } from '@axium/server/routes';
|
|
7
7
|
import { pick } from 'utilium';
|
|
8
8
|
import * as z from 'zod';
|
|
9
|
-
import { batchFormatVersion, StorageItemInit, StorageItemUpdate, syncProtocolVersion } from '../common.js';
|
|
9
|
+
import { batchFormatVersion, GetItemOptions, StorageItemInit, StorageItemUpdate, syncProtocolVersion } from '../common.js';
|
|
10
10
|
import '../polyfills.js';
|
|
11
11
|
import { getLimits } from './config.js';
|
|
12
|
-
import { deleteRecursive, getRecursive, getUserStats, parseItem } from './db.js';
|
|
12
|
+
import { deleteRecursive, getParents, getRecursive, getUserStats, parseItem } from './db.js';
|
|
13
13
|
import { checkNewItem, createNewItem, startUpload } from './item.js';
|
|
14
14
|
addRoute({
|
|
15
15
|
path: '/api/storage',
|
|
@@ -44,8 +44,12 @@ addRoute({
|
|
|
44
44
|
async GET(request, { id: itemId }) {
|
|
45
45
|
if (!getConfig('@axium/storage').enabled)
|
|
46
46
|
error(503, 'User storage is disabled');
|
|
47
|
+
const options = parseSearch(request, GetItemOptions);
|
|
47
48
|
const { item } = await authRequestForItem(request, 'storage', itemId, { read: true }, true);
|
|
48
|
-
|
|
49
|
+
const result = parseItem(item);
|
|
50
|
+
if (options.parents)
|
|
51
|
+
result.parents = await getParents(itemId);
|
|
52
|
+
return result;
|
|
49
53
|
},
|
|
50
54
|
async PATCH(request, { id: itemId }) {
|
|
51
55
|
if (!getConfig('@axium/storage').enabled)
|
package/dist/server/db.d.ts
CHANGED
|
@@ -29,4 +29,8 @@ export declare function getRecursive(this: {
|
|
|
29
29
|
}>;
|
|
30
30
|
export declare function getRecursiveIds(...ids: string[]): AsyncGenerator<string>;
|
|
31
31
|
export declare function deleteRecursive(deleteSelf: boolean, ...itemId: string[]): Promise<void>;
|
|
32
|
+
export declare function getParents(itemId: string): Promise<{
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
}[]>;
|
|
32
36
|
export declare function getTotalUse(): Promise<bigint>;
|
package/dist/server/db.js
CHANGED
|
@@ -64,6 +64,24 @@ export async function deleteRecursive(deleteSelf, ...itemId) {
|
|
|
64
64
|
for (const id of toDelete)
|
|
65
65
|
unlinkSync(join(getConfig('@axium/storage').data, id));
|
|
66
66
|
}
|
|
67
|
+
export async function getParents(itemId) {
|
|
68
|
+
const rows = await database
|
|
69
|
+
.withRecursive('parents', qb => qb
|
|
70
|
+
.selectFrom('storage')
|
|
71
|
+
.select(['id', 'name', 'parentId'])
|
|
72
|
+
.select(eb => eb.lit(0).as('depth'))
|
|
73
|
+
.where('id', '=', itemId)
|
|
74
|
+
.unionAll(qb
|
|
75
|
+
.selectFrom('storage as s')
|
|
76
|
+
.innerJoin('parents as p', 's.id', 'p.parentId')
|
|
77
|
+
.select(['s.id', 's.name', 's.parentId'])
|
|
78
|
+
.select(eb => eb(eb.ref('p.depth'), '+', eb.lit(1)).as('depth'))))
|
|
79
|
+
.selectFrom('parents')
|
|
80
|
+
.select(['name', 'id'])
|
|
81
|
+
.orderBy('depth', 'desc')
|
|
82
|
+
.execute();
|
|
83
|
+
return rows;
|
|
84
|
+
}
|
|
67
85
|
export async function getTotalUse() {
|
|
68
86
|
const { size } = await database
|
|
69
87
|
.selectFrom('storage')
|
package/package.json
CHANGED
|
@@ -43,6 +43,11 @@
|
|
|
43
43
|
(!a.userId && !a.role && !a.tag)
|
|
44
44
|
)?.manage as boolean | undefined) ?? true}
|
|
45
45
|
/>
|
|
46
|
+
{#if item.parents}
|
|
47
|
+
<p class="parents" data-sveltekit-reload>
|
|
48
|
+
{#each item.parents as { id, name } (id)}<a href="/files/{id}">{name}</a>{/each}
|
|
49
|
+
</p>
|
|
50
|
+
{/if}
|
|
46
51
|
{#if item.type == 'inode/directory'}
|
|
47
52
|
{#snippet action(i: string, text: string, handler: (e: Event) => unknown)}
|
|
48
53
|
<button
|
|
@@ -123,4 +128,9 @@
|
|
|
123
128
|
gap: 1em;
|
|
124
129
|
align-items: center;
|
|
125
130
|
}
|
|
131
|
+
|
|
132
|
+
.parents a::before {
|
|
133
|
+
content: ' / ';
|
|
134
|
+
color: #888;
|
|
135
|
+
}
|
|
126
136
|
</style>
|
|
@@ -5,7 +5,7 @@ import type { StorageItemMetadata } from '@axium/storage/common';
|
|
|
5
5
|
export const ssr = false;
|
|
6
6
|
|
|
7
7
|
export async function load({ params }: PageLoadEvent) {
|
|
8
|
-
const item = await getItemMetadata(params.id);
|
|
8
|
+
const item = await getItemMetadata(params.id, { parents: true });
|
|
9
9
|
|
|
10
10
|
let items: StorageItemMetadata[] | undefined;
|
|
11
11
|
|