/
utils.ts
40 lines (37 loc) · 1.37 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import {extname} from "https://deno.land/std/path/mod.ts";
export function getMean(prevMean:number, curr:number, total:number) {
return Number(((prevMean * total + curr) / (total + 1)).toFixed(3));
}
const EXTENSION_TO_CONTENT_TYPE:Record<string,string>={
'.bin': 'application/octet-stream',
'.csv': 'text/csv',
'.doc': 'application/msword',
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'.gz': 'application/gzip',
'.gif': 'image/gif',
'.htm': 'text/html',
'.html': 'text/html',
'.jpeg': 'image/jpeg',
'.jpg': 'image/jpeg',
'.js': 'text/javascript',
'.json': 'application/json',
'.mp3': 'audio/mpeg',
'.mp4': 'video/mp4',
'.mpeg': 'video/mpeg',
'.png': 'image/png',
'.pdf': 'application/pdf',
'.ppt': 'application/vnd.ms-powerpoint',
'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'.rar': 'application/vnd.rar',
'.svg': 'image/svg+xml',
'.tar': 'application/x-tar',
'.txt': 'text/plain',
'.wav': 'audio/wav',
'.xls': 'application/vnd.ms-excel',
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'.xml': 'application/xml',
'.zip': 'application/zip'
};
export function getContentType(path:string) {
return EXTENSION_TO_CONTENT_TYPE[extname(path)] || 'application/octet-stream';
}