@adminforth/upload 1.0.6 → 1.0.7
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 +307 -0
- package/dist/types.js +1 -0
- package/package.json +5 -3
- package/tsconfig.json +112 -0
- package/dist/package-lock.json +0 -21
- package/dist/package.json +0 -15
- package/dist/preview.vue +0 -56
- package/dist/uploader.vue +0 -163
package/dist/index.js
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import AWS from 'aws-sdk';
|
|
11
|
+
import { AdminForthPlugin, AdminForthResourcePages } from "adminforth";
|
|
12
|
+
const ADMINFORTH_NOT_YET_USED_TAG = 'adminforth-candidate-for-cleanup';
|
|
13
|
+
export default class UploadPlugin extends AdminForthPlugin {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
super(options, import.meta.url);
|
|
16
|
+
this.options = options;
|
|
17
|
+
}
|
|
18
|
+
setupLifecycleRule() {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
// check that lifecyle rule "adminforth-unused-cleaner" exists
|
|
21
|
+
const CLEANUP_RULE_ID = 'adminforth-unused-cleaner';
|
|
22
|
+
const s3 = new AWS.S3({
|
|
23
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
24
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
25
|
+
region: this.options.s3Region
|
|
26
|
+
});
|
|
27
|
+
// check bucket exists
|
|
28
|
+
const bucketExists = s3.headBucket({ Bucket: this.options.s3Bucket }).promise();
|
|
29
|
+
if (!bucketExists) {
|
|
30
|
+
throw new Error(`Bucket ${this.options.s3Bucket} does not exist`);
|
|
31
|
+
}
|
|
32
|
+
// check that lifecycle rule exists
|
|
33
|
+
let ruleExists = false;
|
|
34
|
+
try {
|
|
35
|
+
const lifecycleConfig = yield s3.getBucketLifecycleConfiguration({ Bucket: this.options.s3Bucket }).promise();
|
|
36
|
+
ruleExists = lifecycleConfig.Rules.some((rule) => rule.ID === CLEANUP_RULE_ID);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
if (e.code !== 'NoSuchLifecycleConfiguration') {
|
|
40
|
+
throw e;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
ruleExists = false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!ruleExists) {
|
|
47
|
+
// create
|
|
48
|
+
// rule deletes object has tag adminforth-candidate-for-cleanup = true after 2 days
|
|
49
|
+
const params = {
|
|
50
|
+
Bucket: this.options.s3Bucket,
|
|
51
|
+
LifecycleConfiguration: {
|
|
52
|
+
Rules: [
|
|
53
|
+
{
|
|
54
|
+
ID: CLEANUP_RULE_ID,
|
|
55
|
+
Status: 'Enabled',
|
|
56
|
+
Filter: {
|
|
57
|
+
Tag: {
|
|
58
|
+
Key: ADMINFORTH_NOT_YET_USED_TAG,
|
|
59
|
+
Value: 'true'
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
Expiration: {
|
|
63
|
+
Days: 2
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
yield s3.putBucketLifecycleConfiguration(params).promise();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
genPreviewUrl(record, s3) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
var _a;
|
|
76
|
+
if ((_a = this.options.preview) === null || _a === void 0 ? void 0 : _a.previewUrl) {
|
|
77
|
+
record[`previewUrl_${this.pluginInstanceId}`] = this.options.preview.previewUrl({ s3Path: record[this.options.pathColumnName] });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const previewUrl = yield s3.getSignedUrl('getObject', {
|
|
81
|
+
Bucket: this.options.s3Bucket,
|
|
82
|
+
Key: record[this.options.pathColumnName],
|
|
83
|
+
});
|
|
84
|
+
record[`previewUrl_${this.pluginInstanceId}`] = previewUrl;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
modifyResourceConfig(adminforth, resourceConfig) {
|
|
88
|
+
const _super = Object.create(null, {
|
|
89
|
+
modifyResourceConfig: { get: () => super.modifyResourceConfig }
|
|
90
|
+
});
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
var _a, _b, _c;
|
|
93
|
+
this.setupLifecycleRule();
|
|
94
|
+
_super.modifyResourceConfig.call(this, adminforth, resourceConfig);
|
|
95
|
+
// after column to store the path of the uploaded file, add new VirtualColumn,
|
|
96
|
+
// show only in edit and create views
|
|
97
|
+
// use component uploader.vue
|
|
98
|
+
const { pathColumnName } = this.options;
|
|
99
|
+
const pluginFrontendOptions = {
|
|
100
|
+
allowedExtensions: this.options.allowedFileExtensions,
|
|
101
|
+
maxFileSize: this.options.maxFileSize,
|
|
102
|
+
pluginInstanceId: this.pluginInstanceId,
|
|
103
|
+
};
|
|
104
|
+
const virtualColumn = {
|
|
105
|
+
virtual: true,
|
|
106
|
+
name: `uploader_${this.pluginInstanceId}`,
|
|
107
|
+
components: Object.assign({ edit: {
|
|
108
|
+
file: this.componentPath('uploader.vue'),
|
|
109
|
+
meta: pluginFrontendOptions,
|
|
110
|
+
}, create: {
|
|
111
|
+
file: this.componentPath('uploader.vue'),
|
|
112
|
+
meta: pluginFrontendOptions,
|
|
113
|
+
}, show: {
|
|
114
|
+
file: this.componentPath('preview.vue'),
|
|
115
|
+
meta: pluginFrontendOptions,
|
|
116
|
+
} }, (((_a = this.options.preview) === null || _a === void 0 ? void 0 : _a.showInList) ? {
|
|
117
|
+
list: {
|
|
118
|
+
file: this.componentPath('preview.vue'),
|
|
119
|
+
meta: pluginFrontendOptions,
|
|
120
|
+
}
|
|
121
|
+
} : {})),
|
|
122
|
+
showIn: ['edit', 'create', 'show', ...(((_b = this.options.preview) === null || _b === void 0 ? void 0 : _b.showInList) ? [
|
|
123
|
+
AdminForthResourcePages.list
|
|
124
|
+
] : [])],
|
|
125
|
+
};
|
|
126
|
+
const pathColumnIndex = resourceConfig.columns.findIndex((column) => column.name === pathColumnName);
|
|
127
|
+
if (pathColumnIndex === -1) {
|
|
128
|
+
throw new Error(`Column with name "${pathColumnName}" not found in resource "${resourceConfig.name}"`);
|
|
129
|
+
}
|
|
130
|
+
// insert virtual column after path column if it is not already there
|
|
131
|
+
const virtualColumnIndex = resourceConfig.columns.findIndex((column) => column.name === virtualColumn.name);
|
|
132
|
+
if (virtualColumnIndex === -1) {
|
|
133
|
+
resourceConfig.columns.splice(pathColumnIndex + 1, 0, virtualColumn);
|
|
134
|
+
}
|
|
135
|
+
// if showIn of path column has 'create' or 'edit' remove it
|
|
136
|
+
const pathColumn = resourceConfig.columns[pathColumnIndex];
|
|
137
|
+
if (pathColumn.showIn && (pathColumn.showIn.includes('create') || pathColumn.showIn.includes('edit'))) {
|
|
138
|
+
pathColumn.showIn = pathColumn.showIn.filter((view) => !['create', 'edit'].includes(view));
|
|
139
|
+
}
|
|
140
|
+
virtualColumn.required = pathColumn.required;
|
|
141
|
+
virtualColumn.label = pathColumn.label;
|
|
142
|
+
virtualColumn.editingNote = pathColumn.editingNote;
|
|
143
|
+
// ** HOOKS FOR CREATE **//
|
|
144
|
+
// add beforeSave hook to save virtual column to path column
|
|
145
|
+
resourceConfig.hooks.create.beforeSave.push((_d) => __awaiter(this, [_d], void 0, function* ({ record }) {
|
|
146
|
+
if (record[virtualColumn.name]) {
|
|
147
|
+
record[pathColumnName] = record[virtualColumn.name];
|
|
148
|
+
delete record[virtualColumn.name];
|
|
149
|
+
}
|
|
150
|
+
return { ok: true };
|
|
151
|
+
}));
|
|
152
|
+
// in afterSave hook, aremove tag adminforth-not-yet-used from the file
|
|
153
|
+
resourceConfig.hooks.create.afterSave.push((_e) => __awaiter(this, [_e], void 0, function* ({ record }) {
|
|
154
|
+
if (record[pathColumnName]) {
|
|
155
|
+
const s3 = new AWS.S3({
|
|
156
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
157
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
158
|
+
region: this.options.s3Region
|
|
159
|
+
});
|
|
160
|
+
yield s3.putObjectTagging({
|
|
161
|
+
Bucket: this.options.s3Bucket,
|
|
162
|
+
Key: record[pathColumnName],
|
|
163
|
+
Tagging: {
|
|
164
|
+
TagSet: []
|
|
165
|
+
}
|
|
166
|
+
}).promise();
|
|
167
|
+
}
|
|
168
|
+
return { ok: true };
|
|
169
|
+
}));
|
|
170
|
+
// ** HOOKS FOR SHOW **//
|
|
171
|
+
// add show hook to get presigned URL
|
|
172
|
+
resourceConfig.hooks.show.afterDatasourceResponse.push((_f) => __awaiter(this, [_f], void 0, function* ({ response }) {
|
|
173
|
+
const record = response[0];
|
|
174
|
+
if (!record) {
|
|
175
|
+
return { ok: true };
|
|
176
|
+
}
|
|
177
|
+
if (record[pathColumnName]) {
|
|
178
|
+
const s3 = new AWS.S3({
|
|
179
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
180
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
181
|
+
region: this.options.s3Region
|
|
182
|
+
});
|
|
183
|
+
yield this.genPreviewUrl(record, s3);
|
|
184
|
+
}
|
|
185
|
+
return { ok: true };
|
|
186
|
+
}));
|
|
187
|
+
// ** HOOKS FOR LIST **//
|
|
188
|
+
if ((_c = this.options.preview) === null || _c === void 0 ? void 0 : _c.showInList) {
|
|
189
|
+
resourceConfig.hooks.list.afterDatasourceResponse.push((_g) => __awaiter(this, [_g], void 0, function* ({ response }) {
|
|
190
|
+
const s3 = new AWS.S3({
|
|
191
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
192
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
193
|
+
region: this.options.s3Region
|
|
194
|
+
});
|
|
195
|
+
yield Promise.all(response.map((record) => __awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
if (record[this.options.pathColumnName]) {
|
|
197
|
+
yield this.genPreviewUrl(record, s3);
|
|
198
|
+
}
|
|
199
|
+
})));
|
|
200
|
+
return { ok: true };
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
// ** HOOKS FOR DELETE **//
|
|
204
|
+
// add delete hook which sets tag adminforth-candidate-for-cleanup to true
|
|
205
|
+
resourceConfig.hooks.delete.beforeSave.push((_h) => __awaiter(this, [_h], void 0, function* ({ record }) {
|
|
206
|
+
if (record[pathColumnName]) {
|
|
207
|
+
const s3 = new AWS.S3({
|
|
208
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
209
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
210
|
+
region: this.options.s3Region
|
|
211
|
+
});
|
|
212
|
+
yield s3.putObjectTagging({
|
|
213
|
+
Bucket: this.options.s3Bucket,
|
|
214
|
+
Key: record[pathColumnName],
|
|
215
|
+
Tagging: {
|
|
216
|
+
TagSet: [
|
|
217
|
+
{
|
|
218
|
+
Key: ADMINFORTH_NOT_YET_USED_TAG,
|
|
219
|
+
Value: 'true'
|
|
220
|
+
}
|
|
221
|
+
]
|
|
222
|
+
}
|
|
223
|
+
}).promise();
|
|
224
|
+
}
|
|
225
|
+
return { ok: true };
|
|
226
|
+
}));
|
|
227
|
+
// ** HOOKS FOR EDIT **//
|
|
228
|
+
// beforeSave
|
|
229
|
+
resourceConfig.hooks.edit.beforeSave.push((_j) => __awaiter(this, [_j], void 0, function* ({ record }) {
|
|
230
|
+
// null is when value is removed
|
|
231
|
+
if (record[virtualColumn.name] || record[virtualColumn.name] === null) {
|
|
232
|
+
record[pathColumnName] = record[virtualColumn.name];
|
|
233
|
+
}
|
|
234
|
+
return { ok: true };
|
|
235
|
+
}));
|
|
236
|
+
// add edit postSave hook to delete old file and remove tag from new file
|
|
237
|
+
resourceConfig.hooks.edit.afterSave.push((_k) => __awaiter(this, [_k], void 0, function* ({ record, oldRecord }) {
|
|
238
|
+
if (record[virtualColumn.name] || record[virtualColumn.name] === null) {
|
|
239
|
+
const s3 = new AWS.S3({
|
|
240
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
241
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
242
|
+
region: this.options.s3Region
|
|
243
|
+
});
|
|
244
|
+
if (oldRecord[pathColumnName]) {
|
|
245
|
+
// put tag to delete old file
|
|
246
|
+
yield s3.putObjectTagging({
|
|
247
|
+
Bucket: this.options.s3Bucket,
|
|
248
|
+
Key: oldRecord[pathColumnName],
|
|
249
|
+
Tagging: {
|
|
250
|
+
TagSet: [
|
|
251
|
+
{
|
|
252
|
+
Key: ADMINFORTH_NOT_YET_USED_TAG,
|
|
253
|
+
Value: 'true'
|
|
254
|
+
}
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
}).promise();
|
|
258
|
+
}
|
|
259
|
+
if (record[virtualColumn.name] !== null) {
|
|
260
|
+
// remove tag from new file
|
|
261
|
+
yield s3.putObjectTagging({
|
|
262
|
+
Bucket: this.options.s3Bucket,
|
|
263
|
+
Key: record[pathColumnName],
|
|
264
|
+
Tagging: {
|
|
265
|
+
TagSet: []
|
|
266
|
+
}
|
|
267
|
+
}).promise();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return { ok: true };
|
|
271
|
+
}));
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
setupEndpoints(server) {
|
|
275
|
+
server.endpoint({
|
|
276
|
+
method: 'POST',
|
|
277
|
+
path: `/plugin/${this.pluginInstanceId}/get_s3_upload_url`,
|
|
278
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body }) {
|
|
279
|
+
const { originalFilename, contentType, size, originalExtension } = body;
|
|
280
|
+
if (this.options.allowedFileExtensions && !this.options.allowedFileExtensions.includes(originalExtension)) {
|
|
281
|
+
throw new Error(`File extension "${originalExtension}" is not allowed, allowed extensions are: ${this.options.allowedFileExtensions.join(', ')}`);
|
|
282
|
+
}
|
|
283
|
+
const s3Path = this.options.s3Path({ originalFilename, originalExtension, contentType });
|
|
284
|
+
if (s3Path.startsWith('/')) {
|
|
285
|
+
throw new Error('s3Path should not start with /, please adjust s3path function to not return / at the start of the path');
|
|
286
|
+
}
|
|
287
|
+
const s3 = new AWS.S3({
|
|
288
|
+
accessKeyId: this.options.s3AccessKeyId,
|
|
289
|
+
secretAccessKey: this.options.s3SecretAccessKey,
|
|
290
|
+
region: this.options.s3Region
|
|
291
|
+
});
|
|
292
|
+
const params = {
|
|
293
|
+
Bucket: this.options.s3Bucket,
|
|
294
|
+
Key: s3Path,
|
|
295
|
+
ContentType: contentType,
|
|
296
|
+
ACL: this.options.s3ACL || 'private',
|
|
297
|
+
Tagging: `${ADMINFORTH_NOT_YET_USED_TAG}=true`,
|
|
298
|
+
};
|
|
299
|
+
const uploadUrl = yield s3.getSignedUrl('putObject', params);
|
|
300
|
+
return {
|
|
301
|
+
uploadUrl,
|
|
302
|
+
s3Path,
|
|
303
|
+
};
|
|
304
|
+
})
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/upload",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"rollout": "tsc && cp -rf custom dist/ && npm version patch && npm publish --access public",
|
|
8
|
-
"postinstall": "npm link adminforth"
|
|
9
|
+
"postinstall": "npm link adminforth",
|
|
10
|
+
"build": "tsc"
|
|
9
11
|
},
|
|
10
12
|
"type": "module",
|
|
11
13
|
"author": "",
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Projects */
|
|
6
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/* Language and Environment */
|
|
15
|
+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
16
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
17
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
18
|
+
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
19
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
20
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
21
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
22
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
23
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
24
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
25
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
26
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
27
|
+
|
|
28
|
+
/* Modules */
|
|
29
|
+
// changed from commmonjs to node16 because The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.
|
|
30
|
+
"module": "node16", /* Specify what module code is generated. */
|
|
31
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
32
|
+
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
33
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
34
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
35
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
36
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
37
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
38
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
39
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
40
|
+
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
41
|
+
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
42
|
+
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
43
|
+
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
44
|
+
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
45
|
+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
46
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
47
|
+
|
|
48
|
+
/* JavaScript Support */
|
|
49
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
50
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
51
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
52
|
+
|
|
53
|
+
/* Emit */
|
|
54
|
+
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
55
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
56
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
57
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
58
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
59
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
60
|
+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
61
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
62
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
63
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
64
|
+
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
65
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
66
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
67
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
68
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
69
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
70
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
71
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
72
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
73
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
74
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
75
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
76
|
+
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
77
|
+
|
|
78
|
+
/* Interop Constraints */
|
|
79
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
80
|
+
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
81
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
82
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
83
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
84
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
85
|
+
|
|
86
|
+
/* Type Checking */
|
|
87
|
+
"strict": false, /* TODO */ /* Enable all strict type-checking options. */
|
|
88
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
89
|
+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
90
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
91
|
+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
92
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
93
|
+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
94
|
+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
95
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
96
|
+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
97
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
98
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
99
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
100
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
101
|
+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
102
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
103
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
104
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
105
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
106
|
+
|
|
107
|
+
/* Completeness */
|
|
108
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
109
|
+
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
|
|
110
|
+
},
|
|
111
|
+
"exclude": ["node_modules", "dist", "custom"], /* Exclude files from compilation. */
|
|
112
|
+
}
|
package/dist/package-lock.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "custom",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"lockfileVersion": 3,
|
|
5
|
-
"requires": true,
|
|
6
|
-
"packages": {
|
|
7
|
-
"": {
|
|
8
|
-
"name": "custom",
|
|
9
|
-
"version": "1.0.0",
|
|
10
|
-
"license": "ISC",
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"medium-zoom": "^1.1.0"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"node_modules/medium-zoom": {
|
|
16
|
-
"version": "1.1.0",
|
|
17
|
-
"resolved": "https://registry.npmjs.org/medium-zoom/-/medium-zoom-1.1.0.tgz",
|
|
18
|
-
"integrity": "sha512-ewyDsp7k4InCUp3jRmwHBRFGyjBimKps/AJLjRSox+2q/2H4p/PNpQf+pwONWlJiOudkBXtbdmVbFjqyybfTmQ=="
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
package/dist/package.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "custom",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [],
|
|
10
|
-
"author": "",
|
|
11
|
-
"license": "ISC",
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"medium-zoom": "^1.1.0"
|
|
14
|
-
}
|
|
15
|
-
}
|
package/dist/preview.vue
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<img v-if="url" :src="url"
|
|
4
|
-
class="rounded-md"
|
|
5
|
-
ref="img"
|
|
6
|
-
data-zoomable
|
|
7
|
-
@click.stop="zoom.open()"
|
|
8
|
-
/>
|
|
9
|
-
</div>
|
|
10
|
-
</template>
|
|
11
|
-
|
|
12
|
-
<style>
|
|
13
|
-
.medium-zoom-image {
|
|
14
|
-
z-index: 999999;
|
|
15
|
-
background: rgba(0, 0, 0, 0.8);
|
|
16
|
-
}
|
|
17
|
-
.medium-zoom-overlay {
|
|
18
|
-
background: rgba(255, 255, 255, 0.8) !important
|
|
19
|
-
}
|
|
20
|
-
body.medium-zoom--opened aside {
|
|
21
|
-
filter: grayscale(1)
|
|
22
|
-
}
|
|
23
|
-
</style>
|
|
24
|
-
|
|
25
|
-
<style scoped>
|
|
26
|
-
img {
|
|
27
|
-
min-width: 200px;
|
|
28
|
-
}
|
|
29
|
-
</style>
|
|
30
|
-
<script setup>
|
|
31
|
-
import { ref, computed , onMounted, watch} from 'vue'
|
|
32
|
-
import mediumZoom from 'medium-zoom'
|
|
33
|
-
|
|
34
|
-
const img = ref(null);
|
|
35
|
-
|
|
36
|
-
const props = defineProps({
|
|
37
|
-
record: Object,
|
|
38
|
-
column: Object,
|
|
39
|
-
meta: Object,
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
const url = computed(() => {
|
|
43
|
-
return props.record[`previewUrl_${props.meta.pluginInstanceId}`];
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const zoom = ref(null);
|
|
47
|
-
|
|
48
|
-
onMounted(() => {
|
|
49
|
-
zoom.value = mediumZoom(img.value, {
|
|
50
|
-
margin: 24,
|
|
51
|
-
// container: '#app',
|
|
52
|
-
});
|
|
53
|
-
console.log('mounted', props.meta)
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
</script>
|
package/dist/uploader.vue
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="flex items-center justify-center w-full">
|
|
3
|
-
<label for="dropzone-file" class="flex flex-col items-center justify-center w-full h-64 border-2 border-gray-300 border-dashed rounded-lg cursor-pointer bg-gray-50 dark:hover:bg-gray-800 dark:bg-gray-700 hover:bg-gray-100 dark:border-gray-600 dark:hover:border-gray-500 dark:hover:bg-gray-600">
|
|
4
|
-
<div class="flex flex-col items-center justify-center pt-5 pb-6">
|
|
5
|
-
<img v-if="imgPreview" :src="imgPreview" class="w-100 mt-4 rounded-lg h-40 object-contain" />
|
|
6
|
-
|
|
7
|
-
<svg v-else class="w-8 h-8 mb-4 text-gray-500 dark:text-gray-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 16">
|
|
8
|
-
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 13h3a3 3 0 0 0 0-6h-.025A5.56 5.56 0 0 0 16 6.5 5.5 5.5 0 0 0 5.207 5.021C5.137 5.017 5.071 5 5 5a4 4 0 0 0 0 8h2.167M10 15V6m0 0L8 8m2-2 2 2"/>
|
|
9
|
-
</svg>
|
|
10
|
-
|
|
11
|
-
<template v-if="!uploaded">
|
|
12
|
-
<p class="mb-2 text-sm text-gray-500 dark:text-gray-400"><span class="font-semibold">Click to upload</span> or drag and drop</p>
|
|
13
|
-
<p class="text-xs text-gray-500 dark:text-gray-400">
|
|
14
|
-
{{ allowedExtensionsLabel }} {{ meta.maxFileSize ? `(up to ${maxFileSizeHumanized})` : '' }}
|
|
15
|
-
</p>
|
|
16
|
-
</template>
|
|
17
|
-
|
|
18
|
-
<div class="w-full bg-gray-200 rounded-full dark:bg-gray-700 mt-1 mb-2" v-if="progress > 0 && !uploaded">
|
|
19
|
-
<div class="bg-blue-600 text-xs font-medium text-blue-100 text-center p-0.5 leading-none rounded-full"
|
|
20
|
-
:style="{width: `${progress}%`}">{{ progress }}%
|
|
21
|
-
</div>
|
|
22
|
-
</div>
|
|
23
|
-
|
|
24
|
-
<div v-else-if="uploaded" class="flex items-center justify-center w-full mt-1">
|
|
25
|
-
<svg class="w-4 h-4 text-green-600 dark:text-green-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
|
26
|
-
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
|
|
27
|
-
</svg>
|
|
28
|
-
<p class="ml-2 text-sm text-green-600 dark:text-green-400">File uploaded</p>
|
|
29
|
-
</div>
|
|
30
|
-
</div>
|
|
31
|
-
<input id="dropzone-file" type="file" class="hidden" @change="onFileChange" />
|
|
32
|
-
</label>
|
|
33
|
-
</div>
|
|
34
|
-
|
|
35
|
-
</template>
|
|
36
|
-
|
|
37
|
-
<script setup>
|
|
38
|
-
import { computed, ref } from 'vue'
|
|
39
|
-
import { callAdminForthApi } from '@/utils'
|
|
40
|
-
|
|
41
|
-
const props = defineProps({
|
|
42
|
-
meta: String
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const emit = defineEmits(['update:value']);
|
|
46
|
-
|
|
47
|
-
const imgPreview = ref(null);
|
|
48
|
-
const progress = ref(0);
|
|
49
|
-
|
|
50
|
-
const uploadedPath = ref(null);
|
|
51
|
-
const uploaded = ref(false);
|
|
52
|
-
|
|
53
|
-
const allowedExtensionsLabel = computed(() => {
|
|
54
|
-
const allowedExtensions = props.meta.allowedExtensions || []
|
|
55
|
-
if (allowedExtensions.length === 0) {
|
|
56
|
-
return 'Any file type'
|
|
57
|
-
}
|
|
58
|
-
// make upper case and write in format EXT1, EXT2 or EXT3
|
|
59
|
-
let label = allowedExtensions.map(ext => ext.toUpperCase()).join(', ');
|
|
60
|
-
// last comma to 'or'
|
|
61
|
-
label = label.replace(/,([^,]*)$/, ' or$1')
|
|
62
|
-
return label
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const maxFileSizeHumanized = computed(() => {
|
|
66
|
-
let maxFileSize = props.meta.maxFileSize || 0
|
|
67
|
-
if (maxFileSize === 0) {
|
|
68
|
-
return ''
|
|
69
|
-
}
|
|
70
|
-
// if maxFileSize is in bytes, convert to KB, MB, GB, TB
|
|
71
|
-
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
|
72
|
-
let i = 0
|
|
73
|
-
while (maxFileSize >= 1024 && i < units.length - 1) {
|
|
74
|
-
maxFileSize /= 1024
|
|
75
|
-
i++
|
|
76
|
-
}
|
|
77
|
-
return `${maxFileSize.toFixed(2)} ${units[i]}`
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
const onFileChange = async (e) => {
|
|
81
|
-
const file = e.target.files[0]
|
|
82
|
-
if (!file) {
|
|
83
|
-
imgPreview.value = null;
|
|
84
|
-
progress.value = 0;
|
|
85
|
-
uploaded.value = false;
|
|
86
|
-
return
|
|
87
|
-
}
|
|
88
|
-
console.log('File selected:', file);
|
|
89
|
-
|
|
90
|
-
// get filename, extension, size, mimeType
|
|
91
|
-
const { name, size, type } = file;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const extension = name.split('.').pop();
|
|
95
|
-
console.log('File details:', { name, extension, size, type });
|
|
96
|
-
// validate file extension
|
|
97
|
-
const allowedExtensions = props.meta.allowedExtensions || []
|
|
98
|
-
if (allowedExtensions.length > 0 && !allowedExtensions.includes(extension)) {
|
|
99
|
-
window.adminforth.alert({
|
|
100
|
-
message: `Sorry but the file type ${extension} is not allowed. Please upload a file with one of the following extensions: ${allowedExtensionsLabel.value}`,
|
|
101
|
-
variant: 'danger'
|
|
102
|
-
});
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// validate file size
|
|
107
|
-
if (props.meta.maxFileSize && size > props.meta.maxFileSize) {
|
|
108
|
-
window.adminforth.alert({
|
|
109
|
-
message: `Sorry but the file size is too large. Please upload a file with a maximum size of ${maxFileSizeHumanized.value}`,
|
|
110
|
-
variant: 'danger'
|
|
111
|
-
});
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
// supports preview
|
|
115
|
-
if (type.startsWith('image/')) {
|
|
116
|
-
const reader = new FileReader();
|
|
117
|
-
reader.onload = (e) => {
|
|
118
|
-
imgPreview.value = e.target.result;
|
|
119
|
-
}
|
|
120
|
-
reader.readAsDataURL(file);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const { uploadUrl, previewUrl, s3Path } = await callAdminForthApi({
|
|
124
|
-
path: `/plugin/${props.meta.pluginInstanceId}/get_s3_upload_url`,
|
|
125
|
-
method: 'POST',
|
|
126
|
-
body: {
|
|
127
|
-
originalFilename: name,
|
|
128
|
-
contentType: type,
|
|
129
|
-
size,
|
|
130
|
-
originalExtension: extension,
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
console.log('S3 upload URL:', uploadUrl);
|
|
135
|
-
|
|
136
|
-
const xhr = new XMLHttpRequest();
|
|
137
|
-
const success = await new Promise((resolve) => {
|
|
138
|
-
xhr.upload.onprogress = (e) => {
|
|
139
|
-
if (e.lengthComputable) {
|
|
140
|
-
progress.value = Math.round((e.loaded / e.total) * 100);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
xhr.addEventListener('loadend', () => {
|
|
144
|
-
resolve(xhr.readyState === 4 && xhr.status === 200);
|
|
145
|
-
});
|
|
146
|
-
xhr.open('PUT', uploadUrl, true);
|
|
147
|
-
xhr.setRequestHeader('Content-Type', type);
|
|
148
|
-
xhr.send(file);
|
|
149
|
-
});
|
|
150
|
-
if (!success) {
|
|
151
|
-
window.adminforth.alert({
|
|
152
|
-
message: 'Sorry but the file was not be uploaded. Please try again.',
|
|
153
|
-
variant: 'danger'
|
|
154
|
-
});
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
uploaded.value = true;
|
|
158
|
-
emit('update:value', s3Path);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
</script>
|