Skip to content

Commit 22f1da5

Browse files
committed
BREAKING CHANGE: use adapters for storage
1 parent 124e3b9 commit 22f1da5

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ export default class UploadPlugin extends AdminForthPlugin {
2828
}
2929

3030
async setupLifecycleRule() {
31-
this.options.storage.adapter.setupLifecycle();
31+
this.options.storageAdapter.setupLifecycle();
3232
}
3333

3434
async genPreviewUrl(record: any) {
3535
if (this.options.preview?.previewUrl) {
3636
record[`previewUrl_${this.pluginInstanceId}`] = this.options.preview.previewUrl({ filePath: record[this.options.pathColumnName] });
3737
return;
3838
}
39-
const previewUrl = await this.options.storage.adapter.getDownloadUrl(record[this.options.pathColumnName], 1800);
39+
const previewUrl = await this.options.storageAdapter.getDownloadUrl(record[this.options.pathColumnName], 1800);
4040

4141
record[`previewUrl_${this.pluginInstanceId}`] = previewUrl;
4242
}
@@ -161,7 +161,7 @@ export default class UploadPlugin extends AdminForthPlugin {
161161
if (record[pathColumnName]) {
162162
process.env.HEAVY_DEBUG && console.log('🪥🪥 remove ObjectTagging', record[pathColumnName]);
163163
// let it crash if it fails: this is a new file which just was uploaded.
164-
await this.options.storage.adapter.markKeyForNotDeletation(record[pathColumnName]);
164+
await this.options.storageAdapter.markKeyForNotDeletation(record[pathColumnName]);
165165
}
166166
return { ok: true };
167167
});
@@ -204,7 +204,7 @@ export default class UploadPlugin extends AdminForthPlugin {
204204
resourceConfig.hooks.delete.afterSave.push(async ({ record }: { record: any }) => {
205205
if (record[pathColumnName]) {
206206
try {
207-
await this.options.storage.adapter.markKeyForDeletation(record[pathColumnName]);
207+
await this.options.storageAdapter.markKeyForDeletation(record[pathColumnName]);
208208
} catch (e) {
209209
// file might be e.g. already deleted, so we catch error
210210
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 {
233233
if (oldRecord[pathColumnName]) {
234234
// put tag to delete old file
235235
try {
236-
await this.options.storage.adapter.markKeyForDeletation(oldRecord[pathColumnName]);
236+
await this.options.storageAdapter.markKeyForDeletation(oldRecord[pathColumnName]);
237237
} catch (e) {
238238
// file might be e.g. already deleted, so we catch error
239239
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 {
242242
if (updates[virtualColumn.name] !== null) {
243243
// remove tag from new file
244244
// in this case we let it crash if it fails: this is a new file which just was uploaded.
245-
await this.options.storage.adapter.markKeyForNotDeletation(updates[pathColumnName]);
245+
await this.options.storageAdapter.markKeyForNotDeletation(updates[pathColumnName]);
246246
}
247247
}
248248
return { ok: true };
@@ -296,12 +296,12 @@ export default class UploadPlugin extends AdminForthPlugin {
296296
if (filePath.startsWith('/')) {
297297
throw new Error('s3Path should not start with /, please adjust s3path function to not return / at the start of the path');
298298
}
299-
const { uploadUrl, uploadExtraParams } = await this.options.storage.adapter.getUploadSignedUrl(filePath, contentType, 1800);
299+
const { uploadUrl, uploadExtraParams } = await this.options.storageAdapter.getUploadSignedUrl(filePath, contentType, 1800);
300300
let previewUrl;
301301
if (this.options.preview?.previewUrl) {
302302
previewUrl = this.options.preview.previewUrl({ filePath });
303303
} else {
304-
previewUrl = await this.options.storage.adapter.getDownloadUrl(filePath, 1800);
304+
previewUrl = await this.options.storageAdapter.getDownloadUrl(filePath, 1800);
305305
}
306306

307307
return {

types.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,10 @@ export type PluginOptions = {
155155

156156
}
157157

158-
storage?: {
159-
/**
160-
* The adapter used to store the files.
161-
* For now only S3 adapter is supported.
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+
163+
storageAdapter: StorageAdapter,
166164
}

0 commit comments

Comments
 (0)