change /v1/get_file use URL params

This commit is contained in:
2022-11-03 08:18:07 +08:00
parent df081d39ca
commit 5c3fb66db3

View File

@@ -86,26 +86,25 @@ func (api *API) HandleGetFileFfprobeInfo(w http.ResponseWriter, r *http.Request)
} }
} }
// /get_file // /api/v1/get_file?id=123
// get raw file with io.Copy method // get raw file with io.Copy method
func (api *API) HandleGetFile(w http.ResponseWriter, r *http.Request) { func (api *API) HandleGetFile(w http.ResponseWriter, r *http.Request) {
getFileRequest := &GetFileRequest{ q := r.URL.Query()
ID: -1, ids := q["id"]
} _id, err := strconv.Atoi(ids[0])
err := json.NewDecoder(r.Body).Decode(getFileRequest)
if err != nil { if err != nil {
api.HandleError(w, r, err) api.HandleError(w, r, err)
return return
} }
id := int64(_id)
// check empty // check empty
if getFileRequest.ID < 0 { if id < 0 {
api.HandleErrorString(w, r, `"id" can't be none or negative`) api.HandleErrorString(w, r, `"id" can't be none or negative`)
return return
} }
file, err := api.Db.GetFile(getFileRequest.ID) file, err := api.Db.GetFile(id)
if err != nil { if err != nil {
api.HandleError(w, r, err) api.HandleError(w, r, err)
return return