70 lines
1.6 KiB
Elixir
70 lines
1.6 KiB
Elixir
defmodule RlRepo.Router do
|
|
require Logger
|
|
|
|
@moduledoc """
|
|
TODO: new_route("/<pkg>/", fn -> IO>puts("hello") end)
|
|
"""
|
|
def status_404() do
|
|
placeholders = %{"reason" => "Unknown"}
|
|
|
|
{404, "text/html", RlRepo.Template.template("404-error", placeholders)}
|
|
end
|
|
|
|
def route_1(path, request_type) do
|
|
if request_type == "POST" do
|
|
Logger.info("Post request handled!")
|
|
end
|
|
|
|
if path == "/favicon.ico" do
|
|
{200, "afdssadf", "1112"}
|
|
end
|
|
|
|
placeholders = %{"reason" => "Unknown"}
|
|
|
|
{200, "text/html", RlRepo.Template.template("button-page", placeholders)}
|
|
end
|
|
|
|
def route_3(path, request_type) do
|
|
Logger.info("#{request_type}")
|
|
{repo_name, pkg_name, action} = path
|
|
|
|
if action == "info" do
|
|
Logger.info("fetching json")
|
|
end
|
|
|
|
{200, "application/json", "{\"pkg_name\": \"#{pkg_name}\"}"}
|
|
end
|
|
|
|
def route_4(path, request_type) do
|
|
Logger.info("#{request_type}")
|
|
# {repo_name, sub_repo_name, pkg_name, action} = path
|
|
{200, "application/json", RlRepo.Json.fmt_as_json()}
|
|
end
|
|
|
|
def parse_1_segment_path(path) do
|
|
[repo_name | _] = path
|
|
{repo_name}
|
|
end
|
|
|
|
def parse_3_segment_path(path) do
|
|
[repo_name | rest] = path
|
|
[pkg_name | rest] = rest
|
|
[action | _] = rest
|
|
|
|
Logger.info("REPO #{repo_name} PKG #{pkg_name} ACTION #{action}")
|
|
|
|
{repo_name, pkg_name, action}
|
|
end
|
|
|
|
def parse_4_segment_path(path) do
|
|
[repo_name | rest] = path
|
|
[sub_repo_name | rest] = rest
|
|
[pkg_name | rest] = rest
|
|
[action | _] = rest
|
|
|
|
Logger.info("REPO #{repo_name} SUB_REPO #{sub_repo_name} PKG #{pkg_name} ACTION #{action}")
|
|
|
|
{repo_name, sub_repo_name, pkg_name, action}
|
|
end
|
|
end
|