From 0b077ae180aad4cc86e1ff4594a200da008807cc Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 17 Apr 2021 01:29:27 +0200 Subject: Added battles storage to server --- .gitignore | 1 + derelict.go | 47 ++++++++++++++++++++++++++++++++++++++++++++--- recent.tmpl | 10 +++++++--- view.tmpl | 15 ++------------- 4 files changed, 54 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 265df06..9ea276c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__ *.json derelict +.derelict diff --git a/derelict.go b/derelict.go index 2f5e8b3..aac7c10 100644 --- a/derelict.go +++ b/derelict.go @@ -4,9 +4,11 @@ import ( "embed" "github.com/gorilla/mux" "html/template" + "io/ioutil" "log" "net/http" "os" + "sort" ) //go:embed *.json *.css *.js *.svg @@ -17,24 +19,63 @@ var internal embed.FS var templates *template.Template +var root string + func main() { + initRoot() + port := os.Getenv("DERELICTPORT") if port == "" { port = "8080" } + templates = template.Must(template.ParseFS(internal, "*.tmpl")) router := mux.NewRouter() router.HandleFunc("/", handleRecent).Methods("GET") - router.HandleFunc("/view", handleView).Queries("id", "{id:[_0-9]+}").Methods("GET") + router.HandleFunc("/view/{id:[_0-9]+}", handleView).Methods("GET") + router.HandleFunc("/battles/", handleBattlesPost).Methods("POST") + router.HandleFunc("/battles/{id:[_0-9]+}", handleBattlesId).Methods("GET") router.PathPrefix("/").Handler(http.FileServer(http.FS(content))) + log.Fatal(http.ListenAndServe(":"+port, router)) } +func initRoot() { + root = os.Getenv("DERELICTROOT") + if root == "" { + root = ".derelict" + } + os.Mkdir(root, 0755) + os.Mkdir(root+"/battles", 0755) +} + +func handleBattlesPost(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusNotImplemented) +} + +func handleBattlesId(w http.ResponseWriter, r *http.Request) { + id := mux.Vars(r)["id"] + w.Header().Add("Content-Type", "application/json") + http.ServeFile(w, r, root+"/battles/"+id) +} + func handleRecent(w http.ResponseWriter, r *http.Request) { - templates.ExecuteTemplate(w, "recent", "") + files, err := ioutil.ReadDir(root + "/battles") + if err != nil { + panic(err) + } + sort.Slice(files, func(lhs, rhs int) bool { + return files[lhs].ModTime().After(files[rhs].ModTime()) + }) + count := 10 + if count > len(files) { + count = len(files) + } + templates.ExecuteTemplate(w, "recent", files[:count]) } func handleView(w http.ResponseWriter, r *http.Request) { - templates.ExecuteTemplate(w, "view", "") + id := mux.Vars(r)["id"] + templates.ExecuteTemplate(w, "view", id) } diff --git a/recent.tmpl b/recent.tmpl index 8f0a48d..4a64d58 100644 --- a/recent.tmpl +++ b/recent.tmpl @@ -13,9 +13,13 @@

Recent

- +
Battle in Amamake127 wrecks3 grids2021-03-29 18:00 -
Battle in Eytjangard20 wrecks2 grids2021-03-24 18:00 -
Battle in N-RAEL8 wrecks1 grid2021-03-22 18:00 +{{range .}} +
{{.Name}} + some wrecks + some grids + {{.ModTime.Format "January 02, 2006 15:04 UTC"}} +{{end}}

About

Derelict is a tool for 3D visualizations of after the battle wreckage fields for EVE Online. Main diff --git a/view.tmpl b/view.tmpl index 835d2f0..ddb88a0 100644 --- a/view.tmpl +++ b/view.tmpl @@ -4,7 +4,7 @@ -Derelict +{{.}} - Derelict

@@ -12,18 +12,7 @@

Derelict

LMB and drag in space to rotate camera.
RMB and drag in space to move camera.

LMB wreck to open killmail.
RMB wreck to focus camera. -

Address must contain id parameter to show some wrecks. -
Currently there is no service that would offer an API to acquire battle reports, so only battles that I - uploaded manually are available as of now: -

-

I plan to address this issue. +

Scroll to zoom in/out.

Grid

Timeline

-- cgit v1.1