@adminforth/upload 1.5.0 → 2.0.0
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/build.log +1 -1
- package/dist/index.js +8 -8
- package/index.ts +8 -8
- package/package.json +1 -1
- package/types.ts +5 -8
package/build.log
CHANGED
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
24
24
|
}
|
|
25
25
|
setupLifecycleRule() {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
this.options.
|
|
27
|
+
this.options.storageAdapter.setupLifecycle();
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
genPreviewUrl(record) {
|
|
@@ -34,7 +34,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
34
34
|
record[`previewUrl_${this.pluginInstanceId}`] = this.options.preview.previewUrl({ filePath: record[this.options.pathColumnName] });
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
const previewUrl = yield this.options.
|
|
37
|
+
const previewUrl = yield this.options.storageAdapter.getDownloadUrl(record[this.options.pathColumnName], 1800);
|
|
38
38
|
record[`previewUrl_${this.pluginInstanceId}`] = previewUrl;
|
|
39
39
|
});
|
|
40
40
|
}
|
|
@@ -148,7 +148,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
148
148
|
if (record[pathColumnName]) {
|
|
149
149
|
process.env.HEAVY_DEBUG && console.log('🪥🪥 remove ObjectTagging', record[pathColumnName]);
|
|
150
150
|
// let it crash if it fails: this is a new file which just was uploaded.
|
|
151
|
-
yield this.options.
|
|
151
|
+
yield this.options.storageAdapter.markKeyForNotDeletation(record[pathColumnName]);
|
|
152
152
|
}
|
|
153
153
|
return { ok: true };
|
|
154
154
|
}));
|
|
@@ -182,7 +182,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
182
182
|
resourceConfig.hooks.delete.afterSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ record }) {
|
|
183
183
|
if (record[pathColumnName]) {
|
|
184
184
|
try {
|
|
185
|
-
yield this.options.
|
|
185
|
+
yield this.options.storageAdapter.markKeyForDeletation(record[pathColumnName]);
|
|
186
186
|
}
|
|
187
187
|
catch (e) {
|
|
188
188
|
// file might be e.g. already deleted, so we catch error
|
|
@@ -206,7 +206,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
206
206
|
if (oldRecord[pathColumnName]) {
|
|
207
207
|
// put tag to delete old file
|
|
208
208
|
try {
|
|
209
|
-
yield this.options.
|
|
209
|
+
yield this.options.storageAdapter.markKeyForDeletation(oldRecord[pathColumnName]);
|
|
210
210
|
}
|
|
211
211
|
catch (e) {
|
|
212
212
|
// file might be e.g. already deleted, so we catch error
|
|
@@ -216,7 +216,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
216
216
|
if (updates[virtualColumn.name] !== null) {
|
|
217
217
|
// remove tag from new file
|
|
218
218
|
// in this case we let it crash if it fails: this is a new file which just was uploaded.
|
|
219
|
-
yield this.options.
|
|
219
|
+
yield this.options.storageAdapter.markKeyForNotDeletation(updates[pathColumnName]);
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
222
|
return { ok: true };
|
|
@@ -261,13 +261,13 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
261
261
|
if (filePath.startsWith('/')) {
|
|
262
262
|
throw new Error('s3Path should not start with /, please adjust s3path function to not return / at the start of the path');
|
|
263
263
|
}
|
|
264
|
-
const { uploadUrl, uploadExtraParams } = yield this.options.
|
|
264
|
+
const { uploadUrl, uploadExtraParams } = yield this.options.storageAdapter.getUploadSignedUrl(filePath, contentType, 1800);
|
|
265
265
|
let previewUrl;
|
|
266
266
|
if ((_c = this.options.preview) === null || _c === void 0 ? void 0 : _c.previewUrl) {
|
|
267
267
|
previewUrl = this.options.preview.previewUrl({ filePath });
|
|
268
268
|
}
|
|
269
269
|
else {
|
|
270
|
-
previewUrl = yield this.options.
|
|
270
|
+
previewUrl = yield this.options.storageAdapter.getDownloadUrl(filePath, 1800);
|
|
271
271
|
}
|
|
272
272
|
return {
|
|
273
273
|
uploadUrl,
|
package/index.ts
CHANGED
|
@@ -28,7 +28,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
async setupLifecycleRule() {
|
|
31
|
-
this.options.
|
|
31
|
+
this.options.storageAdapter.setupLifecycle();
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
async genPreviewUrl(record: any) {
|
|
@@ -36,7 +36,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
36
36
|
record[`previewUrl_${this.pluginInstanceId}`] = this.options.preview.previewUrl({ filePath: record[this.options.pathColumnName] });
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
|
-
const previewUrl = await this.options.
|
|
39
|
+
const previewUrl = await this.options.storageAdapter.getDownloadUrl(record[this.options.pathColumnName], 1800);
|
|
40
40
|
|
|
41
41
|
record[`previewUrl_${this.pluginInstanceId}`] = previewUrl;
|
|
42
42
|
}
|
|
@@ -161,7 +161,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
161
161
|
if (record[pathColumnName]) {
|
|
162
162
|
process.env.HEAVY_DEBUG && console.log('🪥🪥 remove ObjectTagging', record[pathColumnName]);
|
|
163
163
|
// let it crash if it fails: this is a new file which just was uploaded.
|
|
164
|
-
await this.options.
|
|
164
|
+
await this.options.storageAdapter.markKeyForNotDeletation(record[pathColumnName]);
|
|
165
165
|
}
|
|
166
166
|
return { ok: true };
|
|
167
167
|
});
|
|
@@ -204,7 +204,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
204
204
|
resourceConfig.hooks.delete.afterSave.push(async ({ record }: { record: any }) => {
|
|
205
205
|
if (record[pathColumnName]) {
|
|
206
206
|
try {
|
|
207
|
-
await this.options.
|
|
207
|
+
await this.options.storageAdapter.markKeyForDeletation(record[pathColumnName]);
|
|
208
208
|
} catch (e) {
|
|
209
209
|
// file might be e.g. already deleted, so we catch error
|
|
210
210
|
console.error(`Error setting tag ${ADMINFORTH_NOT_YET_USED_TAG} to true for object ${record[pathColumnName]}. File will not be auto-cleaned up`, e);
|
|
@@ -233,7 +233,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
233
233
|
if (oldRecord[pathColumnName]) {
|
|
234
234
|
// put tag to delete old file
|
|
235
235
|
try {
|
|
236
|
-
await this.options.
|
|
236
|
+
await this.options.storageAdapter.markKeyForDeletation(oldRecord[pathColumnName]);
|
|
237
237
|
} catch (e) {
|
|
238
238
|
// file might be e.g. already deleted, so we catch error
|
|
239
239
|
console.error(`Error setting tag ${ADMINFORTH_NOT_YET_USED_TAG} to true for object ${oldRecord[pathColumnName]}. File will not be auto-cleaned up`, e);
|
|
@@ -242,7 +242,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
242
242
|
if (updates[virtualColumn.name] !== null) {
|
|
243
243
|
// remove tag from new file
|
|
244
244
|
// in this case we let it crash if it fails: this is a new file which just was uploaded.
|
|
245
|
-
await this.options.
|
|
245
|
+
await this.options.storageAdapter.markKeyForNotDeletation(updates[pathColumnName]);
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
return { ok: true };
|
|
@@ -296,12 +296,12 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
296
296
|
if (filePath.startsWith('/')) {
|
|
297
297
|
throw new Error('s3Path should not start with /, please adjust s3path function to not return / at the start of the path');
|
|
298
298
|
}
|
|
299
|
-
const { uploadUrl, uploadExtraParams } = await this.options.
|
|
299
|
+
const { uploadUrl, uploadExtraParams } = await this.options.storageAdapter.getUploadSignedUrl(filePath, contentType, 1800);
|
|
300
300
|
let previewUrl;
|
|
301
301
|
if (this.options.preview?.previewUrl) {
|
|
302
302
|
previewUrl = this.options.preview.previewUrl({ filePath });
|
|
303
303
|
} else {
|
|
304
|
-
previewUrl = await this.options.
|
|
304
|
+
previewUrl = await this.options.storageAdapter.getDownloadUrl(filePath, 1800);
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
return {
|
package/package.json
CHANGED
package/types.ts
CHANGED
|
@@ -155,12 +155,9 @@ export type PluginOptions = {
|
|
|
155
155
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
adapter: StorageAdapter,
|
|
164
|
-
}
|
|
165
|
-
|
|
158
|
+
/**
|
|
159
|
+
* The adapter used to store the files.
|
|
160
|
+
* For now only S3 adapter is supported.
|
|
161
|
+
*/
|
|
162
|
+
storageAdapter: StorageAdapter,
|
|
166
163
|
}
|