Compare commits
4 Commits
c6328bd174
...
f1ad05f789
Author | SHA1 | Date |
---|---|---|
absc | f1ad05f789 | |
absc | dbf5371122 | |
absc | 59f02f4edf | |
absc | 94ee24c777 |
|
@ -16,7 +16,7 @@
|
|||
-module(dudeswave_app).
|
||||
-behaviour(application).
|
||||
|
||||
-export([start/2, stop/1]).
|
||||
-export([bootstrap/3, start/2, stop/1]).
|
||||
|
||||
-define(APPBUCKET, dudeswave).
|
||||
-define(USERSBUCKET, dudes).
|
||||
|
@ -27,15 +27,24 @@ start(_Type, StartArgs) ->
|
|||
undefined -> undefined
|
||||
end,
|
||||
|
||||
Inet = case application:get_env(inet) of
|
||||
ipv4 -> inet;
|
||||
undefined -> inet;
|
||||
ipv6 -> inet6
|
||||
end,
|
||||
|
||||
{ok, Port} = application:get_env(port),
|
||||
|
||||
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, [
|
||||
{port, Port},
|
||||
Inet,
|
||||
{ip, Addr}
|
||||
], #{env => #{dispatch => Dispatch}}),
|
||||
|
||||
|
@ -49,4 +58,4 @@ stop(_State) ->
|
|||
%
|
||||
% Bootstrap procedure to be completed
|
||||
%
|
||||
bootstrap(_Bucket) -> ok.
|
||||
bootstrap(_Admin, _Password, _Nodes) -> ok.
|
||||
|
|
|
@ -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"}.
|
|
@ -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,
|
||||
|
||||
|
|
Loading…
Reference in New Issue