appwrite-utils-cli 0.0.70 → 0.0.71

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/README.md CHANGED
@@ -132,6 +132,7 @@ This setup ensures that developers have robust tools at their fingertips to mana
132
132
 
133
133
  ### Changelog
134
134
 
135
+ - 0.0.71: Slight change to file download logic after errors
135
136
  - 0.0.70: Bump to `node-appwrite` version
136
137
  - 0.0.69: Fixed single ID not getting replaced due to the below change =D also, `nice`
137
138
  - 0.0.68: Fixed the occasional case where, when mapping ID's from old data to new, there would be an array of ID's to match against. `idMappings` now supports arrays.
@@ -252,9 +252,27 @@ export const transferStorageLocalToLocal = async (storage, fromBucketId, toBucke
252
252
  let fromFiles = await tryAwaitWithRetry(async () => await storage.listFiles(fromBucketId, [Query.limit(100)]));
253
253
  const allFromFiles = fromFiles.files;
254
254
  let numberOfFiles = 0;
255
+ const downloadFileWithRetry = async (bucketId, fileId) => {
256
+ let attempts = 3;
257
+ while (attempts > 0) {
258
+ try {
259
+ return await storage.getFileDownload(bucketId, fileId);
260
+ }
261
+ catch (error) {
262
+ console.error(`Error downloading file ${fileId}: ${error}`);
263
+ attempts--;
264
+ if (attempts === 0)
265
+ throw error;
266
+ }
267
+ }
268
+ };
255
269
  if (fromFiles.files.length < 100) {
256
270
  for (const file of allFromFiles) {
257
- const fileData = await tryAwaitWithRetry(async () => await storage.getFileDownload(file.bucketId, file.$id));
271
+ const fileData = await tryAwaitWithRetry(async () => await downloadFileWithRetry(file.bucketId, file.$id));
272
+ if (!fileData) {
273
+ console.error(`Error downloading file ${file.$id}`);
274
+ continue;
275
+ }
258
276
  const fileToCreate = InputFile.fromBuffer(Buffer.from(fileData), file.name);
259
277
  console.log(`Creating file: ${file.name}`);
260
278
  tryAwaitWithRetry(async () => await storage.createFile(toBucketId, file.$id, fileToCreate, file.$permissions));
@@ -277,7 +295,11 @@ export const transferStorageLocalToLocal = async (storage, fromBucketId, toBucke
277
295
  }
278
296
  }
279
297
  for (const file of allFromFiles) {
280
- const fileData = await tryAwaitWithRetry(async () => await storage.getFileDownload(file.bucketId, file.$id));
298
+ const fileData = await tryAwaitWithRetry(async () => await downloadFileWithRetry(file.bucketId, file.$id));
299
+ if (!fileData) {
300
+ console.error(`Error downloading file ${file.$id}`);
301
+ continue;
302
+ }
281
303
  const fileToCreate = InputFile.fromBuffer(Buffer.from(fileData), file.name);
282
304
  await tryAwaitWithRetry(async () => await storage.createFile(toBucketId, file.$id, fileToCreate, file.$permissions));
283
305
  numberOfFiles++;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "appwrite-utils-cli",
3
3
  "description": "Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.",
4
- "version": "0.0.70",
4
+ "version": "0.0.71",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -388,11 +388,29 @@ export const transferStorageLocalToLocal = async (
388
388
  );
389
389
  const allFromFiles = fromFiles.files;
390
390
  let numberOfFiles = 0;
391
+
392
+ const downloadFileWithRetry = async (bucketId: string, fileId: string) => {
393
+ let attempts = 3;
394
+ while (attempts > 0) {
395
+ try {
396
+ return await storage.getFileDownload(bucketId, fileId);
397
+ } catch (error) {
398
+ console.error(`Error downloading file ${fileId}: ${error}`);
399
+ attempts--;
400
+ if (attempts === 0) throw error;
401
+ }
402
+ }
403
+ };
404
+
391
405
  if (fromFiles.files.length < 100) {
392
406
  for (const file of allFromFiles) {
393
407
  const fileData = await tryAwaitWithRetry(
394
- async () => await storage.getFileDownload(file.bucketId, file.$id)
408
+ async () => await downloadFileWithRetry(file.bucketId, file.$id)
395
409
  );
410
+ if (!fileData) {
411
+ console.error(`Error downloading file ${file.$id}`);
412
+ continue;
413
+ }
396
414
  const fileToCreate = InputFile.fromBuffer(
397
415
  Buffer.from(fileData),
398
416
  file.name
@@ -428,8 +446,12 @@ export const transferStorageLocalToLocal = async (
428
446
  }
429
447
  for (const file of allFromFiles) {
430
448
  const fileData = await tryAwaitWithRetry(
431
- async () => await storage.getFileDownload(file.bucketId, file.$id)
449
+ async () => await downloadFileWithRetry(file.bucketId, file.$id)
432
450
  );
451
+ if (!fileData) {
452
+ console.error(`Error downloading file ${file.$id}`);
453
+ continue;
454
+ }
433
455
  const fileToCreate = InputFile.fromBuffer(
434
456
  Buffer.from(fileData),
435
457
  file.name