@adminforth/upload 2.3.6 → 2.3.8

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 CHANGED
@@ -11,5 +11,5 @@ custom/preview.vue
11
11
  custom/tsconfig.json
12
12
  custom/uploader.vue
13
13
 
14
- sent 46,940 bytes received 134 bytes 94,148.00 bytes/sec
15
- total size is 46,465 speedup is 0.99
14
+ sent 46,937 bytes received 134 bytes 94,142.00 bytes/sec
15
+ total size is 46,455 speedup is 0.99
@@ -1,19 +1,27 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "baseUrl": ".", // This should point to your project root
3
+ "baseUrl": ".",
4
4
  "paths": {
5
5
  "@/*": [
6
- // "node_modules/adminforth/dist/spa/src/*"
7
- "../../../spa/src/*"
6
+ "../../../adminforth/spa/src/*"
8
7
  ],
9
8
  "*": [
10
- // "node_modules/adminforth/dist/spa/node_modules/*"
11
- "../../../spa/node_modules/*"
9
+ "../../../adminforth/spa/node_modules/*"
12
10
  ],
13
11
  "@@/*": [
14
- // "node_modules/adminforth/dist/spa/src/*"
15
12
  "."
16
13
  ]
17
14
  }
18
- }
15
+ },
16
+ "include": [
17
+ "./**/*.ts",
18
+ "./**/*.tsx",
19
+ "./**/*.vue",
20
+ "../**/*.ts",
21
+ "../**/*.tsx",
22
+ "../**/*.vue",
23
+ "../*.vue",
24
+ "../*.ts",
25
+ "../*.tsx"
26
+ ]
19
27
  }
@@ -1,19 +1,27 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "baseUrl": ".", // This should point to your project root
3
+ "baseUrl": ".",
4
4
  "paths": {
5
5
  "@/*": [
6
- // "node_modules/adminforth/dist/spa/src/*"
7
- "../../../spa/src/*"
6
+ "../../../adminforth/spa/src/*"
8
7
  ],
9
8
  "*": [
10
- // "node_modules/adminforth/dist/spa/node_modules/*"
11
- "../../../spa/node_modules/*"
9
+ "../../../adminforth/spa/node_modules/*"
12
10
  ],
13
11
  "@@/*": [
14
- // "node_modules/adminforth/dist/spa/src/*"
15
12
  "."
16
13
  ]
17
14
  }
18
- }
15
+ },
16
+ "include": [
17
+ "./**/*.ts",
18
+ "./**/*.tsx",
19
+ "./**/*.vue",
20
+ "../**/*.ts",
21
+ "../**/*.tsx",
22
+ "../**/*.vue",
23
+ "../*.vue",
24
+ "../*.ts",
25
+ "../*.tsx"
26
+ ]
19
27
  }
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,39 +101,27 @@ export default class UploadPlugin extends AdminForthPlugin {
122
101
  meta: pluginFrontendOptions,
123
102
  };
124
103
  }
125
- // insert virtual column after path column if it is not already there
126
- const virtualColumnIndex = resourceConfig.columns.findIndex((column) => column.name === virtualColumn.name);
127
- if (virtualColumnIndex === -1) {
128
- resourceConfig.columns.splice(pathColumnIndex + 1, 0, virtualColumn);
129
- }
130
- // if showIn of path column has 'create' or 'edit' remove it but use it for virtual column
131
- if (pathColumn.showIn && (pathColumn.showIn.create !== undefined)) {
132
- virtualColumn.showIn = Object.assign(Object.assign({}, virtualColumn.showIn), { create: pathColumn.showIn.create });
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);
154
116
  if (record[pathColumnName]) {
155
117
  process.env.HEAVY_DEBUG && console.log('🪥🪥 remove ObjectTagging', record[pathColumnName]);
156
118
  // let it crash if it fails: this is a new file which just was uploaded.
157
- yield this.options.storageAdapter.markKeyForNotDeletation(record[pathColumnName]);
119
+ if (this.options.storageAdapter.markKeyForNotDeletion !== undefined) {
120
+ yield this.options.storageAdapter.markKeyForNotDeletion(record[pathColumnName]);
121
+ }
122
+ else {
123
+ yield this.options.storageAdapter.markKeyForNotDeletation(record[pathColumnName]);
124
+ }
158
125
  }
159
126
  return { ok: true };
160
127
  }));
@@ -188,7 +155,12 @@ export default class UploadPlugin extends AdminForthPlugin {
188
155
  resourceConfig.hooks.delete.afterSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ record }) {
189
156
  if (record[pathColumnName]) {
190
157
  try {
191
- yield this.options.storageAdapter.markKeyForDeletation(record[pathColumnName]);
158
+ if (this.options.storageAdapter.markKeyForDeletion !== undefined) {
159
+ yield this.options.storageAdapter.markKeyForDeletion(record[pathColumnName]);
160
+ }
161
+ else {
162
+ yield this.options.storageAdapter.markKeyForDeletation(record[pathColumnName]);
163
+ }
192
164
  }
193
165
  catch (e) {
194
166
  // file might be e.g. already deleted, so we catch error
@@ -198,31 +170,33 @@ export default class UploadPlugin extends AdminForthPlugin {
198
170
  return { ok: true };
199
171
  }));
200
172
  // ** 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
173
  // add edit postSave hook to delete old file and remove tag from new file
210
174
  resourceConfig.hooks.edit.afterSave.push((_a) => __awaiter(this, [_a], void 0, function* ({ updates, oldRecord }) {
211
- if (updates[virtualColumn.name] || updates[virtualColumn.name] === null) {
175
+ if (updates[pathColumnName] || updates[pathColumnName] === null) {
212
176
  if (oldRecord[pathColumnName]) {
213
177
  // put tag to delete old file
214
178
  try {
215
- yield this.options.storageAdapter.markKeyForDeletation(oldRecord[pathColumnName]);
179
+ if (this.options.storageAdapter.markKeyForDeletion !== undefined) {
180
+ yield this.options.storageAdapter.markKeyForDeletion(oldRecord[pathColumnName]);
181
+ }
182
+ else {
183
+ yield this.options.storageAdapter.markKeyForDeletation(oldRecord[pathColumnName]);
184
+ }
216
185
  }
217
186
  catch (e) {
218
187
  // file might be e.g. already deleted, so we catch error
219
188
  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
189
  }
221
190
  }
222
- if (updates[virtualColumn.name] !== null) {
191
+ if (updates[pathColumnName] !== null) {
223
192
  // remove tag from new file
224
193
  // in this case we let it crash if it fails: this is a new file which just was uploaded.
225
- yield this.options.storageAdapter.markKeyForNotDeletation(updates[pathColumnName]);
194
+ if (this.options.storageAdapter.markKeyForNotDeletion !== undefined) {
195
+ yield this.options.storageAdapter.markKeyForNotDeletion(updates[pathColumnName]);
196
+ }
197
+ else {
198
+ yield this.options.storageAdapter.markKeyForNotDeletation(updates[pathColumnName]);
199
+ }
226
200
  }
227
201
  }
228
202
  return { ok: true };
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
- // insert virtual column after path column if it is not already there
134
- const virtualColumnIndex = resourceConfig.columns.findIndex((column: any) => column.name === virtualColumn.name);
135
- if (virtualColumnIndex === -1) {
136
- resourceConfig.columns.splice(pathColumnIndex + 1, 0, virtualColumn);
111
+ resourceConfig.columns[pathColumnIndex].components.create = {
112
+ file: this.componentPath('uploader.vue'),
113
+ meta: pluginFrontendOptions,
137
114
  }
138
115
 
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 };
116
+ resourceConfig.columns[pathColumnIndex].components.edit = {
117
+ file: this.componentPath('uploader.vue'),
118
+ meta: pluginFrontendOptions,
144
119
  }
145
120
 
146
- if (pathColumn.showIn && (pathColumn.showIn.edit !== undefined)) {
147
- virtualColumn.showIn = { ...virtualColumn.showIn, edit: pathColumn.showIn.edit };
148
- pathColumn.showIn = { ...pathColumn.showIn, edit: false };
149
- }
150
-
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 }) => {
@@ -170,7 +128,11 @@ export default class UploadPlugin extends AdminForthPlugin {
170
128
  if (record[pathColumnName]) {
171
129
  process.env.HEAVY_DEBUG && console.log('🪥🪥 remove ObjectTagging', record[pathColumnName]);
172
130
  // let it crash if it fails: this is a new file which just was uploaded.
173
- await this.options.storageAdapter.markKeyForNotDeletation(record[pathColumnName]);
131
+ if (this.options.storageAdapter.markKeyForNotDeletion !== undefined) {
132
+ await this.options.storageAdapter.markKeyForNotDeletion(record[pathColumnName]);
133
+ } else {
134
+ await this.options.storageAdapter.markKeyForNotDeletation(record[pathColumnName]);
135
+ }
174
136
  }
175
137
  return { ok: true };
176
138
  });
@@ -213,7 +175,11 @@ export default class UploadPlugin extends AdminForthPlugin {
213
175
  resourceConfig.hooks.delete.afterSave.push(async ({ record }: { record: any }) => {
214
176
  if (record[pathColumnName]) {
215
177
  try {
216
- await this.options.storageAdapter.markKeyForDeletation(record[pathColumnName]);
178
+ if (this.options.storageAdapter.markKeyForDeletion !== undefined) {
179
+ await this.options.storageAdapter.markKeyForDeletion(record[pathColumnName]);
180
+ } else {
181
+ await this.options.storageAdapter.markKeyForDeletation(record[pathColumnName]);
182
+ }
217
183
  } catch (e) {
218
184
  // file might be e.g. already deleted, so we catch error
219
185
  console.error(`Error setting tag ${ADMINFORTH_NOT_YET_USED_TAG} to true for object ${record[pathColumnName]}. File will not be auto-cleaned up`, e);
@@ -225,34 +191,34 @@ export default class UploadPlugin extends AdminForthPlugin {
225
191
 
226
192
  // ** HOOKS FOR EDIT **//
227
193
 
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
194
 
237
195
 
238
196
  // add edit postSave hook to delete old file and remove tag from new file
239
197
  resourceConfig.hooks.edit.afterSave.push(async ({ updates, oldRecord }: { updates: any, oldRecord: any }) => {
240
198
 
241
- if (updates[virtualColumn.name] || updates[virtualColumn.name] === null) {
199
+ if (updates[pathColumnName] || updates[pathColumnName] === null) {
242
200
  if (oldRecord[pathColumnName]) {
243
201
  // put tag to delete old file
244
202
  try {
245
- await this.options.storageAdapter.markKeyForDeletation(oldRecord[pathColumnName]);
203
+ if (this.options.storageAdapter.markKeyForDeletion !== undefined) {
204
+ await this.options.storageAdapter.markKeyForDeletion(oldRecord[pathColumnName]);
205
+ } else {
206
+ await this.options.storageAdapter.markKeyForDeletation(oldRecord[pathColumnName]);
207
+ }
246
208
  } catch (e) {
247
209
  // file might be e.g. already deleted, so we catch error
248
210
  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
211
  }
250
212
  }
251
- if (updates[virtualColumn.name] !== null) {
213
+ if (updates[pathColumnName] !== null) {
252
214
  // remove tag from new file
253
215
  // in this case we let it crash if it fails: this is a new file which just was uploaded.
216
+ if (this.options.storageAdapter.markKeyForNotDeletion !== undefined) {
217
+ await this.options.storageAdapter.markKeyForNotDeletion(updates[pathColumnName]);
218
+ } else {
254
219
  await this.options.storageAdapter.markKeyForNotDeletation(updates[pathColumnName]);
255
220
  }
221
+ }
256
222
  }
257
223
  return { ok: true };
258
224
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/upload",
3
- "version": "2.3.6",
3
+ "version": "2.3.8",
4
4
  "description": "Plugin for uploading files for adminforth",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "@aws-sdk/client-s3": "^3.629.0",
24
24
  "@aws-sdk/s3-request-presigner": "^3.629.0",
25
- "adminforth": "^2.4.0-next.237"
25
+ "adminforth": "^2.4.0-next.315"
26
26
  },
27
27
  "keywords": [
28
28
  "adminforth",