Return direct URL in json responses

This commit is contained in:
Andrei Marcu 2019-01-14 15:23:56 -08:00
parent 1fb92ffce3
commit e506304b84
2 changed files with 7 additions and 5 deletions

View File

@ -52,11 +52,12 @@ func fileDisplayHandler(c web.C, w http.ResponseWriter, r *http.Request) {
if strings.EqualFold("application/json", r.Header.Get("Accept")) { if strings.EqualFold("application/json", r.Header.Get("Accept")) {
js, _ := json.Marshal(map[string]string{ js, _ := json.Marshal(map[string]string{
"filename": fileName, "filename": fileName,
"expiry": strconv.FormatInt(metadata.Expiry.Unix(), 10), "direct_url": getSiteURL(r) + Config.selifPath + fileName,
"size": strconv.FormatInt(metadata.Size, 10), "expiry": strconv.FormatInt(metadata.Expiry.Unix(), 10),
"mimetype": metadata.Mimetype, "size": strconv.FormatInt(metadata.Size, 10),
"sha256sum": metadata.Sha256sum, "mimetype": metadata.Mimetype,
"sha256sum": metadata.Sha256sum,
}) })
w.Write(js) w.Write(js)
return return

View File

@ -295,6 +295,7 @@ func generateBarename() string {
func generateJSONresponse(upload Upload, r *http.Request) []byte { func generateJSONresponse(upload Upload, r *http.Request) []byte {
js, _ := json.Marshal(map[string]string{ js, _ := json.Marshal(map[string]string{
"url": getSiteURL(r) + upload.Filename, "url": getSiteURL(r) + upload.Filename,
"direct_url": getSiteURL(r) + Config.selifPath + upload.Filename,
"filename": upload.Filename, "filename": upload.Filename,
"delete_key": upload.Metadata.DeleteKey, "delete_key": upload.Metadata.DeleteKey,
"expiry": strconv.FormatInt(upload.Metadata.Expiry.Unix(), 10), "expiry": strconv.FormatInt(upload.Metadata.Expiry.Unix(), 10),