using Mux using HTTP using Revise push!(LOAD_PATH, "/home/nixo/memories/projects/2018-2019/musicjl") isdir("../juliaMusicDL") && push!(LOAD_PATH, realpath("../juliaMusicDL")) import Beets import RuTrackers import MusicBrainz import TransmissionRPC import JSON # FIXME: replace with JSON2 serialization me = RuTrackers.RuTracker(read("rutracker.json", String) |> JSON.parse) rpc = TransmissionRPC.Transmission(TransmissionRPC.Sockets.ip"192.168.1.3") retry(Beets.update_albums, delays = Base.ExponentialBackOff(n=10, first_delay=5, max_delay = 100)); push!(LOAD_PATH, realpath("JlSonic")) using JlSonic JlSonic.loadplaylists() JlSonic.loadusers() include("router.jl") include("login.jl") using Dates function logger(app, req) println(string("[", Dates.now(), "] ", req[:method], ": ", req[:path][end])) #, " - ", req[:headers]["User-Agent"])) return app(req) end function basiccatch(app, req) try app(req) catch e showerror(e, catch_backtrace()) return d(:status => 500, :body => "failed") end end defaults = stack(Mux.todict, basiccatch, Mux.splitquery, Mux.toresponse, Mux.assetserver, Mux.pkgfiles) @app sonic = ( Mux.defaults, restp("ping", _ -> ping()), restp("getLicense", _ -> getLicense()), mux(logger, sonic_login, branch(req -> req[:login][:login], mux(dispatch, Mux.notfound())), respond(auth_failed())), ) if !isdefined(Main, :started) serve(sonic) started = true end