31 lines
732 B
Go
31 lines
732 B
Go
|
package api
|
||
|
|
||
|
import (
|
||
|
"path"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
// Responsible for serving up static images / videos
|
||
|
func (api *API) mediaHandler(w http.ResponseWriter, r *http.Request) {
|
||
|
if r.Method != http.MethodGet {
|
||
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if path.Dir(r.URL.Path) != "/media" {
|
||
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// Pull out UUIDs
|
||
|
reqInfo := r.Context().Value("uuids").(map[string]string)
|
||
|
uid := reqInfo["uid"]
|
||
|
|
||
|
// Derive Path
|
||
|
fileName := path.Base(r.URL.Path)
|
||
|
folderPath := path.Join("/" + api.Config.DataPath + "/media/" + uid)
|
||
|
mediaPath := path.Join(folderPath + "/" + fileName)
|
||
|
|
||
|
http.ServeFile(w, r, mediaPath)
|
||
|
}
|