mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-12 10:04:20 +01:00
Treat .ts links in statuses as application/typescript
Fixes https://gitlab.com/soapbox-pub/ditto/-/issues/241
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user