@adminforth/upload 2.14.5 → 2.15.1

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 +26 -0
  2. package/index.ts +22 -0
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -134,6 +134,32 @@ export default class UploadPlugin extends AdminForthPlugin {
134
134
  });
135
135
  }
136
136
  ;
137
+ isInternalUrl(url) {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ var _a;
140
+ const adapter = this.options.storageAdapter;
141
+ if (adapter && typeof adapter.isInternalUrl === 'function') {
142
+ try {
143
+ if ((_a = this.options.preview) === null || _a === void 0 ? void 0 : _a.previewUrl) {
144
+ const previewUrl = this.options.preview.previewUrl({ filePath: 'test_filepath' });
145
+ if (url.startsWith(previewUrl.replace('test_filepath', ''))) {
146
+ return true;
147
+ }
148
+ return false;
149
+ }
150
+ return yield adapter.isInternalUrl(url);
151
+ }
152
+ catch (err) {
153
+ console.error(`[UploadPlugin] Error calling isInternalUrl on adapter:`, err);
154
+ return false;
155
+ }
156
+ }
157
+ else {
158
+ throw new Error('Plese update storage adapter');
159
+ }
160
+ return false;
161
+ });
162
+ }
137
163
  instanceUniqueRepresentation(pluginOptions) {
138
164
  return `${pluginOptions.pathColumnName}`;
139
165
  }
package/index.ts CHANGED
@@ -162,6 +162,28 @@ export default class UploadPlugin extends AdminForthPlugin {
162
162
  return { ok: true };
163
163
  };
164
164
 
165
+ async isInternalUrl(url: string): Promise<boolean> {
166
+ const adapter = this.options.storageAdapter as any;
167
+ if (adapter && typeof adapter.isInternalUrl === 'function') {
168
+ try {
169
+ if(this.options.preview?.previewUrl) {
170
+ const previewUrl = this.options.preview.previewUrl({ filePath: 'test_filepath' });
171
+ if (url.startsWith(previewUrl.replace('test_filepath', ''))) {
172
+ return true;
173
+ }
174
+ return false;
175
+ }
176
+ return await adapter.isInternalUrl(url);
177
+ } catch (err) {
178
+ console.error(`[UploadPlugin] Error calling isInternalUrl on adapter:`, err);
179
+ return false;
180
+ }
181
+ } else {
182
+ throw new Error ('Plese update storage adapter')
183
+ }
184
+ return false;
185
+ }
186
+
165
187
  instanceUniqueRepresentation(pluginOptions: any) : string {
166
188
  return `${pluginOptions.pathColumnName}`;
167
189
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/upload",
3
- "version": "2.14.5",
3
+ "version": "2.15.1",
4
4
  "description": "Plugin for uploading files for adminforth",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",