@axium/storage 0.1.1 → 0.1.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/client.js CHANGED
@@ -22,22 +22,27 @@ async function _upload(method, url, data) {
22
22
  json.modifiedAt = new Date(json.modifiedAt);
23
23
  return json;
24
24
  }
25
+ function _parse(result) {
26
+ result.createdAt = new Date(result.createdAt);
27
+ result.modifiedAt = new Date(result.modifiedAt);
28
+ if (result.trashedAt)
29
+ result.trashedAt = new Date(result.trashedAt);
30
+ return result;
31
+ }
25
32
  export async function uploadItem(file) {
26
- return _upload('PUT', '/raw/storage', file);
33
+ return _parse(await _upload('PUT', '/raw/storage', file));
27
34
  }
28
35
  export async function updateItem(fileId, data) {
29
- return _upload('POST', '/raw/storage/' + fileId, data);
36
+ return _parse(await _upload('POST', '/raw/storage/' + fileId, data));
30
37
  }
31
38
  export async function getItemMetadata(fileId) {
32
39
  const result = await fetchAPI('GET', 'storage/item/:id', undefined, fileId);
33
- result.modifiedAt = new Date(result.modifiedAt);
34
- return result;
40
+ return _parse(result);
35
41
  }
36
42
  export async function getDirectoryMetadata(parentId) {
37
43
  const result = await fetchAPI('GET', 'storage/directory/:id', undefined, parentId);
38
- for (const item of result) {
39
- item.modifiedAt = new Date(item.modifiedAt);
40
- }
44
+ for (const item of result)
45
+ _parse(item);
41
46
  return result;
42
47
  }
43
48
  export async function downloadItem(fileId) {
@@ -49,15 +54,16 @@ export async function downloadItem(fileId) {
49
54
  return await response.blob();
50
55
  }
51
56
  export async function updateItemMetadata(fileId, metadata) {
52
- return fetchAPI('PATCH', 'storage/item/:id', metadata, fileId);
57
+ const result = await fetchAPI('PATCH', 'storage/item/:id', metadata, fileId);
58
+ return _parse(result);
53
59
  }
54
60
  export async function deleteItem(fileId) {
55
- return fetchAPI('DELETE', 'storage/item/:id', undefined, fileId);
61
+ const result = await fetchAPI('DELETE', 'storage/item/:id', undefined, fileId);
62
+ return _parse(result);
56
63
  }
57
64
  export async function getUserFiles(userId) {
58
65
  const result = await fetchAPI('GET', 'users/:id/storage', undefined, userId);
59
- for (const item of result.items) {
60
- item.modifiedAt = new Date(item.modifiedAt);
61
- }
66
+ for (const item of result.items)
67
+ _parse(item);
62
68
  return result;
63
69
  }
package/dist/common.d.ts CHANGED
@@ -53,7 +53,7 @@ export interface StorageItemMetadata {
53
53
  id: string;
54
54
  immutable: boolean;
55
55
  modifiedAt: Date;
56
- name: string | null;
56
+ name: string;
57
57
  userId: string;
58
58
  parentId: string | null;
59
59
  /** Whether editing the file is restricted to the owner */
package/dist/plugin.js CHANGED
@@ -34,6 +34,10 @@ async function db_init(opt, db) {
34
34
  .execute()
35
35
  .then(done)
36
36
  .catch(warnExists);
37
+ start('Creating index for storage.userId');
38
+ await db.schema.createIndex('storage_userId_index').on('storage').column('userId').execute().then(done).catch(warnExists);
39
+ start('Creating index for storage.parentId');
40
+ await db.schema.createIndex('storage_parentId_index').on('storage').column('parentId').execute().then(done).catch(warnExists);
37
41
  }
38
42
  async function db_wipe(opt, db) {
39
43
  start('Removing data from user storage');
package/dist/server.d.ts CHANGED
@@ -9,7 +9,7 @@ declare module '@axium/server/database' {
9
9
  id: Generated<string>;
10
10
  immutable: Generated<boolean>;
11
11
  modifiedAt: Generated<Date>;
12
- name: string | null;
12
+ name: string;
13
13
  parentId: string | null;
14
14
  restricted: Generated<boolean>;
15
15
  size: number;
package/dist/server.js CHANGED
@@ -169,7 +169,9 @@ addRoute({
169
169
  const { userId } = await getSessionAndUser(token).catch(withError('Invalid session token', 401));
170
170
  const [usage, limits] = await Promise.all([currentUsage(userId), getLimits(userId)]).catch(withError('Could not fetch usage and/or limits'));
171
171
  const name = event.request.headers.get('x-name');
172
- if ((name?.length || 0) > 255)
172
+ if (!name)
173
+ error(400, 'Missing name header');
174
+ if (name.length > 255)
173
175
  error(400, 'Name is too long');
174
176
  const maybeParentId = event.request.headers.get('x-parent');
175
177
  const parentId = maybeParentId
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/storage",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
5
5
  "description": "User file storage for Axium",
6
6
  "funding": {