@adminforth/storage-adapter-local 1.0.8 → 1.0.10
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/index.js +16 -15
- package/index.ts +16 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import fs from "fs/promises";
|
|
11
11
|
import path from "path";
|
|
12
|
+
import { afLogger } from "adminforth";
|
|
12
13
|
import crypto from "crypto";
|
|
13
14
|
import { createWriteStream } from 'fs';
|
|
14
15
|
import { Level } from 'level';
|
|
@@ -73,13 +74,13 @@ class AdminForthStorageAdapterLocalFilesystem {
|
|
|
73
74
|
}
|
|
74
75
|
markKeyForDeletation(key) {
|
|
75
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
|
|
77
|
+
afLogger.error("Method \"markKeyForDeletation\" is deprecated, use markKeyForDeletion instead");
|
|
77
78
|
const metadata = yield this.metadataDb.get(key).catch((e) => {
|
|
78
|
-
|
|
79
|
+
afLogger.error(`Could not read metadata from db: ${e}`);
|
|
79
80
|
throw new Error(`Could not read metadata from db: ${e}`);
|
|
80
81
|
});
|
|
81
82
|
if (!metadata) {
|
|
82
|
-
|
|
83
|
+
afLogger.error(`Metadata for key ${key} not found`);
|
|
83
84
|
return;
|
|
84
85
|
}
|
|
85
86
|
const metadataParsed = JSON.parse(metadata);
|
|
@@ -95,14 +96,14 @@ class AdminForthStorageAdapterLocalFilesystem {
|
|
|
95
96
|
yield this.candidatesForDeletionDb.put(key, metadataParsed.createdAt);
|
|
96
97
|
}
|
|
97
98
|
catch (e) {
|
|
98
|
-
|
|
99
|
+
afLogger.error(`Could not write metadata to db: ${e}`);
|
|
99
100
|
throw new Error(`Could not write metadata to db: ${e}`);
|
|
100
101
|
}
|
|
101
102
|
});
|
|
102
103
|
}
|
|
103
104
|
markKeyForNotDeletation(key) {
|
|
104
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
|
|
106
|
+
afLogger.error("Method \"markKeyForNotDeletation\" is deprecated, use markKeyForNotDeletion instead");
|
|
106
107
|
try {
|
|
107
108
|
// if key exists, delete it
|
|
108
109
|
yield this.candidatesForDeletionDb.del(key);
|
|
@@ -115,11 +116,11 @@ class AdminForthStorageAdapterLocalFilesystem {
|
|
|
115
116
|
markKeyForDeletion(key) {
|
|
116
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
118
|
const metadata = yield this.metadataDb.get(key).catch((e) => {
|
|
118
|
-
|
|
119
|
+
afLogger.error(`Could not read metadata from db: ${e}`);
|
|
119
120
|
throw new Error(`Could not read metadata from db: ${e}`);
|
|
120
121
|
});
|
|
121
122
|
if (!metadata) {
|
|
122
|
-
|
|
123
|
+
afLogger.error(`Metadata for key ${key} not found`);
|
|
123
124
|
return;
|
|
124
125
|
}
|
|
125
126
|
const metadataParsed = JSON.parse(metadata);
|
|
@@ -135,7 +136,7 @@ class AdminForthStorageAdapterLocalFilesystem {
|
|
|
135
136
|
yield this.candidatesForDeletionDb.put(key, metadataParsed.createdAt);
|
|
136
137
|
}
|
|
137
138
|
catch (e) {
|
|
138
|
-
|
|
139
|
+
afLogger.error(`Could not write metadata to db: ${e}`);
|
|
139
140
|
throw new Error(`Could not write metadata to db: ${e}`);
|
|
140
141
|
}
|
|
141
142
|
});
|
|
@@ -262,10 +263,10 @@ class AdminForthStorageAdapterLocalFilesystem {
|
|
|
262
263
|
createdAt: +Date.now(),
|
|
263
264
|
size: writeStream.bytesWritten,
|
|
264
265
|
})).catch((e) => {
|
|
265
|
-
|
|
266
|
+
afLogger.error(`Could not write metadata to db: ${e}`);
|
|
266
267
|
throw new Error(`Could not write metadata to db: ${e}`);
|
|
267
268
|
});
|
|
268
|
-
this.
|
|
269
|
+
this.markKeyForDeletion(key);
|
|
269
270
|
res.status(200).send("File uploaded");
|
|
270
271
|
});
|
|
271
272
|
}));
|
|
@@ -303,7 +304,7 @@ class AdminForthStorageAdapterLocalFilesystem {
|
|
|
303
304
|
},
|
|
304
305
|
}, (err) => {
|
|
305
306
|
if (err) {
|
|
306
|
-
|
|
307
|
+
afLogger.error(`Could not send file ${filePath}: ${err}`);
|
|
307
308
|
res.status(500).send("Could not send file");
|
|
308
309
|
}
|
|
309
310
|
});
|
|
@@ -345,7 +346,7 @@ class AdminForthStorageAdapterLocalFilesystem {
|
|
|
345
346
|
const keys = yield this.candidatesForDeletionDb.keys().all();
|
|
346
347
|
for (const key of keys) {
|
|
347
348
|
const createdAt = yield this.candidatesForDeletionDb.get(key).catch((e) => {
|
|
348
|
-
|
|
349
|
+
afLogger.error(`Could not read metadata from db: ${e}`);
|
|
349
350
|
throw new Error(`Could not read metadata from db: ${e}`);
|
|
350
351
|
});
|
|
351
352
|
if (now - +createdAt > 24 * 60 * 60 * 1000) {
|
|
@@ -354,7 +355,7 @@ class AdminForthStorageAdapterLocalFilesystem {
|
|
|
354
355
|
yield fs.unlink(path.resolve(this.options.fileSystemFolder, key));
|
|
355
356
|
}
|
|
356
357
|
catch (e) {
|
|
357
|
-
|
|
358
|
+
afLogger.error(`Could not delete file ${key}: ${e}`);
|
|
358
359
|
throw new Error(`Could not delete file ${key}: ${e}`);
|
|
359
360
|
}
|
|
360
361
|
// delete metadata
|
|
@@ -362,7 +363,7 @@ class AdminForthStorageAdapterLocalFilesystem {
|
|
|
362
363
|
yield this.metadataDb.del(key);
|
|
363
364
|
}
|
|
364
365
|
catch (e) {
|
|
365
|
-
|
|
366
|
+
afLogger.error(`Could not delete metadata from db: ${e}`);
|
|
366
367
|
throw new Error(`Could not delete metadata from db: ${e}`);
|
|
367
368
|
}
|
|
368
369
|
}
|
|
@@ -416,7 +417,7 @@ class AdminForthStorageAdapterLocalFilesystem {
|
|
|
416
417
|
const fileBuffer = yield fs.readFile(filePath);
|
|
417
418
|
const base64 = fileBuffer.toString("base64");
|
|
418
419
|
const metadata = yield this.metadataDb.get(key).catch((e) => {
|
|
419
|
-
|
|
420
|
+
afLogger.error(`Could not read metadata from db: ${e}`);
|
|
420
421
|
throw new Error(`Could not read metadata from db: ${e}`);
|
|
421
422
|
});
|
|
422
423
|
if (!metadata) {
|
package/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "fs/promises";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import AdminForth, { StorageAdapter } from "adminforth";
|
|
3
|
+
import AdminForth, { StorageAdapter, afLogger } from "adminforth";
|
|
4
4
|
import crypto from "crypto";
|
|
5
5
|
import { createWriteStream } from 'fs';
|
|
6
6
|
import { Level } from 'level';
|
|
@@ -99,13 +99,13 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
async markKeyForDeletation(key: string): Promise<void> {
|
|
102
|
-
|
|
102
|
+
afLogger.error("Method \"markKeyForDeletation\" is deprecated, use markKeyForDeletion instead");
|
|
103
103
|
const metadata = await this.metadataDb.get(key).catch((e) => {
|
|
104
|
-
|
|
104
|
+
afLogger.error(`Could not read metadata from db: ${e}`);
|
|
105
105
|
throw new Error(`Could not read metadata from db: ${e}`);
|
|
106
106
|
});
|
|
107
107
|
if (!metadata) {
|
|
108
|
-
|
|
108
|
+
afLogger.error(`Metadata for key ${key} not found`);
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
111
|
const metadataParsed = JSON.parse(metadata);
|
|
@@ -120,13 +120,13 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA
|
|
|
120
120
|
try {
|
|
121
121
|
await this.candidatesForDeletionDb.put(key, metadataParsed.createdAt)
|
|
122
122
|
} catch (e) {
|
|
123
|
-
|
|
123
|
+
afLogger.error(`Could not write metadata to db: ${e}`);
|
|
124
124
|
throw new Error(`Could not write metadata to db: ${e}`);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
async markKeyForNotDeletation(key: string): Promise<void> {
|
|
129
|
-
|
|
129
|
+
afLogger.error("Method \"markKeyForNotDeletation\" is deprecated, use markKeyForNotDeletion instead");
|
|
130
130
|
try {
|
|
131
131
|
// if key exists, delete it
|
|
132
132
|
await this.candidatesForDeletionDb.del(key);
|
|
@@ -137,11 +137,11 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA
|
|
|
137
137
|
|
|
138
138
|
async markKeyForDeletion(key: string): Promise<void> {
|
|
139
139
|
const metadata = await this.metadataDb.get(key).catch((e) => {
|
|
140
|
-
|
|
140
|
+
afLogger.error(`Could not read metadata from db: ${e}`);
|
|
141
141
|
throw new Error(`Could not read metadata from db: ${e}`);
|
|
142
142
|
});
|
|
143
143
|
if (!metadata) {
|
|
144
|
-
|
|
144
|
+
afLogger.error(`Metadata for key ${key} not found`);
|
|
145
145
|
return;
|
|
146
146
|
}
|
|
147
147
|
const metadataParsed = JSON.parse(metadata);
|
|
@@ -156,7 +156,7 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA
|
|
|
156
156
|
try {
|
|
157
157
|
await this.candidatesForDeletionDb.put(key, metadataParsed.createdAt)
|
|
158
158
|
} catch (e) {
|
|
159
|
-
|
|
159
|
+
afLogger.error(`Could not write metadata to db: ${e}`);
|
|
160
160
|
throw new Error(`Could not write metadata to db: ${e}`);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
@@ -293,11 +293,11 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA
|
|
|
293
293
|
size: writeStream.bytesWritten,
|
|
294
294
|
})
|
|
295
295
|
).catch((e) => {
|
|
296
|
-
|
|
296
|
+
afLogger.error(`Could not write metadata to db: ${e}`);
|
|
297
297
|
throw new Error(`Could not write metadata to db: ${e}`);
|
|
298
298
|
});
|
|
299
299
|
|
|
300
|
-
this.
|
|
300
|
+
this.markKeyForDeletion(key);
|
|
301
301
|
|
|
302
302
|
res.status(200).send("File uploaded");
|
|
303
303
|
});
|
|
@@ -342,7 +342,7 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA
|
|
|
342
342
|
},
|
|
343
343
|
(err) => {
|
|
344
344
|
if (err) {
|
|
345
|
-
|
|
345
|
+
afLogger.error(`Could not send file ${filePath}: ${err}`);
|
|
346
346
|
res.status(500).send("Could not send file");
|
|
347
347
|
}
|
|
348
348
|
}
|
|
@@ -393,7 +393,7 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA
|
|
|
393
393
|
const keys = await this.candidatesForDeletionDb.keys().all();
|
|
394
394
|
for (const key of keys) {
|
|
395
395
|
const createdAt = await this.candidatesForDeletionDb.get(key).catch((e) => {
|
|
396
|
-
|
|
396
|
+
afLogger.error(`Could not read metadata from db: ${e}`);
|
|
397
397
|
throw new Error(`Could not read metadata from db: ${e}`);
|
|
398
398
|
});
|
|
399
399
|
if (now - +createdAt > 24 * 60 * 60 * 1000) {
|
|
@@ -401,14 +401,14 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA
|
|
|
401
401
|
try {
|
|
402
402
|
await fs.unlink(path.resolve(this.options.fileSystemFolder, key));
|
|
403
403
|
} catch (e) {
|
|
404
|
-
|
|
404
|
+
afLogger.error(`Could not delete file ${key}: ${e}`);
|
|
405
405
|
throw new Error(`Could not delete file ${key}: ${e}`);
|
|
406
406
|
}
|
|
407
407
|
// delete metadata
|
|
408
408
|
try {
|
|
409
409
|
await this.metadataDb.del(key);
|
|
410
410
|
} catch (e) {
|
|
411
|
-
|
|
411
|
+
afLogger.error(`Could not delete metadata from db: ${e}`);
|
|
412
412
|
throw new Error(`Could not delete metadata from db: ${e}`);
|
|
413
413
|
}
|
|
414
414
|
}
|
|
@@ -464,7 +464,7 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA
|
|
|
464
464
|
const fileBuffer = await fs.readFile(filePath);
|
|
465
465
|
const base64 = fileBuffer.toString("base64");
|
|
466
466
|
const metadata = await this.metadataDb.get(key).catch((e) => {
|
|
467
|
-
|
|
467
|
+
afLogger.error(`Could not read metadata from db: ${e}`);
|
|
468
468
|
throw new Error(`Could not read metadata from db: ${e}`);
|
|
469
469
|
});
|
|
470
470
|
if (!metadata) {
|