-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
51 lines (45 loc) · 1.04 KB
/
response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"log"
"net/url"
"path"
"time"
"github.com/weaming/golib/utils"
"github.com/weaming/photobox/imageupload"
)
type UploadResponse struct {
Image *imageupload.Image `json:"image"`
Thumb *imageupload.Image `json:"thumb"`
Data *ImagePathUrl `json:"data"`
}
type ImagePathUrl struct {
OriginPath string `json:"path"`
ThumbPath string `json:"thumb_path"`
OriginURL string `json:"url"`
ThumbURL string `json:"thumb_url"`
}
func generateImagePathUrl(hash, format string) ImagePathUrl {
now := time.Now()
if format == "jpeg" {
format = "jpg"
}
suffix := path.Join(utils.FormatDateTime("%Y/%m/%d", now), fmt.Sprintf("%d_%v.%v", now.Unix(), hash, format))
o, t := path.Join("origin", suffix), path.Join("thumb", suffix)
return ImagePathUrl{
o, t,
joinURI(ImageDomain, o),
joinURI(ImageDomain, t),
}
}
func joinURI(base, uri string) string {
u, err := url.Parse(uri)
if err != nil {
log.Fatal(err)
}
b, err := url.Parse(base)
if err != nil {
log.Fatal(err)
}
return b.ResolveReference(u).String()
}