package main import ( "biukop.com/sfm/loan" log "github.com/sirupsen/logrus" "net/http" ) func apiV1UploadAsThumbnail(w http.ResponseWriter, r *http.Request, ss *loan.Session) { strId := r.URL.Path[len(apiV1Prefix+"upload-as-thumbnail/"):] //remove prefix if strId == "default" { http.ServeFile(w, r, config.UploadsDir.ThumbDefault) return } ul, e := getRequestedUpload(strId, w, r, ss) if e != nil { return } // see if a thumbnail is available already if !fileExists(ul.thumbPath()) { e = ul.convertUploadsToThumb() if e != nil { // serve a default no preview is available http.ServeFile(w, r, config.UploadsDir.ThumbDefault) log.Error("error creating preview image", ul, e) return } } if fileExists(ul.thumbPath()) { http.ServeFile(w, r, ul.thumbPath()) return } else { apiV1Client404Error(w, r, ss) } } func apiV1UploadCreateThumbnail(w http.ResponseWriter, r *http.Request, ss *loan.Session) { //time.Sleep(1 * time.Second) strId := r.URL.Path[len(apiV1Prefix+"upload-as-thumbnail/"):] //remove prefix if strId == "" { apiV1Client404Error(w, r, ss) return } ul, e := getRequestedUpload(strId, w, r, ss) if e != nil { return } // see if a thumbnail is available already if !fileExists(ul.thumbPath()) { e = ul.convertUploadsToThumb() if e != nil { log.Error("error creating thumbNail image", ul, e) } } if fileExists(ul.thumbPath()) { apiV1SendJson(true, w, r, ss) return } else { apiV1SendJson(false, w, r, ss) } }