Skip to content

Commit

Permalink
feat: add xspf-url fn
Browse files Browse the repository at this point in the history
  • Loading branch information
altaywtf committed Sep 12, 2024
1 parent 819f2d9 commit df4c6d9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/file/file-url-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ const mockFileRenderType = (type: string) => {
};

describe('FileURLProvider', () => {
it('should correctly format the apiURL', () => {
const customApiURL = 'https://custom-api.example.com';
const customToken = 'custom-token';
const provider = new FileURLProvider(customApiURL, customToken);

expect(provider.apiURL).toBe('https://custom-api.example.com/v2');
});

it('should not append /v2 if apiURL already ends with /v2', () => {
const apiURLWithV2 = 'https://api.example.com/v2';
const customToken = 'another-token';
const provider = new FileURLProvider(apiURLWithV2, customToken);

expect(provider.apiURL).toBe('https://api.example.com/v2');
});

describe('getDownloadURL', () => {
it('should return download URL for file ID', () => {
const fileId = 123;
Expand Down Expand Up @@ -200,4 +216,28 @@ describe('FileURLProvider', () => {
expect(url).toBeNull();
});
});

describe('getXSPFURL', () => {
it('should return null if file is not a video', () => {
mockFileRenderType('audio');
const file: IFile = {
...baseFile,
file_type: 'AUDIO',
};
const url = provider.getXSPFURL(file);
expect(url).toBeNull();
});

it('should return XSPF URL for video file', () => {
mockFileRenderType('video');
const file: IFile = {
...baseFile,
file_type: 'VIDEO',
};
const url = provider.getXSPFURL(file);
expect(url).toMatchInlineSnapshot(
`"https://api.example.com/v2/files/1/xspf?oauth_token=test-token"`
);
});
});
});
8 changes: 8 additions & 0 deletions src/file/file-url-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,12 @@ export class FileURLProvider {
return null;
}
}

getXSPFURL(file: IFile) {
if (getFileRenderType(file) !== 'video') {
return null;
}

return `${this.apiURL}/files/${file.id}/xspf?oauth_token=${this.token}`;
}
}

0 comments on commit df4c6d9

Please sign in to comment.