@axium/storage 0.1.0 → 0.1.2

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/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');
@@ -2,7 +2,7 @@
2
2
  import { formatBytes } from '@axium/core/format';
3
3
  import { forMime as iconForMime } from '@axium/core/icons';
4
4
  import { FormDialog, Icon } from '@axium/server/lib';
5
- import { deleteItem, getDirectoryMetadata, updateItem } from '@axium/storage/client';
5
+ import { deleteItem, getDirectoryMetadata, updateItemMetadata } from '@axium/storage/client';
6
6
  import type { StorageItemMetadata } from '@axium/storage/common';
7
7
 
8
8
  const { id }: { id: string } = $props();
@@ -35,10 +35,16 @@
35
35
  {/if}
36
36
  {/snippet}
37
37
 
38
- <div class="FilesList">
38
+ <div class="StorageList">
39
39
  {#await getDirectoryMetadata(id).then(data => (items = data)) then}
40
+ <div class="StorageListItem header">
41
+ <span></span>
42
+ <span>Name</span>
43
+ <span>Last Modified</span>
44
+ <span>Size</span>
45
+ </div>
40
46
  {#each items as item, i (item.id)}
41
- <div class="FilesListItem">
47
+ <div class="StorageListItem">
42
48
  <Icon i={iconForMime(item.type)} />
43
49
  <span class="name">{item.name}</span>
44
50
  <span>{item.modifiedAt.toLocaleString()}</span>
@@ -48,7 +54,7 @@
48
54
  {@render action('delete', 'delete', i)}
49
55
  </div>
50
56
  {:else}
51
- <i>No items.</i>
57
+ <i>Empty.</i>
52
58
  {/each}
53
59
  {:catch error}
54
60
  <i style:color="#c44">{error.message}</i>
@@ -59,7 +65,7 @@
59
65
  bind:dialog={dialogs.rename}
60
66
  submitText="Rename"
61
67
  submit={async (data: { name: string }) => {
62
- await updateItem(activeItem.id, data);
68
+ await updateItemMetadata(activeItem.id, data);
63
69
  activeItem.name = data.name;
64
70
  }}
65
71
  >
@@ -93,25 +99,38 @@
93
99
  </FormDialog>
94
100
 
95
101
  <style>
96
- .FilesList {
102
+ .StorageList {
97
103
  display: flex;
98
104
  flex-direction: column;
99
- gap: 0.5em;
100
105
  padding: 0.5em;
101
106
  }
102
107
 
103
- .FilesListItem {
108
+ .StorageListItem.header {
109
+ font-weight: bold;
110
+ border-bottom: 1px solid #bbc;
111
+ }
112
+
113
+ .StorageListItem {
104
114
  display: grid;
105
115
  grid-template-columns: 1em 4fr 15em 5em repeat(1em, 3);
106
116
  align-items: center;
107
117
  gap: 0.5em;
108
118
  }
109
119
 
120
+ .StorageListItem:not(:last-child) {
121
+ padding: 0.5em 0;
122
+ border-bottom: 1px solid #bbc;
123
+ }
124
+
125
+ .StorageListItem:not(.header):hover {
126
+ background-color: #8888;
127
+ }
128
+
110
129
  .action {
111
130
  visibility: hidden;
112
131
  }
113
132
 
114
- .FilesListItem:hover .action {
133
+ .StorageListItem:hover .action {
115
134
  visibility: visible;
116
135
  }
117
136
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/storage",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
5
5
  "description": "User file storage for Axium",
6
6
  "funding": {