parent
							
								
									f4afb145d6
								
							
						
					
					
						commit
						73c53fa4e2
					
				@ -35,6 +35,7 @@
 | 
			
		||||
                    'image/gif': 'GIF',
 | 
			
		||||
                    'image/jpeg': 'JPEG',
 | 
			
		||||
                    'image/png': 'PNG',
 | 
			
		||||
                    'image/webp': 'WEBP',
 | 
			
		||||
                    'video/webm': 'WEBM',
 | 
			
		||||
                    'video/mp4': 'MPEG-4',
 | 
			
		||||
                    'application/x-shockwave-flash': 'SWF',
 | 
			
		||||
 | 
			
		||||
@ -8,6 +8,7 @@
 | 
			
		||||
                    'image/gif': 'GIF',
 | 
			
		||||
                    'image/jpeg': 'JPEG',
 | 
			
		||||
                    'image/png': 'PNG',
 | 
			
		||||
                    'image/webp': 'WEBP',
 | 
			
		||||
                    'video/webm': 'WEBM',
 | 
			
		||||
                    'video/mp4': 'MPEG-4',
 | 
			
		||||
                    'application/x-shockwave-flash': 'SWF',
 | 
			
		||||
 | 
			
		||||
@ -13,6 +13,7 @@ function _mimeTypeToPostType(mimeType) {
 | 
			
		||||
        'image/gif': 'image',
 | 
			
		||||
        'image/jpeg': 'image',
 | 
			
		||||
        'image/png': 'image',
 | 
			
		||||
        'image/webp': 'image',
 | 
			
		||||
        'video/mp4': 'video',
 | 
			
		||||
        'video/webm': 'video',
 | 
			
		||||
    }[mimeType] || 'unknown';
 | 
			
		||||
@ -113,6 +114,7 @@ class Url extends Uploadable {
 | 
			
		||||
            'jpg': 'image/jpeg',
 | 
			
		||||
            'png': 'image/png',
 | 
			
		||||
            'gif': 'image/gif',
 | 
			
		||||
            'webp': 'image/webp',
 | 
			
		||||
            'mp4': 'video/mp4',
 | 
			
		||||
            'webm': 'video/webm',
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
@ -18,6 +18,9 @@ def get_mime_type(content: bytes) -> str:
 | 
			
		||||
    if content[0:6] in (b'GIF87a', b'GIF89a'):
 | 
			
		||||
        return 'image/gif'
 | 
			
		||||
 | 
			
		||||
    if content[8:12] == b'WEBP':
 | 
			
		||||
        return 'image/webp'
 | 
			
		||||
 | 
			
		||||
    if content[0:4] == b'\x1A\x45\xDF\xA3':
 | 
			
		||||
        return 'video/webm'
 | 
			
		||||
 | 
			
		||||
@ -33,6 +36,7 @@ def get_extension(mime_type: str) -> Optional[str]:
 | 
			
		||||
        'image/gif': 'gif',
 | 
			
		||||
        'image/jpeg': 'jpg',
 | 
			
		||||
        'image/png': 'png',
 | 
			
		||||
        'image/webp': 'webp',
 | 
			
		||||
        'video/mp4': 'mp4',
 | 
			
		||||
        'video/webm': 'webm',
 | 
			
		||||
        'application/octet-stream': 'dat',
 | 
			
		||||
@ -49,7 +53,7 @@ def is_video(mime_type: str) -> bool:
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def is_image(mime_type: str) -> bool:
 | 
			
		||||
    return mime_type.lower() in ('image/jpeg', 'image/png', 'image/gif')
 | 
			
		||||
    return mime_type.lower() in ('image/jpeg', 'image/png', 'image/gif', 'image/webp')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def is_animated_gif(content: bytes) -> bool:
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								server/szurubooru/tests/assets/webp.webp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								server/szurubooru/tests/assets/webp.webp
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 4.5 KiB  | 
@ -9,6 +9,7 @@ from szurubooru.func import mime
 | 
			
		||||
    ('png.png', 'image/png'),
 | 
			
		||||
    ('jpeg.jpg', 'image/jpeg'),
 | 
			
		||||
    ('gif.gif', 'image/gif'),
 | 
			
		||||
    ('webp.webp', 'image/webp'),
 | 
			
		||||
    ('text.txt', 'application/octet-stream'),
 | 
			
		||||
])
 | 
			
		||||
def test_get_mime_type(read_asset, input_path, expected_mime_type):
 | 
			
		||||
@ -26,6 +27,7 @@ def test_get_mime_type_for_empty_file():
 | 
			
		||||
    ('image/png', 'png'),
 | 
			
		||||
    ('image/jpeg', 'jpg'),
 | 
			
		||||
    ('image/gif', 'gif'),
 | 
			
		||||
    ('image/webp', 'webp'),
 | 
			
		||||
    ('application/octet-stream', 'dat'),
 | 
			
		||||
])
 | 
			
		||||
def test_get_extension(mime_type, expected_extension):
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user