@adminforth/upload 2.3.6 β 2.3.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/build.log +2 -2
- package/custom/tsconfig.json +14 -3
- package/dist/custom/tsconfig.json +14 -3
- package/dist/index.js +10 -56
- package/index.ts +8 -58
- package/package.json +1 -1
package/build.log
CHANGED
|
@@ -11,5 +11,5 @@ custom/preview.vue
|
|
|
11
11
|
custom/tsconfig.json
|
|
12
12
|
custom/uploader.vue
|
|
13
13
|
|
|
14
|
-
sent
|
|
15
|
-
total size is 46,
|
|
14
|
+
sent 47,144 bytes received 134 bytes 94,556.00 bytes/sec
|
|
15
|
+
total size is 46,662 speedup is 0.99
|
package/custom/tsconfig.json
CHANGED
|
@@ -4,16 +4,27 @@
|
|
|
4
4
|
"paths": {
|
|
5
5
|
"@/*": [
|
|
6
6
|
// "node_modules/adminforth/dist/spa/src/*"
|
|
7
|
-
"../../../spa/src/*"
|
|
7
|
+
"../../../adminforth/spa/src/*"
|
|
8
8
|
],
|
|
9
9
|
"*": [
|
|
10
10
|
// "node_modules/adminforth/dist/spa/node_modules/*"
|
|
11
|
-
"../../../spa/node_modules/*"
|
|
11
|
+
"../../../adminforth/spa/node_modules/*"
|
|
12
12
|
],
|
|
13
13
|
"@@/*": [
|
|
14
14
|
// "node_modules/adminforth/dist/spa/src/*"
|
|
15
15
|
"."
|
|
16
16
|
]
|
|
17
17
|
}
|
|
18
|
-
}
|
|
18
|
+
},
|
|
19
|
+
"include": [
|
|
20
|
+
"./**/*.ts",
|
|
21
|
+
"./**/*.tsx",
|
|
22
|
+
"./**/*.vue",
|
|
23
|
+
"../**/*.ts",
|
|
24
|
+
"../**/*.tsx",
|
|
25
|
+
"../**/*.vue",
|
|
26
|
+
"../*.vue",
|
|
27
|
+
"../*.ts",
|
|
28
|
+
"../*.tsx"
|
|
29
|
+
]
|
|
19
30
|
}
|
|
@@ -4,16 +4,27 @@
|
|
|
4
4
|
"paths": {
|
|
5
5
|
"@/*": [
|
|
6
6
|
// "node_modules/adminforth/dist/spa/src/*"
|
|
7
|
-
"../../../spa/src/*"
|
|
7
|
+
"../../../adminforth/spa/src/*"
|
|
8
8
|
],
|
|
9
9
|
"*": [
|
|
10
10
|
// "node_modules/adminforth/dist/spa/node_modules/*"
|
|
11
|
-
"../../../spa/node_modules/*"
|
|
11
|
+
"../../../adminforth/spa/node_modules/*"
|
|
12
12
|
],
|
|
13
13
|
"@@/*": [
|
|
14
14
|
// "node_modules/adminforth/dist/spa/src/*"
|
|
15
15
|
"."
|
|
16
16
|
]
|
|
17
17
|
}
|
|
18
|
-
}
|
|
18
|
+
},
|
|
19
|
+
"include": [
|
|
20
|
+
"./**/*.ts",
|
|
21
|
+
"./**/*.tsx",
|
|
22
|
+
"./**/*.vue",
|
|
23
|
+
"../**/*.ts",
|
|
24
|
+
"../**/*.tsx",
|
|
25
|
+
"../**/*.vue",
|
|
26
|
+
"../*.vue",
|
|
27
|
+
"../*.ts",
|
|
28
|
+
"../*.tsx"
|
|
29
|
+
]
|
|
19
30
|
}
|
package/dist/index.js
CHANGED
|
@@ -86,27 +86,6 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
86
86
|
};
|
|
87
87
|
// define components which will be imported from other components
|
|
88
88
|
this.componentPath('imageGenerator.vue');
|
|
89
|
-
const virtualColumn = {
|
|
90
|
-
virtual: true,
|
|
91
|
-
name: `uploader_${this.pluginInstanceId}`,
|
|
92
|
-
components: {
|
|
93
|
-
edit: {
|
|
94
|
-
file: this.componentPath('uploader.vue'),
|
|
95
|
-
meta: pluginFrontendOptions,
|
|
96
|
-
},
|
|
97
|
-
create: {
|
|
98
|
-
file: this.componentPath('uploader.vue'),
|
|
99
|
-
meta: pluginFrontendOptions,
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
showIn: {
|
|
103
|
-
create: true,
|
|
104
|
-
edit: true,
|
|
105
|
-
list: false,
|
|
106
|
-
show: false,
|
|
107
|
-
filter: false,
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
89
|
if (!resourceConfig.columns[pathColumnIndex].components) {
|
|
111
90
|
resourceConfig.columns[pathColumnIndex].components = {};
|
|
112
91
|
}
|
|
@@ -122,32 +101,15 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
122
101
|
meta: pluginFrontendOptions,
|
|
123
102
|
};
|
|
124
103
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
pathColumn.showIn = Object.assign(Object.assign({}, pathColumn.showIn), { create: false });
|
|
134
|
-
}
|
|
135
|
-
if (pathColumn.showIn && (pathColumn.showIn.edit !== undefined)) {
|
|
136
|
-
virtualColumn.showIn = Object.assign(Object.assign({}, virtualColumn.showIn), { edit: pathColumn.showIn.edit });
|
|
137
|
-
pathColumn.showIn = Object.assign(Object.assign({}, pathColumn.showIn), { edit: false });
|
|
138
|
-
}
|
|
139
|
-
virtualColumn.required = pathColumn.required;
|
|
140
|
-
virtualColumn.label = pathColumn.label;
|
|
141
|
-
virtualColumn.editingNote = pathColumn.editingNote;
|
|
104
|
+
resourceConfig.columns[pathColumnIndex].components.create = {
|
|
105
|
+
file: this.componentPath('uploader.vue'),
|
|
106
|
+
meta: pluginFrontendOptions,
|
|
107
|
+
};
|
|
108
|
+
resourceConfig.columns[pathColumnIndex].components.edit = {
|
|
109
|
+
file: this.componentPath('uploader.vue'),
|
|
110
|
+
meta: pluginFrontendOptions,
|
|
111
|
+
};
|
|
142
112
|
// ** HOOKS FOR CREATE **//
|
|
143
|
-
// add beforeSave hook to save virtual column to path column
|
|
144
|
-
resourceConfig.hooks.create.beforeSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ record }) {
|
|
145
|
-
if (record[virtualColumn.name]) {
|
|
146
|
-
record[pathColumnName] = record[virtualColumn.name];
|
|
147
|
-
delete record[virtualColumn.name];
|
|
148
|
-
}
|
|
149
|
-
return { ok: true };
|
|
150
|
-
}));
|
|
151
113
|
// in afterSave hook, aremove tag adminforth-not-yet-used from the file
|
|
152
114
|
resourceConfig.hooks.create.afterSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ record }) {
|
|
153
115
|
process.env.HEAVY_DEBUG && console.log('πΎπΎ after save ', record === null || record === void 0 ? void 0 : record.id);
|
|
@@ -198,17 +160,9 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
198
160
|
return { ok: true };
|
|
199
161
|
}));
|
|
200
162
|
// ** HOOKS FOR EDIT **//
|
|
201
|
-
// beforeSave
|
|
202
|
-
resourceConfig.hooks.edit.beforeSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ record }) {
|
|
203
|
-
// null is when value is removed
|
|
204
|
-
if (record[virtualColumn.name] || record[virtualColumn.name] === null) {
|
|
205
|
-
record[pathColumnName] = record[virtualColumn.name];
|
|
206
|
-
}
|
|
207
|
-
return { ok: true };
|
|
208
|
-
}));
|
|
209
163
|
// add edit postSave hook to delete old file and remove tag from new file
|
|
210
164
|
resourceConfig.hooks.edit.afterSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ updates, oldRecord }) {
|
|
211
|
-
if (updates[
|
|
165
|
+
if (updates[pathColumnName] || updates[pathColumnName] === null) {
|
|
212
166
|
if (oldRecord[pathColumnName]) {
|
|
213
167
|
// put tag to delete old file
|
|
214
168
|
try {
|
|
@@ -219,7 +173,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
219
173
|
console.error(`Error setting tag ${ADMINFORTH_NOT_YET_USED_TAG} to true for object ${oldRecord[pathColumnName]}. File will not be auto-cleaned up`, e);
|
|
220
174
|
}
|
|
221
175
|
}
|
|
222
|
-
if (updates[
|
|
176
|
+
if (updates[pathColumnName] !== null) {
|
|
223
177
|
// remove tag from new file
|
|
224
178
|
// in this case we let it crash if it fails: this is a new file which just was uploaded.
|
|
225
179
|
yield this.options.storageAdapter.markKeyForNotDeletation(updates[pathColumnName]);
|
package/index.ts
CHANGED
|
@@ -90,28 +90,6 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
90
90
|
// define components which will be imported from other components
|
|
91
91
|
this.componentPath('imageGenerator.vue');
|
|
92
92
|
|
|
93
|
-
const virtualColumn: AdminForthResourceColumn = {
|
|
94
|
-
virtual: true,
|
|
95
|
-
name: `uploader_${this.pluginInstanceId}`,
|
|
96
|
-
components: {
|
|
97
|
-
edit: {
|
|
98
|
-
file: this.componentPath('uploader.vue'),
|
|
99
|
-
meta: pluginFrontendOptions,
|
|
100
|
-
},
|
|
101
|
-
create: {
|
|
102
|
-
file: this.componentPath('uploader.vue'),
|
|
103
|
-
meta: pluginFrontendOptions,
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
showIn: {
|
|
107
|
-
create: true,
|
|
108
|
-
edit: true,
|
|
109
|
-
list: false,
|
|
110
|
-
show: false,
|
|
111
|
-
filter: false,
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
|
|
115
93
|
if (!resourceConfig.columns[pathColumnIndex].components) {
|
|
116
94
|
resourceConfig.columns[pathColumnIndex].components = {};
|
|
117
95
|
}
|
|
@@ -130,38 +108,18 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
130
108
|
};
|
|
131
109
|
}
|
|
132
110
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
resourceConfig.columns.splice(pathColumnIndex + 1, 0, virtualColumn);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
// if showIn of path column has 'create' or 'edit' remove it but use it for virtual column
|
|
141
|
-
if (pathColumn.showIn && (pathColumn.showIn.create !== undefined)) {
|
|
142
|
-
virtualColumn.showIn = { ...virtualColumn.showIn, create: pathColumn.showIn.create };
|
|
143
|
-
pathColumn.showIn = { ...pathColumn.showIn, create: false };
|
|
111
|
+
resourceConfig.columns[pathColumnIndex].components.create = {
|
|
112
|
+
file: this.componentPath('uploader.vue'),
|
|
113
|
+
meta: pluginFrontendOptions,
|
|
144
114
|
}
|
|
145
115
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
116
|
+
resourceConfig.columns[pathColumnIndex].components.edit = {
|
|
117
|
+
file: this.componentPath('uploader.vue'),
|
|
118
|
+
meta: pluginFrontendOptions,
|
|
149
119
|
}
|
|
150
120
|
|
|
151
|
-
virtualColumn.required = pathColumn.required;
|
|
152
|
-
virtualColumn.label = pathColumn.label;
|
|
153
|
-
virtualColumn.editingNote = pathColumn.editingNote;
|
|
154
|
-
|
|
155
121
|
// ** HOOKS FOR CREATE **//
|
|
156
122
|
|
|
157
|
-
// add beforeSave hook to save virtual column to path column
|
|
158
|
-
resourceConfig.hooks.create.beforeSave.push(async ({ record }: { record: any }) => {
|
|
159
|
-
if (record[virtualColumn.name]) {
|
|
160
|
-
record[pathColumnName] = record[virtualColumn.name];
|
|
161
|
-
delete record[virtualColumn.name];
|
|
162
|
-
}
|
|
163
|
-
return { ok: true };
|
|
164
|
-
});
|
|
165
123
|
|
|
166
124
|
// in afterSave hook, aremove tag adminforth-not-yet-used from the file
|
|
167
125
|
resourceConfig.hooks.create.afterSave.push(async ({ record }: { record: any }) => {
|
|
@@ -225,20 +183,12 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
225
183
|
|
|
226
184
|
// ** HOOKS FOR EDIT **//
|
|
227
185
|
|
|
228
|
-
// beforeSave
|
|
229
|
-
resourceConfig.hooks.edit.beforeSave.push(async ({ record }: { record: any }) => {
|
|
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
186
|
|
|
237
187
|
|
|
238
188
|
// add edit postSave hook to delete old file and remove tag from new file
|
|
239
189
|
resourceConfig.hooks.edit.afterSave.push(async ({ updates, oldRecord }: { updates: any, oldRecord: any }) => {
|
|
240
190
|
|
|
241
|
-
if (updates[
|
|
191
|
+
if (updates[pathColumnName] || updates[pathColumnName] === null) {
|
|
242
192
|
if (oldRecord[pathColumnName]) {
|
|
243
193
|
// put tag to delete old file
|
|
244
194
|
try {
|
|
@@ -248,7 +198,7 @@ export default class UploadPlugin extends AdminForthPlugin {
|
|
|
248
198
|
console.error(`Error setting tag ${ADMINFORTH_NOT_YET_USED_TAG} to true for object ${oldRecord[pathColumnName]}. File will not be auto-cleaned up`, e);
|
|
249
199
|
}
|
|
250
200
|
}
|
|
251
|
-
if (updates[
|
|
201
|
+
if (updates[pathColumnName] !== null) {
|
|
252
202
|
// remove tag from new file
|
|
253
203
|
// in this case we let it crash if it fails: this is a new file which just was uploaded.
|
|
254
204
|
await this.options.storageAdapter.markKeyForNotDeletation(updates[pathColumnName]);
|