mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Treat .ts links in statuses as application/typescript
Fixes https://gitlab.com/soapbox-pub/ditto/-/issues/241
This commit is contained in:
parent
dfae0b15c7
commit
bd3d7fda94
2 changed files with 15 additions and 1 deletions
|
|
@ -7,6 +7,10 @@ Deno.test('getUrlMediaType', () => {
|
|||
assertEquals(getUrlMediaType('https://example.com/index.html'), 'text/html');
|
||||
assertEquals(getUrlMediaType('https://example.com/yolo'), undefined);
|
||||
assertEquals(getUrlMediaType('https://example.com/'), undefined);
|
||||
assertEquals(
|
||||
getUrlMediaType('https://gitlab.com/soapbox-pub/nostrify/-/blob/main/packages/policies/WoTPolicy.ts'),
|
||||
'application/typescript',
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test('isPermittedMediaType', () => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { typeByExtension } from '@std/media-types';
|
||||
import { typeByExtension as _typeByExtension } from '@std/media-types';
|
||||
|
||||
/** Get media type of the filename in the URL by its extension, if any. */
|
||||
export function getUrlMediaType(url: string): string | undefined {
|
||||
|
|
@ -22,3 +22,13 @@ export function isPermittedMediaType(mediaType: string, permitted: string[]): bo
|
|||
const [baseType, _subType] = mediaType.split('/');
|
||||
return permitted.includes(baseType);
|
||||
}
|
||||
|
||||
/** Custom type-by-extension with overrides. */
|
||||
function typeByExtension(ext: string): string | undefined {
|
||||
switch (ext) {
|
||||
case 'ts':
|
||||
return 'application/typescript';
|
||||
default:
|
||||
return _typeByExtension(ext);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue