Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

64 lines
1.5KB

  1. package main
  2. import (
  3. "biukop.com/sfm/loan"
  4. log "github.com/sirupsen/logrus"
  5. "net/http"
  6. )
  7. func apiV1UploadAsThumbnail(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  8. strId := r.URL.Path[len(apiV1Prefix+"upload-as-thumbnail/"):] //remove prefix
  9. if strId == "default" {
  10. http.ServeFile(w, r, config.UploadsDir.ThumbDefault)
  11. return
  12. }
  13. ul, e := getRequestedUpload(strId, w, r, ss)
  14. if e != nil {
  15. return
  16. }
  17. // see if a thumbnail is available already
  18. if !fileExists(ul.thumbPath()) {
  19. e = ul.convertUploadsToThumb()
  20. if e != nil {
  21. // serve a default no preview is available
  22. http.ServeFile(w, r, config.UploadsDir.ThumbDefault)
  23. log.Error("error creating preview image", ul, e)
  24. return
  25. }
  26. }
  27. if fileExists(ul.thumbPath()) {
  28. http.ServeFile(w, r, ul.thumbPath())
  29. return
  30. } else {
  31. apiV1Client404Error(w, r, ss)
  32. }
  33. }
  34. func apiV1UploadCreateThumbnail(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  35. //time.Sleep(1 * time.Second)
  36. strId := r.URL.Path[len(apiV1Prefix+"upload-as-thumbnail/"):] //remove prefix
  37. if strId == "" {
  38. apiV1Client404Error(w, r, ss)
  39. return
  40. }
  41. ul, e := getRequestedUpload(strId, w, r, ss)
  42. if e != nil {
  43. return
  44. }
  45. // see if a thumbnail is available already
  46. if !fileExists(ul.thumbPath()) {
  47. e = ul.convertUploadsToThumb()
  48. if e != nil {
  49. log.Error("error creating thumbNail image", ul, e)
  50. }
  51. }
  52. if fileExists(ul.thumbPath()) {
  53. apiV1SendJson(true, w, r, ss)
  54. return
  55. } else {
  56. apiV1SendJson(false, w, r, ss)
  57. }
  58. }