Skip to content

Commit 4480d5e

Browse files
pcholujAndrzej Sala
authored andcommitted
feat(filelink): add set soruce method (#270)
1 parent 813de22 commit 4480d5e

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

src/lib/filelink.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ describe('filelink', () => {
128128
expect(result).toEqual(TransformSchema);
129129
});
130130

131+
it('should not require apikay on filestack external url', () => {
132+
const filelink = new Filelink('https://cdn.filestackcontent.com/5aYkEQJSQCmYShsoCnZN');
133+
filelink.shadow(false).upscale();
134+
expect(filelink.toString()).toBe('https://cdn.filestackcontent.com/upscale/\"https://cdn.filestackcontent.com/5aYkEQJSQCmYShsoCnZN\"');
135+
});
136+
131137
it('should be able to disable selected task', () => {
132138
const filelink = new Filelink(defaultSource);
133139
filelink.shadow(false).upscale();

src/lib/filelink.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -542,20 +542,8 @@ export class Filelink {
542542
* @memberof Filelink
543543
*/
544544
constructor(source: string | string[], apikey?: string) {
545-
this.source = source;
546-
const isExternal = this.isSourceExternal();
547-
548-
debug(`Source ${source} - isExternal? ${isExternal}`);
549-
550-
if (isExternal && !apikey) {
551-
throw new FilestackError('External sources requires apikey to handle transforms');
552-
}
553-
554-
if (!isExternal && typeof this.source === 'string' && !handleRegexp.test(this.source)) {
555-
throw new FilestackError('Invalid filestack source provided');
556-
}
557-
558545
this.apikey = apikey;
546+
this.setSource(source);
559547
}
560548

561549
/**
@@ -606,6 +594,22 @@ export class Filelink {
606594
return this;
607595
}
608596

597+
setSource(source: string | string[]) {
598+
this.source = source;
599+
600+
const isExternal = this.isSourceExternal();
601+
602+
debug(`Source ${source} - isExternal? ${isExternal}`);
603+
604+
if (isExternal && !this.apikey) {
605+
throw new FilestackError('External sources requires apikey to handle transforms');
606+
}
607+
608+
if (!isExternal && typeof this.source === 'string' && (!handleRegexp.test(this.source) && this.source.indexOf('filestackcontent') === -1)) {
609+
throw new FilestackError('Invalid filestack source provided');
610+
}
611+
}
612+
609613
/**
610614
* Returns JSONSchema form transformations params
611615
*
@@ -1289,7 +1293,7 @@ export class Filelink {
12891293
continue;
12901294
}
12911295

1292-
if (toTest[i].indexOf('src:') === 0 || toTest[i].indexOf('http') === 0) {
1296+
if (toTest[i].indexOf('src:') === 0 || (toTest[i].indexOf('http') === 0 && toTest[i].indexOf('filestackcontent') === -1)) {
12931297
return true;
12941298
}
12951299
}

0 commit comments

Comments
 (0)