This commit is contained in:
2026-07-14 23:19:56 +02:00
parent fafe5b0eab
commit 9096844266
+504 -337
View File
@@ -23,347 +23,498 @@ get_ext :: proc(url: string) -> string {
return "" return ""
} }
detect_embed_type :: proc(url: string) -> string { detect_mime_type :: proc(url: string) -> string {
ext := get_ext(url) ext := get_ext(url)
switch ext { switch ext {
case ".jpg", case ".jpg", ".jpeg", ".jpe", ".jfif", ".jif", ".pjpeg", ".pjp":
".jpeg", return "image/jpeg"
".jpe", case ".png":
".jfif", return "image/png"
".jif", case ".apng":
".pjpeg", return "image/apng"
".pjp", case ".gif":
".png", return "image/gif"
".apng", case ".webp":
".gif", return "image/webp"
".webp", case ".avif":
".avif", return "image/avif"
".heic", case ".heic":
".heif", return "image/heic"
".hif", case ".heif", ".hif":
".bmp", return "image/heif"
".dib", case ".bmp", ".dib":
".tif", return "image/bmp"
".tiff", case ".tif", ".tiff":
".ico", return "image/tiff"
".cur", case ".ico", ".cur":
".svg", return "image/x-icon"
".svgz", case ".svg", ".svgz":
".raw", return "image/svg+xml"
".cr2", case ".raw":
".cr3", return "image/x-raw"
".nef", case ".cr2":
".nrw", return "image/x-canon-cr2"
".orf", case ".cr3":
".sr2", return "image/x-canon-cr3"
".arw", case ".nef":
".srf", return "image/x-nikon-nef"
".rw2", case ".nrw":
".pef", return "image/x-nikon-nrw"
".raf", case ".orf":
".dng", return "image/x-olympus-orf"
".3fr", case ".sr2", ".srf":
".ari", return "image/x-sony-sr2"
".bay", case ".arw":
".cap", return "image/x-sony-arw"
".dcr", case ".rw2":
".erf", return "image/x-panasonic-rw2"
".fff", case ".pef":
".iiq", return "image/x-pentax-pef"
".k25", case ".rwl":
".kdc", return "image/x-pentax-rwl"
".mdc", case ".raf":
".mos", return "image/x-fuji-raf"
".mrw", case ".dng":
".obm", return "image/x-adobe-dng"
".ptx", case ".3fr":
".pxn", return "image/x-3fr"
".r3d", case ".ari":
".rwl", return "image/x-ari"
".rwz", case ".bay":
".srw", return "image/x-bay"
".x3f", case ".cap":
".gpr", return "image/x-cap"
".pgm", case ".dcr":
".ppm", return "image/x-kodak-dcr"
".pbm", case ".erf":
".pnm", return "image/x-epson-erf"
".pam", case ".fff":
".pfm", return "image/x-hasselblad-fff"
".tga", case ".iiq":
".icb", return "image/x-iiq"
".vda", case ".k25":
".vst", return "image/x-kodak-k25"
".pcx", case ".kdc":
".xbm", return "image/x-kodak-kdc"
".xpm", case ".mdc":
".xwd", return "image/x-minolta-mdc"
".sgi", case ".mos":
".rgb", return "image/x-mamiya-mos"
".rgba", case ".mrw":
".bw", return "image/x-minolta-mrw"
".jp2", case ".obm":
".j2k", return "image/x-obm"
".j2c", case ".ptx":
".jpf", return "image/x-pentax-ptx"
".jpx", case ".pxn":
".jpm", return "image/x-panasonic-pxn"
".mj2", case ".r3d":
".wbmp", return "image/x-red-r3d"
".emf", case ".rwz":
".wmf", return "image/x-rwz"
".eps", case ".srw":
".epsi", return "image/x-samsung-srw"
".epsf", case ".x3f":
".psd", return "image/x-sigma-x3f"
".psb", case ".gpr":
".ai", return "image/x-gpr"
".cdr", case ".pgm":
".xcf", return "image/x-portable-graymap"
".gbr", case ".ppm":
".gih", return "image/x-portable-pixmap"
".pat", case ".pbm":
".art", return "image/x-portable-bitmap"
".jxl", case ".pnm":
".jxr", return "image/x-portable-anymap"
".wdp", case ".pam":
".hdp", return "image/x-portable-arbitrarymap"
".exr", case ".pfm":
".hdr", return "image/x-portable-floatmap"
".dpx", case ".tga", ".icb", ".vda", ".vst":
".cin", return "image/x-targa"
".fits", case ".pcx":
".fit", return "image/x-pcx"
".fts", case ".xbm":
".icns", return "image/x-xbitmap"
".flif", case ".xpm":
".dds", return "image/x-xpixmap"
".ktx", case ".xwd":
".ktx2", return "image/x-xwindowdump"
".astc", case ".sgi", ".rgb", ".rgba", ".bw":
".kodak", return "image/x-sgi"
".fpx", case ".jp2", ".j2k", ".j2c":
".pcd", return "image/jp2"
".cmx", case ".jpf", ".jpx", ".jpm", ".mj2":
".drw", return "image/jpx"
".cgm", case ".wbmp":
".plt", return "image/vnd.wap.wbmp"
".hpgl", case ".emf":
".iff", return "image/x-emf"
".ilbm", case ".wmf":
".lbm", return "image/x-wmf"
".mac", case ".eps", ".epsi", ".epsf":
".msp", return "application/postscript"
".pct", case ".psd":
".pic", return "image/vnd.adobe.photoshop"
".pict", case ".psb":
".pntg", return "image/vnd.adobe.photoshop"
".qtif", case ".ai":
".qti", return "application/postscript"
".ras", case ".cdr":
".sun", return "image/x-coreldraw"
".tpic", case ".xcf":
".wpg", return "image/x-xcf"
".g3", case ".gbr":
".g4", return "image/x-gimp-gbr"
".dcm", case ".gih":
".dicom", return "image/x-gimp-gih"
".ora", case ".pat":
".kra", return "image/x-gimp-pat"
".clip": case ".art":
return "image" return "image/x-art"
case ".mp3", case ".jxl":
".mp2", return "image/jxl"
".mp1", case ".jxr", ".wdp", ".hdp":
".mpa", return "image/vnd.ms-photo"
".mpga", case ".exr":
".ogg", return "image/x-exr"
".oga", case ".hdr":
".opus", return "image/vnd.radiance"
".spx", case ".dpx":
".wav", return "image/x-dpx"
".wave", case ".cin":
".flac", return "image/x-cineon"
".aac", case ".fits", ".fit", ".fts":
".adts", return "image/fits"
".wma", case ".icns":
".m4a", return "image/x-icns"
".m4b", case ".flif":
".m4p", return "image/x-flif"
".m4r", case ".dds":
".aif", return "image/vnd.ms-dds"
".aiff", case ".ktx":
".aifc", return "image/ktx"
".au", case ".ktx2":
".snd", return "image/ktx2"
".mid", case ".astc":
".midi", return "image/x-astc"
".rmi", case ".kodak":
".kar", return "image/x-kodak"
".ra", case ".fpx":
".ram", return "image/vnd.fpx"
".mka", case ".pcd":
".ape", return "image/x-photo-cd"
".wv", case ".cmx":
".ac3", return "image/x-cmx"
".ec3", case ".drw":
".eac3", return "image/x-drw"
".dts", case ".cgm":
".dtshd", return "image/cgm"
".amr", case ".plt", ".hpgl":
".awb", return "image/x-hpgl"
".caf", case ".iff", ".ilbm", ".lbm":
".gsm", return "image/x-iff"
".mpc", case ".mac":
".shn", return "image/x-macpaint"
".tta", case ".msp":
".voc", return "image/x-mspaint"
".vox", case ".pct", ".pic", ".pict":
".8svx", return "image/x-pict"
".mod", case ".pntg":
".s3m", return "image/x-macpaint"
".xm", case ".qtif", ".qti":
".it", return "image/x-quicktime"
".stm", case ".ras", ".sun":
".med", return "image/x-sun-raster"
".mtm", case ".tpic":
".umx", return "image/x-tpic"
".669", case ".wpg":
".far", return "image/x-wpg"
".amf", case ".g3":
".dsm", return "image/g3fax"
".gdm", case ".g4":
".imf", return "image/g4fax"
".okt", case ".dcm", ".dicom":
".sfx", return "application/dicom"
".ult", case ".ora":
".uni", return "image/openraster"
".psm", case ".kra":
".j2b", return "application/x-krita"
".dbm", case ".clip":
".digi", return "image/x-clip"
".dtm",
".plm", case ".mp3", ".mp2", ".mp1", ".mpa", ".mpga":
".nsf", return "audio/mpeg"
".nsfe", case ".ogg", ".oga", ".opus":
".spc", return "audio/ogg"
".gym", case ".spx":
".vgm", return "audio/x-speex"
".vgz", case ".wav", ".wave":
".gbs", return "audio/wav"
".hes", case ".flac":
".ay", return "audio/flac"
".sid", case ".aac", ".adts":
".oma", return "audio/aac"
".aa3", case ".wma":
".at3", return "audio/x-ms-wma"
".at9", case ".m4a", ".m4b", ".m4p", ".m4r":
".qcp", return "audio/mp4"
".tak", case ".aif", ".aiff", ".aifc":
".ofr", return "audio/aiff"
".ofs", case ".au", ".snd":
".sox", return "audio/basic"
".weba", case ".mid", ".midi", ".rmi", ".kar":
".dss", return "audio/midi"
".alac", case ".ra", ".ram":
".vqf", return "audio/x-pn-realaudio"
".vql", case ".mka":
".mxmf", return "audio/x-matroska"
".ota", case ".ape":
".imy", return "audio/x-ape"
".rtttl", case ".wv":
".rtx", return "audio/x-wavpack"
".xmf", case ".ac3":
".w64", return "audio/ac3"
".rf64", case ".ec3", ".eac3":
".bwf", return "audio/eac3"
".cda", case ".dts":
".aup": return "audio/vnd.dts"
return "audio" case ".dtshd":
case ".mp4", return "audio/vnd.dts.hd"
".m4v", case ".amr", ".awb":
".mp4v", return "audio/amr"
".webm", case ".caf":
".mov", return "audio/x-caf"
".qt", case ".gsm":
".avi", return "audio/x-gsm"
".mkv", case ".mpc":
".flv", return "audio/x-musepack"
".f4v", case ".shn":
".f4p", return "audio/x-shn"
".f4a", case ".tta":
".f4b", return "audio/x-tta"
".wmv", case ".voc":
".mpg", return "audio/x-voc"
".mpeg", case ".vox":
".mpe", return "audio/x-vox"
".m1v", case ".8svx":
".m2v", return "audio/x-8svx"
".mpv", case ".mod":
".mp2v", return "audio/x-mod"
".mpv2", case ".s3m":
".ogv", return "audio/x-s3m"
".ogx", case ".xm":
".3gp", return "audio/x-xm"
".3g2", case ".it":
".3gpp", return "audio/x-it"
".3gpp2", case ".stm":
".asf", return "audio/x-stm"
".asx", case ".med":
".vob", return "audio/x-med"
".ts", case ".mtm":
".mts", return "audio/x-mtm"
".m2ts", case ".umx":
".tsv", return "audio/x-umx"
".tsa", case ".669":
".divx", return "audio/x-669"
".xvid", case ".far":
".rm", return "audio/x-far"
".rmvb", case ".amf":
".swf", return "audio/x-amf"
".dv", case ".dsm":
".dif", return "audio/x-dsm"
".gifv", case ".gdm":
".roq", return "audio/x-gdm"
".nsv", case ".imf":
".svi", return "audio/x-imf"
".annodex", case ".okt":
".axv", return "audio/x-okt"
".amv", case ".sfx":
".bik", return "audio/x-sfx"
".bk2", case ".ult":
".smk", return "audio/x-ult"
".ivf", case ".uni":
".mxf", return "audio/x-uni"
".nut", case ".psm":
".ogm", return "audio/x-psm"
".fli", case ".j2b":
".flc", return "audio/x-j2b"
".y4m", case ".dbm":
".264", return "audio/x-dbm"
".h264", case ".digi":
".265", return "audio/x-digi"
".h265", case ".dtm":
".hevc", return "audio/x-dtm"
".av1", case ".plm":
".vc1", return "audio/x-plm"
".vp8", case ".nsf", ".nsfe":
".vp9", return "audio/x-nsf"
".wtv", case ".spc":
".yuv", return "audio/x-spc"
".str", case ".gym":
".pva", return "audio/x-gym"
".trp", case ".vgm", ".vgz":
".rec", return "audio/x-vgm"
".vid", case ".gbs":
".rv", return "audio/x-gbs"
".cpk", case ".hes":
".film": return "audio/x-hes"
return "video" case ".ay":
return "audio/x-ay"
case ".sid":
return "audio/x-sid"
case ".oma":
return "audio/x-oma"
case ".aa3", ".at3", ".at9":
return "audio/x-atrac"
case ".qcp":
return "audio/qcelp"
case ".tak":
return "audio/x-tak"
case ".ofr", ".ofs":
return "audio/x-optimfrog"
case ".sox":
return "audio/x-sox"
case ".weba":
return "audio/webm"
case ".dss":
return "audio/x-dss"
case ".alac":
return "audio/alac"
case ".vqf", ".vql":
return "audio/x-vqf"
case ".mxmf":
return "audio/x-mxmf"
case ".ota":
return "audio/x-ota"
case ".imy":
return "audio/i-melody"
case ".rtttl":
return "audio/x-rtttl"
case ".rtx":
return "audio/x-rtx"
case ".xmf":
return "audio/x-xmf"
case ".w64":
return "audio/x-w64"
case ".rf64":
return "audio/x-rf64"
case ".bwf":
return "audio/x-bwf"
case ".cda":
return "audio/x-cda"
case ".aup":
return "audio/x-aup"
case ".mp4", ".m4v", ".mp4v":
return "video/mp4"
case ".webm":
return "video/webm"
case ".mov", ".qt":
return "video/quicktime"
case ".avi":
return "video/x-msvideo"
case ".mkv":
return "video/x-matroska"
case ".flv":
return "video/x-flv"
case ".f4v", ".f4p":
return "video/x-f4v"
case ".f4a", ".f4b":
return "audio/mp4"
case ".wmv":
return "video/x-ms-wmv"
case ".mpg", ".mpeg", ".mpe", ".m1v", ".m2v", ".mpv", ".mp2v", ".mpv2":
return "video/mpeg"
case ".ogv", ".ogx":
return "video/ogg"
case ".3gp", ".3gpp":
return "video/3gpp"
case ".3g2", ".3gpp2":
return "video/3gpp2"
case ".asf", ".asx":
return "video/x-ms-asf"
case ".vob":
return "video/x-vob"
case ".ts", ".mts", ".m2ts", ".tsv", ".tsa":
return "video/mp2t"
case ".divx":
return "video/x-divx"
case ".xvid":
return "video/x-xvid"
case ".rm", ".rmvb":
return "video/x-pn-realvideo"
case ".swf":
return "application/x-shockwave-flash"
case ".dv", ".dif":
return "video/x-dv"
case ".gifv":
return "video/x-gifv"
case ".roq":
return "video/x-roq"
case ".nsv":
return "video/x-nsv"
case ".svi":
return "video/x-svi"
case ".annodex":
return "application/x-annodex"
case ".axv":
return "video/x-annodex"
case ".amv":
return "video/x-amv"
case ".bik", ".bk2":
return "video/x-bik"
case ".smk":
return "video/x-smacker"
case ".ivf":
return "video/x-ivf"
case ".mxf":
return "application/mxf"
case ".nut":
return "video/x-nut"
case ".ogm":
return "video/x-ogm"
case ".fli", ".flc":
return "video/x-fli"
case ".y4m":
return "video/x-yuv4mpegpipe"
case ".264", ".h264":
return "video/H264"
case ".265", ".h265", ".hevc":
return "video/H265"
case ".av1":
return "video/AV1"
case ".vc1":
return "video/x-vc1"
case ".vp8":
return "video/VP8"
case ".vp9":
return "video/VP9"
case ".wtv":
return "video/x-wtv"
case ".yuv":
return "video/x-yuv"
case ".str":
return "video/x-str"
case ".pva":
return "video/x-pva"
case ".trp":
return "video/x-trp"
case ".rec":
return "video/x-rec"
case ".vid":
return "video/x-vid"
case ".rv":
return "video/vnd.rn-realvideo"
case ".cpk":
return "video/x-cpk"
case ".film":
return "video/x-film"
case "js", "javascript": case "js", "javascript":
return "script" return "text/javascript"
case: case:
return "iframe" return "text/html"
} }
} }
@@ -383,3 +534,19 @@ parse_type_hint :: proc(type_hint: string) -> string {
return "" return ""
} }
} }
detect_embed_type :: proc(url: string) -> string {
mime := detect_mime_type(url)
switch {
case strings.has_prefix(mime, "image/"):
return "image"
case strings.has_prefix(mime, "audio/"):
return "audio"
case strings.has_prefix(mime, "video/"):
return "video"
case mime == "text/javascript" || mime == "application/javascript":
return "script"
case:
return "iframe"
}
}