@adminforth/upload 2.15.0 → 2.15.2

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.
Files changed (3) hide show
  1. package/dist/index.js +15 -1
  2. package/index.ts +14 -2
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -40,7 +40,13 @@ export default class UploadPlugin extends AdminForthPlugin {
40
40
  const pkName = (_a = this.resourceConfig.columns.find((column) => column.primaryKey)) === null || _a === void 0 ? void 0 : _a.name;
41
41
  record = yield this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ(pkName, recordPk)]);
42
42
  }
43
- const filePath = this.options.filePath({ originalFilename, originalExtension, contentType, record });
43
+ const sanitizeFileName = (name) => {
44
+ return name
45
+ .normalize("NFKD")
46
+ .replace(/[^a-zA-Z0-9._-]/g, "_");
47
+ };
48
+ const fileName = sanitizeFileName(originalFilename);
49
+ const filePath = this.options.filePath({ originalFilename: fileName, originalExtension, contentType, record });
44
50
  if (filePath.startsWith('/')) {
45
51
  throw new Error('s3Path should not start with /, please adjust s3path function to not return / at the start of the path');
46
52
  }
@@ -136,9 +142,17 @@ export default class UploadPlugin extends AdminForthPlugin {
136
142
  ;
137
143
  isInternalUrl(url) {
138
144
  return __awaiter(this, void 0, void 0, function* () {
145
+ var _a;
139
146
  const adapter = this.options.storageAdapter;
140
147
  if (adapter && typeof adapter.isInternalUrl === 'function') {
141
148
  try {
149
+ if ((_a = this.options.preview) === null || _a === void 0 ? void 0 : _a.previewUrl) {
150
+ const previewUrl = this.options.preview.previewUrl({ filePath: 'test_filepath' });
151
+ if (url.startsWith(previewUrl.replace('test_filepath', ''))) {
152
+ return true;
153
+ }
154
+ return false;
155
+ }
142
156
  return yield adapter.isInternalUrl(url);
143
157
  }
144
158
  catch (err) {
package/index.ts CHANGED
@@ -60,7 +60,13 @@ export default class UploadPlugin extends AdminForthPlugin {
60
60
  )
61
61
  }
62
62
 
63
- const filePath: string = this.options.filePath({ originalFilename, originalExtension, contentType, record });
63
+ const sanitizeFileName = (name) => {
64
+ return name
65
+ .normalize("NFKD")
66
+ .replace(/[^a-zA-Z0-9._-]/g, "_")
67
+ }
68
+ const fileName = sanitizeFileName(originalFilename);
69
+ const filePath: string = this.options.filePath({ originalFilename: fileName, originalExtension, contentType, record });
64
70
  if (filePath.startsWith('/')) {
65
71
  throw new Error('s3Path should not start with /, please adjust s3path function to not return / at the start of the path');
66
72
  }
@@ -164,9 +170,15 @@ export default class UploadPlugin extends AdminForthPlugin {
164
170
 
165
171
  async isInternalUrl(url: string): Promise<boolean> {
166
172
  const adapter = this.options.storageAdapter as any;
167
-
168
173
  if (adapter && typeof adapter.isInternalUrl === 'function') {
169
174
  try {
175
+ if(this.options.preview?.previewUrl) {
176
+ const previewUrl = this.options.preview.previewUrl({ filePath: 'test_filepath' });
177
+ if (url.startsWith(previewUrl.replace('test_filepath', ''))) {
178
+ return true;
179
+ }
180
+ return false;
181
+ }
170
182
  return await adapter.isInternalUrl(url);
171
183
  } catch (err) {
172
184
  console.error(`[UploadPlugin] Error calling isInternalUrl on adapter:`, err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/upload",
3
- "version": "2.15.0",
3
+ "version": "2.15.2",
4
4
  "description": "Plugin for uploading files for adminforth",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",