@axium/storage 0.3.12 → 0.3.14

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.d.ts CHANGED
@@ -5,7 +5,7 @@ export interface UploadOptions {
5
5
  parentId?: string;
6
6
  name?: string;
7
7
  }
8
- export declare function uploadItem(file: Blob | File, opt: UploadOptions): Promise<StorageItemMetadata>;
8
+ export declare function uploadItem(file: Blob | File, opt?: UploadOptions): Promise<StorageItemMetadata>;
9
9
  export declare function updateItem(fileId: string, data: Blob): Promise<StorageItemMetadata>;
10
10
  export declare function getItemMetadata(fileId: string): Promise<StorageItemMetadata>;
11
11
  export declare function getDirectoryMetadata(parentId: string): Promise<StorageItemMetadata[]>;
package/dist/client.js CHANGED
@@ -30,7 +30,7 @@ export function parseItem(result) {
30
30
  result.trashedAt = new Date(result.trashedAt);
31
31
  return result;
32
32
  }
33
- export async function uploadItem(file, opt) {
33
+ export async function uploadItem(file, opt = {}) {
34
34
  const headers = {};
35
35
  if (opt.parentId)
36
36
  headers['x-parent'] = opt.parentId;
package/dist/server.js CHANGED
@@ -59,9 +59,10 @@ export async function currentUsage(userId) {
59
59
  const result = await database
60
60
  .selectFrom('storage')
61
61
  .where('userId', '=', userId)
62
- .select(database.fn.countAll().as('items'))
62
+ .select(eb => eb.fn.countAll().as('items'))
63
63
  .select(eb => eb.fn.sum('size').as('bytes'))
64
64
  .executeTakeFirstOrThrow();
65
+ result.bytes ||= 0;
65
66
  return result;
66
67
  }
67
68
  export async function get(itemId) {
@@ -222,6 +223,7 @@ addRoute({
222
223
  if (!useCAS) {
223
224
  if (!isDirectory)
224
225
  writeFileSync(path, content);
226
+ await tx.commit().execute();
225
227
  return item;
226
228
  }
227
229
  const existing = await tx
@@ -234,18 +236,17 @@ addRoute({
234
236
  if (!existing) {
235
237
  if (!isDirectory)
236
238
  writeFileSync(path, content);
239
+ await tx.commit().execute();
237
240
  return item;
238
241
  }
239
242
  linkSync(join(config.storage.data, existing.id), path);
243
+ await tx.commit().execute();
240
244
  return item;
241
245
  }
242
246
  catch (error) {
243
247
  await tx.rollback().execute();
244
248
  throw withError('Could not create item', 500)(error);
245
249
  }
246
- finally {
247
- await tx.commit().execute();
248
- }
249
250
  },
250
251
  });
251
252
  addRoute({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/storage",
3
- "version": "0.3.12",
3
+ "version": "0.3.14",
4
4
  "author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
5
5
  "description": "User file storage for Axium",
6
6
  "funding": {