@axium/storage 0.11.2 → 0.12.0
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/db.json +3 -0
- package/dist/client/cli.js +12 -12
- package/dist/client/local.d.ts +3 -1
- package/dist/client/local.js +2 -3
- package/dist/client/sync.js +1 -1
- package/dist/common.d.ts +17 -23
- package/dist/common.js +25 -0
- package/dist/server/cli.js +2 -2
- package/dist/server/config.d.ts +28 -22
- package/dist/server/config.js +43 -3
- package/package.json +3 -3
package/db.json
CHANGED
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
"itemId": { "type": "uuid", "required": true, "primary": true, "references": "storage.id", "onDelete": "cascade" },
|
|
29
29
|
"createdAt": { "type": "timestamptz", "required": true, "default": "now()" },
|
|
30
30
|
"permission": { "type": "integer", "required": true, "check": "permission >= 0 AND permission <= 5" }
|
|
31
|
+
},
|
|
32
|
+
"constraints": {
|
|
33
|
+
"PK_acl_storage": { "type": "primary_key", "on": ["userId", "itemId"] }
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
},
|
package/dist/client/cli.js
CHANGED
|
@@ -16,7 +16,7 @@ const cli = program
|
|
|
16
16
|
.helpGroup('Plugins:')
|
|
17
17
|
.description('CLI integration for @axium/storage')
|
|
18
18
|
.option('-q, --quiet', 'Suppress output')
|
|
19
|
-
.hook('preAction',
|
|
19
|
+
.hook('preAction', action => {
|
|
20
20
|
const opts = action.optsWithGlobals();
|
|
21
21
|
if (opts.quiet)
|
|
22
22
|
setQuiet(true);
|
|
@@ -33,11 +33,11 @@ cli.command('ls')
|
|
|
33
33
|
.description('List the contents of a folder')
|
|
34
34
|
.argument('<path>', 'remote folder path')
|
|
35
35
|
.option('-l, --long', 'Show more details')
|
|
36
|
-
.option('-h, --human-readable', 'Show sizes in human readable format')
|
|
37
|
-
.action(async function (path) {
|
|
38
|
-
const { users } = await syncCache().catch(io.
|
|
36
|
+
.option('-h, --human-readable', 'Show sizes in human readable format', false)
|
|
37
|
+
.action(async function axium_files_ls(path) {
|
|
38
|
+
const { users } = await syncCache().catch(io.exit);
|
|
39
39
|
const { long, humanReadable } = this.optsWithGlobals();
|
|
40
|
-
const items = await getDirectory(path).catch(io.
|
|
40
|
+
const items = await getDirectory(path).catch(io.exit);
|
|
41
41
|
if (!long) {
|
|
42
42
|
console.log(items.map(colorItem).join('\t'));
|
|
43
43
|
return;
|
|
@@ -53,14 +53,14 @@ cli.command('mkdir')
|
|
|
53
53
|
const pathParts = path.split('/');
|
|
54
54
|
const name = pathParts.pop();
|
|
55
55
|
const parentPath = pathParts.join('/');
|
|
56
|
-
const parent = !parentPath ? null : await resolveItem(parentPath).catch(io.
|
|
56
|
+
const parent = !parentPath ? null : await resolveItem(parentPath).catch(io.exit);
|
|
57
57
|
if (parent) {
|
|
58
58
|
if (!parent)
|
|
59
59
|
io.exit('Could not resolve parent folder.');
|
|
60
60
|
if (parent.type != 'inode/directory')
|
|
61
61
|
io.exit('Parent path is not a directory.');
|
|
62
62
|
}
|
|
63
|
-
await api.uploadItem(new Blob([], { type: 'inode/directory' }), { parentId: parent?.id, name }).catch(io.
|
|
63
|
+
await api.uploadItem(new Blob([], { type: 'inode/directory' }), { parentId: parent?.id, name }).catch(io.exit);
|
|
64
64
|
});
|
|
65
65
|
cli.command('status')
|
|
66
66
|
.option('-v, --verbose', 'Show more details')
|
|
@@ -144,8 +144,8 @@ cli.command('sync')
|
|
|
144
144
|
.addOption(new Option('--delete <mode>', 'Delete local/remote files that were deleted remotely/locally')
|
|
145
145
|
.choices(['local', 'remote', 'none'])
|
|
146
146
|
.default('none'))
|
|
147
|
-
.option('-d, --dry-run', 'Show what would be done, but do not make any changes')
|
|
148
|
-
.option('-v, --verbose', 'Show more details')
|
|
147
|
+
.option('-d, --dry-run', 'Show what would be done, but do not make any changes', false)
|
|
148
|
+
.option('-v, --verbose', 'Show more details', false)
|
|
149
149
|
.argument('[sync]', 'The name of the Sync to sync')
|
|
150
150
|
.action(async (name, opt) => {
|
|
151
151
|
if (name) {
|
|
@@ -167,16 +167,16 @@ cliCache
|
|
|
167
167
|
.command('refresh')
|
|
168
168
|
.description('Force a refresh of the local cache from the server')
|
|
169
169
|
.action(async () => {
|
|
170
|
-
await syncCache(true).catch(io.
|
|
170
|
+
await syncCache(true).catch(io.exit);
|
|
171
171
|
});
|
|
172
172
|
cliCache
|
|
173
173
|
.command('dump')
|
|
174
174
|
.description('Dump the local cache')
|
|
175
175
|
.option('-v, --verbose', 'Show more details')
|
|
176
176
|
.addOption(new Option('-j, --json', 'Output as JSON').conflicts(['verbose', 'quiet']))
|
|
177
|
-
.action(async function () {
|
|
177
|
+
.action(async function axium_files_cache_dump() {
|
|
178
178
|
const opt = this.optsWithGlobals();
|
|
179
|
-
const data = await syncCache(false).catch(io.
|
|
179
|
+
const data = await syncCache(false).catch(io.exit);
|
|
180
180
|
if (opt.json) {
|
|
181
181
|
console.log(JSON.stringify(data));
|
|
182
182
|
return;
|
package/dist/client/local.d.ts
CHANGED
|
@@ -25,7 +25,9 @@ declare const StorageCache: z.ZodObject<{
|
|
|
25
25
|
email: z.ZodOptional<z.ZodEmail>;
|
|
26
26
|
emailVerified: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodDate>>>;
|
|
27
27
|
image: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
|
|
28
|
-
preferences: z.ZodOptional<z.
|
|
28
|
+
preferences: z.ZodOptional<z.ZodObject<{
|
|
29
|
+
debug: z.ZodBoolean;
|
|
30
|
+
}, z.core.$strip>>;
|
|
29
31
|
roles: z.ZodArray<z.ZodString>;
|
|
30
32
|
registeredAt: z.ZodCoercedDate<unknown>;
|
|
31
33
|
isAdmin: z.ZodOptional<z.ZodBoolean>;
|
package/dist/client/local.js
CHANGED
|
@@ -61,11 +61,10 @@ export async function syncCache(force = null) {
|
|
|
61
61
|
io.done();
|
|
62
62
|
}
|
|
63
63
|
catch (e) {
|
|
64
|
-
const message = e instanceof Error ? e.message : String(e);
|
|
65
64
|
if (quiet)
|
|
66
|
-
io.exit('Failed to update item metadata: ' +
|
|
65
|
+
io.exit('Failed to update item metadata: ' + io.errorText(e));
|
|
67
66
|
else
|
|
68
|
-
io.exit(
|
|
67
|
+
io.exit(e);
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
else {
|
package/dist/client/sync.js
CHANGED
package/dist/common.d.ts
CHANGED
|
@@ -38,31 +38,25 @@ declare module '@axium/core/api' {
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
chunk: boolean;
|
|
53
|
-
/** Maximum size in MiB per transfer/request */
|
|
54
|
-
max_transfer_size: number;
|
|
55
|
-
/** Maximum number of chunks */
|
|
56
|
-
max_chunks: number;
|
|
41
|
+
export declare const StoragePublicConfig: z.ZodObject<{
|
|
42
|
+
batch: z.ZodObject<{
|
|
43
|
+
enabled: z.ZodBoolean;
|
|
44
|
+
max_items: z.ZodNumber;
|
|
45
|
+
max_item_size: z.ZodNumber;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
chunk: z.ZodBoolean;
|
|
48
|
+
max_transfer_size: z.ZodNumber;
|
|
49
|
+
max_chunks: z.ZodNumber;
|
|
50
|
+
}, z.core.$strip>;
|
|
51
|
+
export interface StoragePublicConfig extends z.infer<typeof StoragePublicConfig> {
|
|
57
52
|
}
|
|
58
53
|
export declare const syncProtocolVersion = 0;
|
|
59
|
-
export
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
user_size: number;
|
|
54
|
+
export declare const StorageLimits: z.ZodObject<{
|
|
55
|
+
item_size: z.ZodNumber;
|
|
56
|
+
user_items: z.ZodNumber;
|
|
57
|
+
user_size: z.ZodNumber;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
export interface StorageLimits extends z.infer<typeof StorageLimits> {
|
|
66
60
|
}
|
|
67
61
|
export interface StorageStats {
|
|
68
62
|
usedBytes: number;
|
package/dist/common.js
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
+
export const StoragePublicConfig = z.object({
|
|
3
|
+
/** Configuration for batch updates */
|
|
4
|
+
batch: z.object({
|
|
5
|
+
/** Whether to enable sending multiple files per request */
|
|
6
|
+
enabled: z.boolean(),
|
|
7
|
+
/** Maximum number of items that can be included in a single batch update */
|
|
8
|
+
max_items: z.number(),
|
|
9
|
+
/** Maximum size in KiB per item */
|
|
10
|
+
max_item_size: z.number(),
|
|
11
|
+
}),
|
|
12
|
+
/** Whether to split files larger than `max_transfer_size` into multiple chunks */
|
|
13
|
+
chunk: z.boolean(),
|
|
14
|
+
/** Maximum size in MiB per transfer/request */
|
|
15
|
+
max_transfer_size: z.number(),
|
|
16
|
+
/** Maximum number of chunks */
|
|
17
|
+
max_chunks: z.number(),
|
|
18
|
+
});
|
|
2
19
|
export const syncProtocolVersion = 0;
|
|
20
|
+
export const StorageLimits = z.object({
|
|
21
|
+
/** The maximum size per item in MB */
|
|
22
|
+
item_size: z.number(),
|
|
23
|
+
/** Maximum number of items per user */
|
|
24
|
+
user_items: z.number(),
|
|
25
|
+
/** The maximum storage size per user in MB */
|
|
26
|
+
user_size: z.number(),
|
|
27
|
+
});
|
|
3
28
|
/**
|
|
4
29
|
* An update to file metadata.
|
|
5
30
|
*/
|
package/dist/server/cli.js
CHANGED
|
@@ -27,7 +27,7 @@ cli.command('query')
|
|
|
27
27
|
.addOption(new Option('-u, --user <user>', 'Filter by user UUID or email').argParser(lookupUser))
|
|
28
28
|
.option('-m, --min-size <size>', 'Filter by minimum size', _byteSize('Invalid minimum size.'))
|
|
29
29
|
.option('-M, --max-size <size>', 'Filter by maximum size', _byteSize('Invalid maximum size.'))
|
|
30
|
-
.addOption(new Option('--size', 'Filter by exact size').conflicts(['minSize', 'maxSize']).argParser(_byteSize('Invalid size.')))
|
|
30
|
+
.addOption(new Option('--size <size>', 'Filter by exact size').conflicts(['minSize', 'maxSize']).argParser(_byteSize('Invalid size.')))
|
|
31
31
|
.option('-l, --limit <n>', 'Limit the number of results', (v) => z.coerce.number().int().min(1).max(1000).parse(v), 100)
|
|
32
32
|
.option('-j, --json', 'Output results as JSON', false)
|
|
33
33
|
.addOption(new Option('-f, --format <format>', 'How to format output lines').conflicts('json').default('{id} {type} {size} {userId} {name}'))
|
|
@@ -63,7 +63,7 @@ cli.command('query')
|
|
|
63
63
|
if (opt.size !== undefined) {
|
|
64
64
|
query = query.where('size', '=', opt.size);
|
|
65
65
|
}
|
|
66
|
-
const rawItems = await query.execute().catch(io.
|
|
66
|
+
const rawItems = await query.execute().catch(io.exit);
|
|
67
67
|
const items = rawItems.map(parseItem);
|
|
68
68
|
if (!items.length) {
|
|
69
69
|
console.log(styleText(['italic', 'dim'], 'No storage items match the provided filters.'));
|
package/dist/server/config.d.ts
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { StorageLimits } from '../common.js';
|
|
2
2
|
import '../polyfills.js';
|
|
3
|
+
import * as z from 'zod';
|
|
4
|
+
declare const StorageConfig: z.ZodObject<{
|
|
5
|
+
batch: z.ZodObject<{
|
|
6
|
+
enabled: z.ZodBoolean;
|
|
7
|
+
max_items: z.ZodNumber;
|
|
8
|
+
max_item_size: z.ZodNumber;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
chunk: z.ZodBoolean;
|
|
11
|
+
max_transfer_size: z.ZodNumber;
|
|
12
|
+
max_chunks: z.ZodNumber;
|
|
13
|
+
app_enabled: z.ZodBoolean;
|
|
14
|
+
cas: z.ZodOptional<z.ZodObject<{
|
|
15
|
+
enabled: z.ZodBoolean;
|
|
16
|
+
include: z.ZodArray<z.ZodString>;
|
|
17
|
+
exclude: z.ZodArray<z.ZodString>;
|
|
18
|
+
}, z.core.$strip>>;
|
|
19
|
+
data: z.ZodString;
|
|
20
|
+
enabled: z.ZodBoolean;
|
|
21
|
+
limits: z.ZodObject<{
|
|
22
|
+
item_size: z.ZodNumber;
|
|
23
|
+
user_items: z.ZodNumber;
|
|
24
|
+
user_size: z.ZodNumber;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
trash_duration: z.ZodNumber;
|
|
27
|
+
}, z.core.$strip>;
|
|
3
28
|
declare module '@axium/server/config' {
|
|
4
29
|
interface Config {
|
|
5
|
-
storage:
|
|
6
|
-
/** Whether the files app is enabled. Requires `enabled` */
|
|
7
|
-
app_enabled: boolean;
|
|
8
|
-
/** Content Addressable Storage (CAS) configuration */
|
|
9
|
-
cas: {
|
|
10
|
-
/** Whether to use CAS */
|
|
11
|
-
enabled: boolean;
|
|
12
|
-
/** Mime types to include when determining if CAS should be used */
|
|
13
|
-
include: string[];
|
|
14
|
-
/** Mime types to exclude when determining if CAS should be used */
|
|
15
|
-
exclude: string[];
|
|
16
|
-
};
|
|
17
|
-
/** Path to data directory */
|
|
18
|
-
data: string;
|
|
19
|
-
/** Whether the storage API endpoints are enabled */
|
|
20
|
-
enabled: boolean;
|
|
21
|
-
/** Default limits */
|
|
22
|
-
limits: StorageLimits;
|
|
23
|
-
/** How many days files are kept in the trash */
|
|
24
|
-
trash_duration: number;
|
|
25
|
-
};
|
|
30
|
+
storage: z.infer<typeof StorageConfig>;
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
33
|
export declare const defaultCASMime: RegExp[];
|
|
@@ -45,3 +50,4 @@ export type ExternalLimitHandler = (userId?: string) => StorageLimits | Promise<
|
|
|
45
50
|
*/
|
|
46
51
|
export declare function useLimits(handler: ExternalLimitHandler): void;
|
|
47
52
|
export declare function getLimits(userId?: string): Promise<StorageLimits>;
|
|
53
|
+
export {};
|
package/dist/server/config.js
CHANGED
|
@@ -1,7 +1,35 @@
|
|
|
1
1
|
import { Severity } from '@axium/core';
|
|
2
2
|
import { addEvent } from '@axium/server/audit';
|
|
3
|
-
import { addConfigDefaults, config } from '@axium/server/config';
|
|
3
|
+
import { addConfig, addConfigDefaults, config } from '@axium/server/config';
|
|
4
|
+
import { StorageLimits, StoragePublicConfig } from '../common.js';
|
|
4
5
|
import '../polyfills.js';
|
|
6
|
+
import * as z from 'zod';
|
|
7
|
+
const StorageConfig = StoragePublicConfig.safeExtend({
|
|
8
|
+
/** Whether the files app is enabled. Requires `enabled` */
|
|
9
|
+
app_enabled: z.boolean(),
|
|
10
|
+
/** Content Addressable Storage (CAS) configuration */
|
|
11
|
+
cas: z
|
|
12
|
+
.object({
|
|
13
|
+
/** Whether to use CAS */
|
|
14
|
+
enabled: z.boolean(),
|
|
15
|
+
/** Mime types to include when determining if CAS should be used */
|
|
16
|
+
include: z.string().array(),
|
|
17
|
+
/** Mime types to exclude when determining if CAS should be used */
|
|
18
|
+
exclude: z.string().array(),
|
|
19
|
+
})
|
|
20
|
+
.optional(),
|
|
21
|
+
/** Path to data directory */
|
|
22
|
+
data: z.string(),
|
|
23
|
+
/** Whether the storage API endpoints are enabled */
|
|
24
|
+
enabled: z.boolean(),
|
|
25
|
+
/** Default limits */
|
|
26
|
+
limits: StorageLimits,
|
|
27
|
+
/** How many days files are kept in the trash */
|
|
28
|
+
trash_duration: z.number(),
|
|
29
|
+
});
|
|
30
|
+
addConfig({
|
|
31
|
+
storage: StorageConfig.optional(),
|
|
32
|
+
});
|
|
5
33
|
export const defaultCASMime = [/video\/.*/, /audio\/.*/];
|
|
6
34
|
addConfigDefaults({
|
|
7
35
|
storage: {
|
|
@@ -29,8 +57,20 @@ addConfigDefaults({
|
|
|
29
57
|
trash_duration: 30,
|
|
30
58
|
},
|
|
31
59
|
});
|
|
32
|
-
addEvent({
|
|
33
|
-
|
|
60
|
+
addEvent({
|
|
61
|
+
source: '@axium/storage',
|
|
62
|
+
name: 'storage_type_mismatch',
|
|
63
|
+
severity: Severity.Warning,
|
|
64
|
+
tags: ['mimetype'],
|
|
65
|
+
extra: { item: z.string() },
|
|
66
|
+
});
|
|
67
|
+
addEvent({
|
|
68
|
+
source: '@axium/storage',
|
|
69
|
+
name: 'storage_size_mismatch',
|
|
70
|
+
severity: Severity.Warning,
|
|
71
|
+
tags: [],
|
|
72
|
+
extra: { item: z.string().nullable() },
|
|
73
|
+
});
|
|
34
74
|
let _getLimits = null;
|
|
35
75
|
/**
|
|
36
76
|
* Define the handler to get limits for a user externally.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axium/storage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"author": "James Prevett <axium@jamespre.dev>",
|
|
5
5
|
"description": "User file storage for Axium",
|
|
6
6
|
"funding": {
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@axium/client": ">=0.9.0",
|
|
43
|
-
"@axium/core": ">=0.
|
|
44
|
-
"@axium/server": ">=0.
|
|
43
|
+
"@axium/core": ">=0.15.0",
|
|
44
|
+
"@axium/server": ">=0.30.0",
|
|
45
45
|
"@sveltejs/kit": "^2.27.3",
|
|
46
46
|
"utilium": "^2.3.8"
|
|
47
47
|
},
|