@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 +18 -12
- package/dist/common.d.ts +1 -1
- package/dist/plugin.js +4 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.js +3 -1
- package/package.json +1 -1
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
}
|
|
66
|
+
for (const item of result.items)
|
|
67
|
+
_parse(item);
|
|
62
68
|
return result;
|
|
63
69
|
}
|
package/dist/common.d.ts
CHANGED
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
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 (
|
|
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
|