Skip to content

Commit cdc1aee

Browse files
committed
Merge branch 'next' of github.com:devforth/adminforth-upload
2 parents a9d41dd + fca0c22 commit cdc1aee

File tree

4 files changed

+53
-48
lines changed

4 files changed

+53
-48
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
Ussage guide and documentation: https://adminforth.dev/docs/tutorial/Plugins/upload/

index.ts

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -150,38 +150,41 @@ getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${t
150150
list: false,
151151
show: false,
152152
filter: false,
153-
}
153+
},
154154
};
155155

156156
if (!resourceConfig.columns[pathColumnIndex].components) {
157157
resourceConfig.columns[pathColumnIndex].components = {};
158158
}
159+
const pathColumn = resourceConfig.columns[pathColumnIndex];
159160

160-
if (this.options.preview?.showInList || this.options.preview?.showInList === undefined) {
161-
// add preview column to list
162-
resourceConfig.columns[pathColumnIndex].components.list = {
163-
file: this.componentPath('preview.vue'),
164-
meta: pluginFrontendOptions,
165-
};
166-
}
161+
// add preview column to list
162+
resourceConfig.columns[pathColumnIndex].components.list = {
163+
file: this.componentPath('preview.vue'),
164+
meta: pluginFrontendOptions,
165+
};
167166

168-
if (this.options.preview?.showInShow || this.options.preview?.showInShow === undefined) {
169-
resourceConfig.columns[pathColumnIndex].components.show = {
170-
file: this.componentPath('preview.vue'),
171-
meta: pluginFrontendOptions,
172-
};
173-
}
167+
resourceConfig.columns[pathColumnIndex].components.show = {
168+
file: this.componentPath('preview.vue'),
169+
meta: pluginFrontendOptions,
170+
};
174171

175172
// insert virtual column after path column if it is not already there
176173
const virtualColumnIndex = resourceConfig.columns.findIndex((column: any) => column.name === virtualColumn.name);
177174
if (virtualColumnIndex === -1) {
178175
resourceConfig.columns.splice(pathColumnIndex + 1, 0, virtualColumn);
179176
}
180177

181-
// if showIn of path column has 'create' or 'edit' remove it
182-
const pathColumn = resourceConfig.columns[pathColumnIndex];
183-
if (pathColumn.showIn && (pathColumn.showIn.create || pathColumn.showIn.edit)) {
184-
pathColumn.showIn = { ...pathColumn.showIn, create: false, edit: false };
178+
179+
// if showIn of path column has 'create' or 'edit' remove it but use it for virtual column
180+
if (pathColumn.showIn && (pathColumn.showIn.create !== undefined)) {
181+
virtualColumn.showIn = { ...virtualColumn.showIn, create: pathColumn.showIn.create };
182+
pathColumn.showIn = { ...pathColumn.showIn, create: false };
183+
}
184+
185+
if (pathColumn.showIn && (pathColumn.showIn.edit !== undefined)) {
186+
virtualColumn.showIn = { ...virtualColumn.showIn, edit: pathColumn.showIn.edit };
187+
pathColumn.showIn = { ...pathColumn.showIn, edit: false };
185188
}
186189

187190
virtualColumn.required = pathColumn.required;
@@ -229,30 +232,33 @@ getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${t
229232

230233

231234
// add show hook to get presigned URL
232-
resourceConfig.hooks.show.afterDatasourceResponse.push(async ({ response }: { response: any }) => {
233-
const record = response[0];
234-
if (!record) {
235-
return { ok: true };
236-
}
237-
if (record[pathColumnName]) {
238-
const s3 = new S3({
239-
credentials: {
240-
accessKeyId: this.options.s3AccessKeyId,
241-
secretAccessKey: this.options.s3SecretAccessKey,
242-
},
235+
if (pathColumn.showIn.show) {
243236

244-
region: this.options.s3Region,
245-
});
237+
resourceConfig.hooks.show.afterDatasourceResponse.push(async ({ response }: { response: any }) => {
238+
const record = response[0];
239+
if (!record) {
240+
return { ok: true };
241+
}
242+
if (record[pathColumnName]) {
243+
const s3 = new S3({
244+
credentials: {
245+
accessKeyId: this.options.s3AccessKeyId,
246+
secretAccessKey: this.options.s3SecretAccessKey,
247+
},
248+
249+
region: this.options.s3Region,
250+
});
246251

247-
await this.genPreviewUrl(record, s3);
248-
}
249-
return { ok: true };
250-
});
252+
await this.genPreviewUrl(record, s3);
253+
}
254+
return { ok: true };
255+
});
256+
}
251257

252258
// ** HOOKS FOR LIST **//
253259

254260

255-
if (this.options.preview?.showInList || this.options.preview?.showInList === undefined) {
261+
if (pathColumn.showIn.list) {
256262
resourceConfig.hooks.list.afterDatasourceResponse.push(async ({ response }: { response: any }) => {
257263
const s3 = new S3({
258264
credentials: {

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Plugin for uploading files for adminforth",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
7+
"homepage": "https://adminforth.dev/docs/tutorial/Plugins/upload/",
78
"repository": {
89
"type": "git",
910
"url": "https://github.com/devforth/adminforth-upload.git"
@@ -19,6 +20,14 @@
1920
"@aws-sdk/client-s3": "^3.629.0",
2021
"@aws-sdk/s3-request-presigner": "^3.629.0"
2122
},
23+
"keywords": [
24+
"adminforth",
25+
"upload",
26+
"plugin",
27+
"s3-upload",
28+
"aws-s3",
29+
"file-upload"
30+
],
2231
"release": {
2332
"plugins": [
2433
"@semantic-release/commit-analyzer",

types.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,6 @@ export type PluginOptions = {
6464

6565
preview: {
6666

67-
/**
68-
* Whether to show preview of image instead of path in list field
69-
* By default true
70-
*/
71-
showInList?: boolean,
72-
73-
/**
74-
* Whether to show preview of image instead of path in list field
75-
* By default true
76-
*/
77-
showInShow?: boolean,
78-
7967
/**
8068
* Maximum width of the preview image
8169
*/

0 commit comments

Comments
 (0)