Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(filelink): add set soruce method #270

Merged
merged 1 commit into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/lib/filelink.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
32 changes: 18 additions & 14 deletions src/lib/filelink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
}
}
Expand Down