diff --git a/src/lib/filelink.spec.ts b/src/lib/filelink.spec.ts index 1396c992..950d0918 100644 --- a/src/lib/filelink.spec.ts +++ b/src/lib/filelink.spec.ts @@ -128,6 +128,12 @@ describe('filelink', () => { expect(result).toEqual(TransformSchema); }); + it('should not require apikay on filestack external url', () => { + const filelink = new Filelink('https://cdn.filestackcontent.com/5aYkEQJSQCmYShsoCnZN'); + filelink.shadow(false).upscale(); + expect(filelink.toString()).toBe('https://cdn.filestackcontent.com/upscale/\"https://cdn.filestackcontent.com/5aYkEQJSQCmYShsoCnZN\"'); + }); + it('should be able to disable selected task', () => { const filelink = new Filelink(defaultSource); filelink.shadow(false).upscale(); diff --git a/src/lib/filelink.ts b/src/lib/filelink.ts index 527a4b02..7ba1e596 100644 --- a/src/lib/filelink.ts +++ b/src/lib/filelink.ts @@ -542,20 +542,8 @@ export class Filelink { * @memberof Filelink */ constructor(source: string | string[], apikey?: string) { - this.source = source; - const isExternal = this.isSourceExternal(); - - debug(`Source ${source} - isExternal? ${isExternal}`); - - if (isExternal && !apikey) { - throw new FilestackError('External sources requires apikey to handle transforms'); - } - - if (!isExternal && typeof this.source === 'string' && !handleRegexp.test(this.source)) { - throw new FilestackError('Invalid filestack source provided'); - } - this.apikey = apikey; + this.setSource(source); } /** @@ -606,6 +594,22 @@ export class Filelink { return this; } + setSource(source: string | string[]) { + this.source = source; + + const isExternal = this.isSourceExternal(); + + debug(`Source ${source} - isExternal? ${isExternal}`); + + if (isExternal && !this.apikey) { + throw new FilestackError('External sources requires apikey to handle transforms'); + } + + if (!isExternal && typeof this.source === 'string' && (!handleRegexp.test(this.source) && this.source.indexOf('filestackcontent') === -1)) { + throw new FilestackError('Invalid filestack source provided'); + } + } + /** * Returns JSONSchema form transformations params * @@ -1289,7 +1293,7 @@ export class Filelink { continue; } - if (toTest[i].indexOf('src:') === 0 || toTest[i].indexOf('http') === 0) { + if (toTest[i].indexOf('src:') === 0 || (toTest[i].indexOf('http') === 0 && toTest[i].indexOf('filestackcontent') === -1)) { return true; } }