apiV0MediaHandler, apiV0TreeHandler

master
Bel LaPointe 2022-02-08 10:55:17 -07:00
parent 06deb5d0c9
commit 7223cb6af9
1 changed files with 13 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"io"
"io/ioutil" "io/ioutil"
"local/router" "local/router"
"net/http" "net/http"
@ -92,7 +93,18 @@ func (server *Server) apiV0MediaHandler(w http.ResponseWriter, r *http.Request)
} }
func (server *Server) apiV0MediaIDHandler(w http.ResponseWriter, r *http.Request) error { func (server *Server) apiV0MediaIDHandler(w http.ResponseWriter, r *http.Request) error {
return errors.New("not impl" + r.URL.Path) id := path.Base(r.URL.Path)
f, err := os.Open(path.Join(server.root, "media", id))
if os.IsNotExist(err) {
http.NotFound(w, r)
return nil
}
if err != nil {
return err
}
defer f.Close()
io.Copy(w, f)
return nil
} }
func (server *Server) apiV0FilesHandler(w http.ResponseWriter, r *http.Request) error { func (server *Server) apiV0FilesHandler(w http.ResponseWriter, r *http.Request) error {