From 59f02f4edf34611be7d9b26b17e3bb7f05a2424a Mon Sep 17 00:00:00 2001 From: absc Date: Fri, 2 Aug 2024 23:05:41 +0200 Subject: [PATCH] This application will handle the mime types at the web request layer. --- storage/priv/mimes.txt | 124 ---------------------------------------- storage/src/storage.erl | 36 ++---------- 2 files changed, 5 insertions(+), 155 deletions(-) delete mode 100644 storage/priv/mimes.txt diff --git a/storage/priv/mimes.txt b/storage/priv/mimes.txt deleted file mode 100644 index 3702ab1..0000000 --- a/storage/priv/mimes.txt +++ /dev/null @@ -1,124 +0,0 @@ -{".gmi", "text/gemini"}. -{".gmni", "text/gemini"}. -{".atom", "application/atom+xml"}. -{".woff", "application/font-woff"}. -{".jar", "application/java-archive"}. -{".war", "application/java-archive"}. -{".ear", "application/java-archive"}. -{".js", "application/javascript"}. -{".json", "application/json"}. -{".hqx", "application/mac-binhex40"}. -{".doc", "application/msword"}. -{".bin", "application/octet-stream"}. -{".exe", "application/octet-stream"}. -{".dll", "application/octet-stream"}. -{".deb", "application/octet-stream"}. -{".dmg", "application/octet-stream"}. -{".fs", "application/octet-stream"}. -{".iso", "application/octet-stream"}. -{".img", "application/octet-stream"}. -{".msi", "application/octet-stream"}. -{".msp", "application/octet-stream"}. -{".msm", "application/octet-stream"}. -{".pdf", "application/pdf"}. -{".ps", "application/postscript"}. -{".eps", "application/postscript"}. -{".ai", "application/postscript"}. -{".rss", "application/rss+xml"}. -{".rtf", "application/rtf"}. -{".m3u8", "application/vnd.apple.mpegurl"}. -{".kml", "application/vnd.google-earth.kml+xml"}. -{".kmz", "application/vnd.google-earth.kmz"}. -{".xls", "application/vnd.ms-excel"}. -{".eot", "application/vnd.ms-fontobject"}. -{".ppt", "application/vnd.ms-powerpoint"}. -{".odc", "application/vnd.oasis.opendocument.chart"}. -{".otc", "application/vnd.oasis.opendocument.chart-template"}. -{".odb", "application/vnd.oasis.opendocument.database"}. -{".odf", "application/vnd.oasis.opendocument.formula"}. -{".otf", "application/vnd.oasis.opendocument.formula-template"}. -{".odg", "application/vnd.oasis.opendocument.graphics"}. -{".otg", "application/vnd.oasis.opendocument.graphics-template"}. -{".odi", "application/vnd.oasis.opendocument.image"}. -{".oti", "application/vnd.oasis.opendocument.image-template"}. -{".odp", "application/vnd.oasis.opendocument.presentation"}. -{".otp", "application/vnd.oasis.opendocument.presentation-template"}. -{".ods", "application/vnd.oasis.opendocument.spreadsheet"}. -{".ots", "application/vnd.oasis.opendocument.spreadsheet-template"}. -{".odt", "application/vnd.oasis.opendocument.text"}. -{".odm", "application/vnd.oasis.opendocument.text-master"}. -{".ott", "application/vnd.oasis.opendocument.text-template"}. -{".oth", "application/vnd.oasis.opendocument.text-web"}. -{".wmlc", "application/vnd.wap.wmlc"}. -{".7z", "application/x-7z-compressed"}. -{".cco", "application/x-cocoa"}. -{".jardiff", "application/x-java-archive-diff"}. -{".jnlp", "application/x-java-jnlp-file"}. -{".run", "application/x-makeself"}. -{".pac", "application/x-ns-proxy-autoconfig"}. -{".pl", "application/x-perl"}. -{".pm", "application/x-perl"}. -{".prc", "application/x-pilot"}. -{".pdb", "application/x-pilot"}. -{".rar", "application/x-rar-compressed"}. -{".rpm", "application/x-redhat-package-manager"}. -{".sea", "application/x-sea"}. -{".swf", "application/x-shockwave-flash"}. -{".sit", "application/x-stuffit"}. -{".tcl", "application/x-tcl"}. -{".tk", "application/x-tcl"}. -{".der", "application/x-x509-ca-cert"}. -{".pem", "application/x-x509-ca-cert"}. -{".crt", "application/x-x509-ca-cert"}. -{".xpi", "application/x-xpinstall"}. -{".xhtml", "application/xhtml+xml"}. -{".zip", "application/zip"}. -{".ez", "application/zip"}. -{".au", "audio/basic"}. -{".snd", "audio/basic"}. -{".mid", "audio/midi"}. -{".midi", "audio/midi"}. -{".kar", "audio/midi"}. -{".mp3", "audio/mpeg"}. -{".ogg", "audio/ogg"}. -{".m4a", "audio/x-m4a"}. -{".ra", "audio/x-realaudio"}. -{".gif", "image/gif"}. -{".jpeg", "image/jpeg"}. -{".jpg", "image/jpeg"}. -{".png", "image/png"}. -{".svg", "image/svg+xml"}. -{".svgz", "image/svg+xml"}. -{".tif", "image/tiff"}. -{".tiff", "image/tiff"}. -{".wbmp", "image/vnd.wap.wbmp"}. -{".webp", "image/webp"}. -{".ico", "image/x-icon"}. -{".jng", "image/x-jng"}. -{".bmp", "image/x-ms-bmp"}. -{".css", "text/css"}. -{".html", "text/html"}. -{".htm", "text/html"}. -{".shtml", "text/html"}. -{".mml", "text/mathml"}. -{".txt", "text/plain"}. -{".jad", "text/vnd.sun.j2me.app-descriptor"}. -{".wml", "text/vnd.wap.wml"}. -{".htc", "text/x-component"}. -{".xml", "text/xml"}. -{".3gpp", "video/3gpp"}. -{".3gp", "video/3gpp"}. -{".ts", "video/mp2t"}. -{".mp4", "video/mp4"}. -{".mpeg", "video/mpeg"}. -{".mpg", "video/mpeg"}. -{".mov", "video/quicktime"}. -{".webm", "video/webm"}. -{".flv", "video/x-flv"}. -{".m4v", "video/x-m4v"}. -{".mkv", "video/x-matroska"}. -{".mng", "video/x-mng"}. -{".asx", "video/x-ms-asf"}. -{".asf", "video/x-ms-asf"}. -{".wmv", "video/x-ms-wmv"}. -{".avi", "video/x-msvideo"}. diff --git a/storage/src/storage.erl b/storage/src/storage.erl index 411998a..2ec65ce 100644 --- a/storage/src/storage.erl +++ b/storage/src/storage.erl @@ -66,15 +66,10 @@ file: -include_lib("stdlib/include/qlc.hrl"). -include_lib("storage/include/storage.hrl"). --define(MIMEFILE, "/mimes.txt"). --define(DEFMIME, "application/octect-stream"). - -type object() :: #object{}. -type metadata() :: [{atom(), term()}]. -export_type([object/0, metadata/0]). --record(mime, {ext, mtype}). - % % Start functions. % @@ -489,11 +484,11 @@ Objs. [#object{key = o1, tags = [foo, bar], value = {ipse, dixit}, - metadata = [{tags, [foo, bar]},{mime, 'application/octect-stream'}] + metadata = [{tags, [foo, bar]}] }, #object{key = o2, tags = [foo, bar], value = 42, - metadata = [{tags, [foo, bar]},{mime, 'application/octect-stream'}] + metadata = [{tags, [foo, bar]}] } ] @@ -525,7 +520,7 @@ Example: {ok, [R]} = read(objects, foo). R. #object{key = o1,value = {ipse, dixit}, - metadata = [{tags, [foo, bar]},{mime, 'application/octet-stream'}]} + metadata = [{tags, [foo, bar]}] ``` """. -spec read(Bucket, Key) -> {ok, Record} | {error, Reason} when @@ -604,23 +599,9 @@ code_change(_OldVsn, N, _Extra) -> {ok, N}. init([]) -> process_flag(trap_exit, true), - mnesia:create_table(mime, [{attributes, record_info(fields, mime)}, - {ram_copies, [node()]}, {local_content, true}]), - - F= fun() -> - {ok, App} = application:get_application(?MODULE), - {ok, M} = file:consult(lists:append(code:priv_dir(App), ?MIMEFILE)), - - [mnesia:write(#mime{ext = E, mtype = T}) || {E, T} <- M] - end, - - mnesia:transaction(F), - {ok, 0}. -terminate(_Reason, _N) -> - mnesia:delete_table(mime), - ok. +terminate(_Reason, _N) -> ok. % % Bucket operations callbacks. @@ -727,15 +708,8 @@ handle_call({write, Bucket, Key, Term}, _From, State) -> handle_call({write, Bucket, Key, Term, []}, _From, State); handle_call({write, Bucket, Key, Term, Metadata}, _From, State) -> - Ex = filename:extension(Key), - F = fun() -> - M = case mnesia:read(mime, Ex) of - [] -> ?DEFMIME; - [Mt] -> Mt#mime.mtype - end, - - R = #object{key = Key, value = Term, metadata = lists:flatten([{mime, M}, Metadata])}, + R = #object{key = Key, value = Term, metadata = Metadata}, mnesia:write(Bucket, R, write) end,