model.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package model
  2. const (
  3. _defaultWmPaddingX = 10
  4. _defaultWmPaddingY = 10
  5. _defaultWmScale = float64(1) / 24
  6. )
  7. // Result upload result
  8. type Result struct {
  9. Location string `json:"location"`
  10. Etag string `json:"etag"`
  11. }
  12. // ResultWm watermark result
  13. type ResultWm struct {
  14. Location string `json:"location"`
  15. Md5 string `json:"md5"`
  16. Height int `json:"height"`
  17. Width int `json:"width"`
  18. }
  19. // UploadParam upload params
  20. type UploadParam struct {
  21. Bucket string `form:"bucket" json:"bucket" validate:"required" `
  22. ContentType string `form:"content_type" json:"content_type"`
  23. Dir string `form:"dir" json:"dir"`
  24. FileName string `form:"file_name" json:"file_name"`
  25. WmKey string `form:"wm_key" json:"wm_key"`
  26. WmText string `form:"wm_text" json:"wm_text"`
  27. WmPaddingX int `form:"wm_padding_x" json:"wm_padding_x"`
  28. WmPaddingY int `form:"wm_padding_y" json:"wm_padding_y"`
  29. WmScale float64 `form:"wm_scale" json:"wm_scale"`
  30. }
  31. // WMInit init watermark default value.
  32. func (up *UploadParam) WMInit() {
  33. if up.WmKey != "" || up.WmText != "" {
  34. if up.WmPaddingX < 0 {
  35. up.WmPaddingX = _defaultWmPaddingX
  36. }
  37. if up.WmPaddingY < 0 {
  38. up.WmPaddingY = _defaultWmPaddingY
  39. }
  40. if up.WmScale <= 0 {
  41. up.WmScale = _defaultWmScale
  42. }
  43. }
  44. }