mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(media): embed additional direct image formats (#1146)
This commit is contained in:
@@ -7,9 +7,14 @@ describe('direct-url', () => {
|
||||
expect(isDirectMediaUrl('https://example.com/photo.jpg')).toBe(true);
|
||||
expect(isDirectMediaUrl('https://i.ibb.co/example/photo.jpg')).toBe(true);
|
||||
expect(isDirectMediaUrl('https://example.com/photo.jpeg')).toBe(true);
|
||||
expect(isDirectMediaUrl('https://example.com/photo.jpe')).toBe(true);
|
||||
expect(isDirectMediaUrl('https://example.com/photo.jfif')).toBe(true);
|
||||
expect(isDirectMediaUrl('https://example.com/photo.jif')).toBe(true);
|
||||
expect(isDirectMediaUrl('https://example.com/photo.png')).toBe(true);
|
||||
expect(isDirectMediaUrl('https://example.com/photo.apng')).toBe(true);
|
||||
expect(isDirectMediaUrl('https://example.com/photo.gif')).toBe(true);
|
||||
expect(isDirectMediaUrl('https://example.com/photo.webp')).toBe(true);
|
||||
expect(isDirectMediaUrl('https://example.com/photo.avif')).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true for video extensions', () => {
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
/** File extensions that denote direct media URLs (images, videos, and Flash movies) */
|
||||
const DIRECT_MEDIA_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.webm', '.mp4', '.mov', '.avi', '.mkv', '.gifv', '.swf'] as const;
|
||||
const DIRECT_MEDIA_EXTENSIONS = [
|
||||
'.jpg',
|
||||
'.jpeg',
|
||||
'.jpe',
|
||||
'.jfif',
|
||||
'.jif',
|
||||
'.png',
|
||||
'.apng',
|
||||
'.gif',
|
||||
'.webp',
|
||||
'.avif',
|
||||
'.webm',
|
||||
'.mp4',
|
||||
'.mov',
|
||||
'.avi',
|
||||
'.mkv',
|
||||
'.gifv',
|
||||
'.swf',
|
||||
] as const;
|
||||
|
||||
/** Returns true if the URL appears to point to a direct media file */
|
||||
export function isDirectMediaUrl(url: string): boolean {
|
||||
|
||||
@@ -131,7 +131,12 @@ describe('media-utils', () => {
|
||||
});
|
||||
expect(getLinkMediaInfo('https://example.com/file.gif')).toMatchObject({ type: 'gif' });
|
||||
expect(getLinkMediaInfo('https://external-preview.redd.it/example.gif?width=480&format=mp4')).toMatchObject({ type: 'video' });
|
||||
expect(getLinkMediaInfo('https://example.com/file.jfif')).toMatchObject({ type: 'image' });
|
||||
expect(getLinkMediaInfo('https://example.com/file.jpe')).toMatchObject({ type: 'image' });
|
||||
expect(getLinkMediaInfo('https://example.com/file.jif')).toMatchObject({ type: 'image' });
|
||||
expect(getLinkMediaInfo('https://example.com/file.png')).toMatchObject({ type: 'image' });
|
||||
expect(getLinkMediaInfo('https://example.com/file.apng')).toMatchObject({ type: 'image' });
|
||||
expect(getLinkMediaInfo('https://example.com/file.avif')).toMatchObject({ type: 'image' });
|
||||
expect(getLinkMediaInfo('https://example.com/file.mp4')).toMatchObject({ type: 'video' });
|
||||
expect(getLinkMediaInfo('https://example.com/file.mp3')).toMatchObject({ type: 'audio' });
|
||||
expect(getLinkMediaInfo('https://example.com/file.swf')).toMatchObject({ type: 'swf' });
|
||||
|
||||
@@ -78,7 +78,7 @@ const getPatternThumbnailUrl = (url: URL): string | undefined => {
|
||||
};
|
||||
|
||||
// Known media file extensions - only these will be classified as media files
|
||||
const KNOWN_IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'bmp', 'ico', 'tiff'];
|
||||
const KNOWN_IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'jpe', 'jfif', 'jif', 'png', 'apng', 'gif', 'webp', 'avif', 'svg', 'bmp', 'ico', 'tiff'];
|
||||
const KNOWN_VIDEO_EXTENSIONS = ['mp4', 'webm', 'mov', 'avi', 'mkv', 'flv', 'wmv', 'm4v'];
|
||||
const KNOWN_AUDIO_EXTENSIONS = ['mp3', 'wav', 'ogg', 'flac', 'aac', 'm4a', 'wma'];
|
||||
const KNOWN_SWF_EXTENSIONS = ['swf'];
|
||||
|
||||
Reference in New Issue
Block a user