@axium/storage 0.3.4 → 0.3.6
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/plugin.d.ts +5 -5
- package/dist/plugin.js +16 -14
- package/package.json +1 -1
package/dist/plugin.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { InitOptions, OpOptions } from '@axium/server/database';
|
|
2
2
|
import './common.js';
|
|
3
3
|
import './server.js';
|
|
4
4
|
declare function statusText(): Promise<string>;
|
|
5
|
-
declare function db_init(opt: InitOptions
|
|
6
|
-
declare function db_wipe(opt: OpOptions
|
|
7
|
-
declare function remove(opt: OpOptions
|
|
8
|
-
declare function clean(opt: OpOptions
|
|
5
|
+
declare function db_init(opt: InitOptions): Promise<void>;
|
|
6
|
+
declare function db_wipe(opt: OpOptions): Promise<void>;
|
|
7
|
+
declare function remove(opt: OpOptions): Promise<void>;
|
|
8
|
+
declare function clean(opt: OpOptions): Promise<void>;
|
|
9
9
|
declare const _default: {
|
|
10
10
|
statusText: typeof statusText;
|
|
11
11
|
hooks: {
|
package/dist/plugin.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { formatBytes } from '@axium/core/format';
|
|
2
|
+
import * as acl from '@axium/server/acl';
|
|
2
3
|
import config from '@axium/server/config';
|
|
3
|
-
import { count, database, warnExists } from '@axium/server/database';
|
|
4
|
+
import { count, createIndex, database, warnExists } from '@axium/server/database';
|
|
4
5
|
import { done, start } from '@axium/server/io';
|
|
5
6
|
import { sql } from 'kysely';
|
|
6
7
|
import pkg from '../package.json' with { type: 'json' };
|
|
@@ -14,13 +15,13 @@ async function statusText() {
|
|
|
14
15
|
.executeTakeFirstOrThrow();
|
|
15
16
|
return `${items} items totaling ${formatBytes(Number(size))}`;
|
|
16
17
|
}
|
|
17
|
-
async function db_init(opt
|
|
18
|
+
async function db_init(opt) {
|
|
18
19
|
start('Creating table storage');
|
|
19
|
-
await
|
|
20
|
+
await database.schema
|
|
20
21
|
.createTable('storage')
|
|
21
22
|
.addColumn('id', 'uuid', col => col.primaryKey().defaultTo(sql `gen_random_uuid()`))
|
|
22
23
|
.addColumn('userId', 'uuid', col => col.notNull().references('users.id').onDelete('cascade').onUpdate('cascade'))
|
|
23
|
-
.addColumn('parentId', 'uuid', col => col.references('storage.
|
|
24
|
+
.addColumn('parentId', 'uuid', col => col.references('storage.id').onDelete('cascade').onUpdate('cascade').defaultTo(null))
|
|
24
25
|
.addColumn('createdAt', 'timestamptz', col => col.notNull().defaultTo(sql `now()`))
|
|
25
26
|
.addColumn('modifiedAt', 'timestamptz', col => col.notNull().defaultTo(sql `now()`))
|
|
26
27
|
.addColumn('size', 'integer', col => col.notNull())
|
|
@@ -34,25 +35,26 @@ async function db_init(opt, db) {
|
|
|
34
35
|
.execute()
|
|
35
36
|
.then(done)
|
|
36
37
|
.catch(warnExists);
|
|
37
|
-
|
|
38
|
-
await
|
|
39
|
-
|
|
40
|
-
await db.schema.createIndex('storage_parentId_index').on('storage').column('parentId').execute().then(done).catch(warnExists);
|
|
38
|
+
await createIndex('storage', 'userId');
|
|
39
|
+
await createIndex('storage', 'parentId');
|
|
40
|
+
await acl.createTable('storage');
|
|
41
41
|
}
|
|
42
|
-
async function db_wipe(opt
|
|
42
|
+
async function db_wipe(opt) {
|
|
43
43
|
start('Removing data from user storage');
|
|
44
|
-
await
|
|
44
|
+
await database.deleteFrom('storage').execute();
|
|
45
|
+
await acl.wipeTable('storage');
|
|
45
46
|
done();
|
|
46
47
|
}
|
|
47
|
-
async function remove(opt
|
|
48
|
+
async function remove(opt) {
|
|
48
49
|
start('Dropping table storage');
|
|
49
|
-
await
|
|
50
|
+
await database.schema.dropTable('storage').execute();
|
|
51
|
+
await acl.dropTable('storage');
|
|
50
52
|
done();
|
|
51
53
|
}
|
|
52
|
-
async function clean(opt
|
|
54
|
+
async function clean(opt) {
|
|
53
55
|
start('Removing expired trash items');
|
|
54
56
|
const nDaysAgo = new Date(Date.now() - 86400000 * config.storage.trash_duration);
|
|
55
|
-
await
|
|
57
|
+
await database
|
|
56
58
|
.deleteFrom('storage')
|
|
57
59
|
.where('trashedAt', 'is not', null)
|
|
58
60
|
.where('trashedAt', '<', nDaysAgo)
|