Compare commits

...

4 Commits

Author SHA1 Message Date
absc f1ad05f789 Make the ip address type configurable.
We want to be able to use both IPv4 and IPv6.
2024-08-02 23:15:28 +02:00
absc dbf5371122 The routes were in the wrong format. Correct them. 2024-08-02 23:12:33 +02:00
absc 59f02f4edf This application will handle the mime types at the web request layer. 2024-08-02 23:05:41 +02:00
absc 94ee24c777 Add the right arguments to the bootstrap procedure. 2024-08-02 22:56:03 +02:00
3 changed files with 18 additions and 159 deletions

View File

@ -16,7 +16,7 @@
-module(dudeswave_app). -module(dudeswave_app).
-behaviour(application). -behaviour(application).
-export([start/2, stop/1]). -export([bootstrap/3, start/2, stop/1]).
-define(APPBUCKET, dudeswave). -define(APPBUCKET, dudeswave).
-define(USERSBUCKET, dudes). -define(USERSBUCKET, dudes).
@ -27,15 +27,24 @@ start(_Type, StartArgs) ->
undefined -> undefined undefined -> undefined
end, end,
Inet = case application:get_env(inet) of
ipv4 -> inet;
undefined -> inet;
ipv6 -> inet6
end,
{ok, Port} = application:get_env(port), {ok, Port} = application:get_env(port),
Dispatch = cowboy_router:compile([ Dispatch = cowboy_router:compile([
{'_', [{"/user", dudeswave_user_handler, #{bucket => ?USERSBUCKET}}]}, {'_', [
{'_', [{"/", dudeswave_handler, #{bucket => ?APPBUCKET}}]} {"/user", dudeswave_user_handler, #{bucket => ?USERSBUCKET}},
{"/", dudeswave_handler, #{bucket => ?APPBUCKET}}
]}
]), ]),
{ok, ListenerPid} = cowboy:start_tls(dudeswave_listener, [ {ok, ListenerPid} = cowboy:start_tls(dudeswave_listener, [
{port, Port}, {port, Port},
Inet,
{ip, Addr} {ip, Addr}
], #{env => #{dispatch => Dispatch}}), ], #{env => #{dispatch => Dispatch}}),
@ -49,4 +58,4 @@ stop(_State) ->
% %
% Bootstrap procedure to be completed % Bootstrap procedure to be completed
% %
bootstrap(_Bucket) -> ok. bootstrap(_Admin, _Password, _Nodes) -> ok.

View File

@ -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"}.

View File

@ -66,15 +66,10 @@ file:
-include_lib("stdlib/include/qlc.hrl"). -include_lib("stdlib/include/qlc.hrl").
-include_lib("storage/include/storage.hrl"). -include_lib("storage/include/storage.hrl").
-define(MIMEFILE, "/mimes.txt").
-define(DEFMIME, "application/octect-stream").
-type object() :: #object{}. -type object() :: #object{}.
-type metadata() :: [{atom(), term()}]. -type metadata() :: [{atom(), term()}].
-export_type([object/0, metadata/0]). -export_type([object/0, metadata/0]).
-record(mime, {ext, mtype}).
% %
% Start functions. % Start functions.
% %
@ -489,11 +484,11 @@ Objs.
[#object{key = o1, [#object{key = o1,
tags = [foo, bar], tags = [foo, bar],
value = {ipse, dixit}, value = {ipse, dixit},
metadata = [{tags, [foo, bar]},{mime, 'application/octect-stream'}] metadata = [{tags, [foo, bar]}]
}, #object{key = o2, }, #object{key = o2,
tags = [foo, bar], tags = [foo, bar],
value = 42, value = 42,
metadata = [{tags, [foo, bar]},{mime, 'application/octect-stream'}] metadata = [{tags, [foo, bar]}]
} }
] ]
@ -525,7 +520,7 @@ Example:
{ok, [R]} = read(objects, foo). {ok, [R]} = read(objects, foo).
R. R.
#object{key = o1,value = {ipse, dixit}, #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 -spec read(Bucket, Key) -> {ok, Record} | {error, Reason} when
@ -604,23 +599,9 @@ code_change(_OldVsn, N, _Extra) -> {ok, N}.
init([]) -> init([]) ->
process_flag(trap_exit, true), 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}. {ok, 0}.
terminate(_Reason, _N) -> terminate(_Reason, _N) -> ok.
mnesia:delete_table(mime),
ok.
% %
% Bucket operations callbacks. % 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, []}, _From, State);
handle_call({write, Bucket, Key, Term, Metadata}, _From, State) -> handle_call({write, Bucket, Key, Term, Metadata}, _From, State) ->
Ex = filename:extension(Key),
F = fun() -> F = fun() ->
M = case mnesia:read(mime, Ex) of R = #object{key = Key, value = Term, metadata = Metadata},
[] -> ?DEFMIME;
[Mt] -> Mt#mime.mtype
end,
R = #object{key = Key, value = Term, metadata = lists:flatten([{mime, M}, Metadata])},
mnesia:write(Bucket, R, write) mnesia:write(Bucket, R, write)
end, end,