@axium/storage 0.2.1 → 0.2.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/common.d.ts +0 -1
- package/dist/common.js +0 -1
- package/dist/plugin.js +0 -1
- package/dist/server.d.ts +2 -6
- package/dist/server.js +7 -13
- package/package.json +1 -1
package/dist/common.d.ts
CHANGED
|
@@ -42,7 +42,6 @@ export declare const StorageItemUpdate: z.ZodObject<{
|
|
|
42
42
|
name: z.ZodOptional<z.ZodString>;
|
|
43
43
|
owner: z.ZodOptional<z.ZodUUID>;
|
|
44
44
|
trash: z.ZodOptional<z.ZodBoolean>;
|
|
45
|
-
restrict: z.ZodOptional<z.ZodBoolean>;
|
|
46
45
|
publicPermission: z.ZodOptional<z.ZodNumber>;
|
|
47
46
|
}, z.core.$strip>;
|
|
48
47
|
export type StorageItemUpdate = z.infer<typeof StorageItemUpdate>;
|
package/dist/common.js
CHANGED
package/dist/plugin.js
CHANGED
|
@@ -23,7 +23,6 @@ async function db_init(opt, db) {
|
|
|
23
23
|
.addColumn('parentId', 'uuid', col => col.references('storage.itemId').onDelete('cascade').onUpdate('cascade').defaultTo(null))
|
|
24
24
|
.addColumn('createdAt', 'timestamptz', col => col.notNull().defaultTo(sql `now()`))
|
|
25
25
|
.addColumn('modifiedAt', 'timestamptz', col => col.notNull().defaultTo(sql `now()`))
|
|
26
|
-
.addColumn('restricted', 'boolean', col => col.notNull().defaultTo(false))
|
|
27
26
|
.addColumn('size', 'integer', col => col.notNull())
|
|
28
27
|
.addColumn('trashedAt', 'timestamptz', col => col.defaultTo(null))
|
|
29
28
|
.addColumn('hash', 'bytea', col => col.notNull())
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Schema } from '@axium/server/database';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Generated, Selectable } from 'kysely';
|
|
3
3
|
import type { StorageItemMetadata, StorageLimits, StorageUsage } from './common.js';
|
|
4
4
|
import './polyfills.js';
|
|
5
5
|
declare module '@axium/server/database' {
|
|
@@ -12,7 +12,6 @@ declare module '@axium/server/database' {
|
|
|
12
12
|
modifiedAt: Generated<Date>;
|
|
13
13
|
name: string;
|
|
14
14
|
parentId: string | null;
|
|
15
|
-
restricted: Generated<boolean>;
|
|
16
15
|
size: number;
|
|
17
16
|
trashedAt: Date | null;
|
|
18
17
|
type: string;
|
|
@@ -53,15 +52,12 @@ declare module '@axium/server/config' {
|
|
|
53
52
|
export interface StorageItem extends StorageItemMetadata {
|
|
54
53
|
data: Uint8Array<ArrayBufferLike>;
|
|
55
54
|
}
|
|
56
|
-
export declare function parseItem<T extends Record<string, unknown> = Record<string, unknown>>(item: Selectable<Schema['storage']>
|
|
57
|
-
hash: string;
|
|
58
|
-
}): StorageItemMetadata<T>;
|
|
55
|
+
export declare function parseItem<T extends Record<string, unknown> = Record<string, unknown>>(item: Selectable<Schema['storage']>): StorageItemMetadata<T>;
|
|
59
56
|
/**
|
|
60
57
|
* Returns the current usage of the storage for a user in bytes.
|
|
61
58
|
*/
|
|
62
59
|
export declare function currentUsage(userId: string): Promise<StorageUsage>;
|
|
63
60
|
export declare function get<T extends Record<string, unknown> = Record<string, unknown>>(itemId: string): Promise<StorageItemMetadata<T>>;
|
|
64
|
-
export declare function withEncodedHash(eb: ExpressionBuilder<Schema, 'storage'>): import("kysely").AliasedExpression<string, "hash">;
|
|
65
61
|
export type ExternalLimitHandler = (userId?: string) => StorageLimits | Promise<StorageLimits>;
|
|
66
62
|
/**
|
|
67
63
|
* Define the handler to get limits for a user externally.
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Permission } from '@axium/core';
|
|
1
|
+
import { Permission } from '@axium/core/access';
|
|
2
2
|
import { checkAuthForItem, checkAuthForUser, getSessionAndUser } from '@axium/server/auth';
|
|
3
3
|
import { addConfigDefaults, config } from '@axium/server/config';
|
|
4
4
|
import { connect, database, expectedTypes } from '@axium/server/database';
|
|
@@ -21,7 +21,6 @@ expectedTypes.storage = {
|
|
|
21
21
|
modifiedAt: { type: 'timestamptz', required: true, hasDefault: true },
|
|
22
22
|
name: { type: 'text' },
|
|
23
23
|
parentId: { type: 'uuid' },
|
|
24
|
-
restricted: { type: 'bool', required: true, hasDefault: true },
|
|
25
24
|
size: { type: 'int4', required: true },
|
|
26
25
|
trashedAt: { type: 'timestampz' },
|
|
27
26
|
type: { type: 'text', required: true },
|
|
@@ -53,6 +52,7 @@ export function parseItem(item) {
|
|
|
53
52
|
...item,
|
|
54
53
|
metadata: item.metadata,
|
|
55
54
|
dataURL: `/raw/storage/${item.id}`,
|
|
55
|
+
hash: item.hash.toHex(),
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
@@ -74,13 +74,10 @@ export async function get(itemId) {
|
|
|
74
74
|
.selectFrom('storage')
|
|
75
75
|
.where('id', '=', itemId)
|
|
76
76
|
.selectAll()
|
|
77
|
-
|
|
77
|
+
.$narrowType()
|
|
78
78
|
.executeTakeFirstOrThrow();
|
|
79
79
|
return parseItem(result);
|
|
80
80
|
}
|
|
81
|
-
export function withEncodedHash(eb) {
|
|
82
|
-
return eb.fn('encode', ['hash', eb.val('hex')]).as('hash');
|
|
83
|
-
}
|
|
84
81
|
let _getLimits = null;
|
|
85
82
|
/**
|
|
86
83
|
* Define the handler to get limits for a user externally.
|
|
@@ -104,7 +101,7 @@ addRoute({
|
|
|
104
101
|
error(503, 'User storage is disabled');
|
|
105
102
|
const itemId = event.params.id;
|
|
106
103
|
const { item } = await checkAuthForItem(event, 'storage', itemId, Permission.Read);
|
|
107
|
-
return item;
|
|
104
|
+
return parseItem(item);
|
|
108
105
|
},
|
|
109
106
|
async PATCH(event) {
|
|
110
107
|
if (!config.storage.enabled)
|
|
@@ -128,7 +125,6 @@ addRoute({
|
|
|
128
125
|
.where('id', '=', itemId)
|
|
129
126
|
.set(values)
|
|
130
127
|
.returningAll()
|
|
131
|
-
.returning(withEncodedHash)
|
|
132
128
|
.executeTakeFirstOrThrow()
|
|
133
129
|
.catch(withError('Could not update item')));
|
|
134
130
|
},
|
|
@@ -136,7 +132,8 @@ addRoute({
|
|
|
136
132
|
if (!config.storage.enabled)
|
|
137
133
|
error(503, 'User storage is disabled');
|
|
138
134
|
const itemId = event.params.id;
|
|
139
|
-
const
|
|
135
|
+
const auth = await checkAuthForItem(event, 'storage', itemId, Permission.Manage);
|
|
136
|
+
const item = parseItem(auth.item);
|
|
140
137
|
await database
|
|
141
138
|
.deleteFrom('storage')
|
|
142
139
|
.where('id', '=', itemId)
|
|
@@ -168,7 +165,6 @@ addRoute({
|
|
|
168
165
|
.where('parentId', '=', itemId)
|
|
169
166
|
.where('trashedAt', '!=', null)
|
|
170
167
|
.selectAll()
|
|
171
|
-
.select(withEncodedHash)
|
|
172
168
|
.execute();
|
|
173
169
|
return items.map(parseItem);
|
|
174
170
|
},
|
|
@@ -217,7 +213,6 @@ addRoute({
|
|
|
217
213
|
.insertInto('storage')
|
|
218
214
|
.values({ userId: userId, hash, name, size, type, immutable: useCAS, parentId })
|
|
219
215
|
.returningAll()
|
|
220
|
-
.returning(withEncodedHash)
|
|
221
216
|
.executeTakeFirstOrThrow()
|
|
222
217
|
.catch(withError('Could not create item'));
|
|
223
218
|
const path = join(config.storage.data, result.id);
|
|
@@ -289,7 +284,6 @@ addRoute({
|
|
|
289
284
|
.where('id', '=', itemId)
|
|
290
285
|
.set({ size, modifiedAt: new Date(), hash })
|
|
291
286
|
.returningAll()
|
|
292
|
-
.returning(withEncodedHash)
|
|
293
287
|
.executeTakeFirstOrThrow()
|
|
294
288
|
.catch(withError('Could not update item'));
|
|
295
289
|
await writeFile(join(config.storage.data, result.id), content).catch(withError('Could not write'));
|
|
@@ -313,7 +307,7 @@ addRoute({
|
|
|
313
307
|
const userId = event.params.id;
|
|
314
308
|
await checkAuthForUser(event, userId);
|
|
315
309
|
const [items, usage, limits] = await Promise.all([
|
|
316
|
-
database.selectFrom('storage').where('userId', '=', userId).selectAll().
|
|
310
|
+
database.selectFrom('storage').where('userId', '=', userId).selectAll().execute(),
|
|
317
311
|
currentUsage(userId),
|
|
318
312
|
getLimits(userId),
|
|
319
313
|
]).catch(withError('Could not fetch data'));
|