@axium/storage 0.16.2 → 0.16.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.
@@ -43,6 +43,7 @@ export async function uploadItem(file, opt = {}) {
43
43
  if (!opt.name)
44
44
  throw 'item name is required';
45
45
  const content = await file.bytes();
46
+ opt.onProgress?.(0, content.length);
46
47
  /** For big files, it takes a *really* long time to compute the hash, so we just don't do it ahead of time and leave it up to the server. */
47
48
  const hash = content.length < uploadConfig.hashThreshold * 1_000_000 ? blake2b(content).toHex() : null;
48
49
  const upload = await fetchAPI('PUT', 'storage', {
@@ -115,7 +115,7 @@ addRoute({
115
115
  if (hash.toHex() != upload.init.hash)
116
116
  error(409, 'Hash mismatch');
117
117
  upload.remove();
118
- return await createNewItem(upload.init, upload.userId, path => {
118
+ const item = await createNewItem(upload.init, upload.userId, path => {
119
119
  try {
120
120
  renameSync(upload.file, path);
121
121
  }
@@ -123,9 +123,15 @@ addRoute({
123
123
  if (e.code != 'EXDEV')
124
124
  throw e;
125
125
  writeFileSync(path, readFileSync(upload.file));
126
- unlinkSync(upload.file);
127
126
  }
128
127
  });
128
+ try {
129
+ unlinkSync(upload.file);
130
+ }
131
+ catch {
132
+ // probably renamed
133
+ }
134
+ return item;
129
135
  },
130
136
  });
131
137
  addRoute({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/storage",
3
- "version": "0.16.2",
3
+ "version": "0.16.3",
4
4
  "author": "James Prevett <axium@jamespre.dev>",
5
5
  "description": "User file storage for Axium",
6
6
  "funding": {