@adminforth/upload 1.1.1 → 1.2.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/README.md +2 -0
- package/dist/index.js +39 -36
- package/index.ts +42 -36
- package/package.json +10 -1
- package/types.ts +0 -12
package/README.md
ADDED
package/dist/index.js
CHANGED
|
@@ -99,7 +99,7 @@ getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${t
|
|
|
99
99
|
modifyResourceConfig: { get: () => super.modifyResourceConfig }
|
|
100
100
|
});
|
|
101
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
var _a, _b, _c, _d
|
|
102
|
+
var _a, _b, _c, _d;
|
|
103
103
|
_super.modifyResourceConfig.call(this, adminforth, resourceConfig);
|
|
104
104
|
// after column to store the path of the uploaded file, add new VirtualColumn,
|
|
105
105
|
// show only in edit and create views
|
|
@@ -149,33 +149,34 @@ getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${t
|
|
|
149
149
|
list: false,
|
|
150
150
|
show: false,
|
|
151
151
|
filter: false,
|
|
152
|
-
}
|
|
152
|
+
},
|
|
153
153
|
};
|
|
154
154
|
if (!resourceConfig.columns[pathColumnIndex].components) {
|
|
155
155
|
resourceConfig.columns[pathColumnIndex].components = {};
|
|
156
156
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
meta: pluginFrontendOptions,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
157
|
+
const pathColumn = resourceConfig.columns[pathColumnIndex];
|
|
158
|
+
// add preview column to list
|
|
159
|
+
resourceConfig.columns[pathColumnIndex].components.list = {
|
|
160
|
+
file: this.componentPath('preview.vue'),
|
|
161
|
+
meta: pluginFrontendOptions,
|
|
162
|
+
};
|
|
163
|
+
resourceConfig.columns[pathColumnIndex].components.show = {
|
|
164
|
+
file: this.componentPath('preview.vue'),
|
|
165
|
+
meta: pluginFrontendOptions,
|
|
166
|
+
};
|
|
170
167
|
// insert virtual column after path column if it is not already there
|
|
171
168
|
const virtualColumnIndex = resourceConfig.columns.findIndex((column) => column.name === virtualColumn.name);
|
|
172
169
|
if (virtualColumnIndex === -1) {
|
|
173
170
|
resourceConfig.columns.splice(pathColumnIndex + 1, 0, virtualColumn);
|
|
174
171
|
}
|
|
175
|
-
// if showIn of path column has 'create' or 'edit' remove it
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
pathColumn.showIn = Object.assign(Object.assign({}, pathColumn.showIn), { create: false
|
|
172
|
+
// if showIn of path column has 'create' or 'edit' remove it but use it for virtual column
|
|
173
|
+
if (pathColumn.showIn && (pathColumn.showIn.create !== undefined)) {
|
|
174
|
+
virtualColumn.showIn = Object.assign(Object.assign({}, virtualColumn.showIn), { create: pathColumn.showIn.create });
|
|
175
|
+
pathColumn.showIn = Object.assign(Object.assign({}, pathColumn.showIn), { create: false });
|
|
176
|
+
}
|
|
177
|
+
if (pathColumn.showIn && (pathColumn.showIn.edit !== undefined)) {
|
|
178
|
+
virtualColumn.showIn = Object.assign(Object.assign({}, virtualColumn.showIn), { edit: pathColumn.showIn.edit });
|
|
179
|
+
pathColumn.showIn = Object.assign(Object.assign({}, pathColumn.showIn), { edit: false });
|
|
179
180
|
}
|
|
180
181
|
virtualColumn.required = pathColumn.required;
|
|
181
182
|
virtualColumn.label = pathColumn.label;
|
|
@@ -214,25 +215,27 @@ getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${t
|
|
|
214
215
|
}));
|
|
215
216
|
// ** HOOKS FOR SHOW **//
|
|
216
217
|
// add show hook to get presigned URL
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
if (pathColumn.showIn.show) {
|
|
219
|
+
resourceConfig.hooks.show.afterDatasourceResponse.push((_a) => __awaiter(this, [_a], void 0, function* ({ response }) {
|
|
220
|
+
const record = response[0];
|
|
221
|
+
if (!record) {
|
|
222
|
+
return { ok: true };
|
|
223
|
+
}
|
|
224
|
+
if (record[pathColumnName]) {
|
|
225
|
+
const s3 = new S3({
|
|
226
|
+
credentials: {
|
|
227
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
228
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
229
|
+
},
|
|
230
|
+
region: this.options.s3Region,
|
|
231
|
+
});
|
|
232
|
+
yield this.genPreviewUrl(record, s3);
|
|
233
|
+
}
|
|
220
234
|
return { ok: true };
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const s3 = new S3({
|
|
224
|
-
credentials: {
|
|
225
|
-
accessKeyId: this.options.s3AccessKeyId,
|
|
226
|
-
secretAccessKey: this.options.s3SecretAccessKey,
|
|
227
|
-
},
|
|
228
|
-
region: this.options.s3Region,
|
|
229
|
-
});
|
|
230
|
-
yield this.genPreviewUrl(record, s3);
|
|
231
|
-
}
|
|
232
|
-
return { ok: true };
|
|
233
|
-
}));
|
|
235
|
+
}));
|
|
236
|
+
}
|
|
234
237
|
// ** HOOKS FOR LIST **//
|
|
235
|
-
if (
|
|
238
|
+
if (pathColumn.showIn.list) {
|
|
236
239
|
resourceConfig.hooks.list.afterDatasourceResponse.push((_a) => __awaiter(this, [_a], void 0, function* ({ response }) {
|
|
237
240
|
const s3 = new S3({
|
|
238
241
|
credentials: {
|
package/index.ts
CHANGED
|
@@ -150,27 +150,24 @@ getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${t
|
|
|
150
150
|
list: false,
|
|
151
151
|
show: false,
|
|
152
152
|
filter: false,
|
|
153
|
-
}
|
|
153
|
+
},
|
|
154
154
|
};
|
|
155
155
|
|
|
156
156
|
if (!resourceConfig.columns[pathColumnIndex].components) {
|
|
157
157
|
resourceConfig.columns[pathColumnIndex].components = {};
|
|
158
158
|
}
|
|
159
|
+
const pathColumn = resourceConfig.columns[pathColumnIndex];
|
|
159
160
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
};
|
|
166
|
-
}
|
|
161
|
+
// add preview column to list
|
|
162
|
+
resourceConfig.columns[pathColumnIndex].components.list = {
|
|
163
|
+
file: this.componentPath('preview.vue'),
|
|
164
|
+
meta: pluginFrontendOptions,
|
|
165
|
+
};
|
|
167
166
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
};
|
|
173
|
-
}
|
|
167
|
+
resourceConfig.columns[pathColumnIndex].components.show = {
|
|
168
|
+
file: this.componentPath('preview.vue'),
|
|
169
|
+
meta: pluginFrontendOptions,
|
|
170
|
+
};
|
|
174
171
|
|
|
175
172
|
// insert virtual column after path column if it is not already there
|
|
176
173
|
const virtualColumnIndex = resourceConfig.columns.findIndex((column: any) => column.name === virtualColumn.name);
|
|
@@ -178,10 +175,16 @@ getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${t
|
|
|
178
175
|
resourceConfig.columns.splice(pathColumnIndex + 1, 0, virtualColumn);
|
|
179
176
|
}
|
|
180
177
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (pathColumn.showIn && (pathColumn.showIn.create
|
|
184
|
-
|
|
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 };
|
|
185
188
|
}
|
|
186
189
|
|
|
187
190
|
virtualColumn.required = pathColumn.required;
|
|
@@ -229,30 +232,33 @@ getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${t
|
|
|
229
232
|
|
|
230
233
|
|
|
231
234
|
// add show hook to get presigned URL
|
|
232
|
-
|
|
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) {
|
|
243
236
|
|
|
244
|
-
|
|
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
|
+
});
|
|
246
251
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
252
|
+
await this.genPreviewUrl(record, s3);
|
|
253
|
+
}
|
|
254
|
+
return { ok: true };
|
|
255
|
+
});
|
|
256
|
+
}
|
|
251
257
|
|
|
252
258
|
// ** HOOKS FOR LIST **//
|
|
253
259
|
|
|
254
260
|
|
|
255
|
-
if (
|
|
261
|
+
if (pathColumn.showIn.list) {
|
|
256
262
|
resourceConfig.hooks.list.afterDatasourceResponse.push(async ({ response }: { response: any }) => {
|
|
257
263
|
const s3 = new S3({
|
|
258
264
|
credentials: {
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/upload",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Plugin for uploading files for adminforth",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"homepage": "https://adminforth.dev/docs/tutorial/Plugins/upload/",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
9
10
|
"url": "https://github.com/devforth/adminforth-upload.git"
|
|
@@ -19,6 +20,14 @@
|
|
|
19
20
|
"@aws-sdk/client-s3": "^3.629.0",
|
|
20
21
|
"@aws-sdk/s3-request-presigner": "^3.629.0"
|
|
21
22
|
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"adminforth",
|
|
25
|
+
"upload",
|
|
26
|
+
"plugin",
|
|
27
|
+
"s3-upload",
|
|
28
|
+
"aws-s3",
|
|
29
|
+
"file-upload"
|
|
30
|
+
],
|
|
22
31
|
"release": {
|
|
23
32
|
"plugins": [
|
|
24
33
|
"@semantic-release/commit-analyzer",
|
package/types.ts
CHANGED
|
@@ -64,18 +64,6 @@ export type PluginOptions = {
|
|
|
64
64
|
|
|
65
65
|
preview: {
|
|
66
66
|
|
|
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
|
-
|
|
79
67
|
/**
|
|
80
68
|
* Maximum width of the preview image
|
|
81
69
|
*/
|