-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
52 lines (45 loc) · 1.09 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
52
package main
import (
"fmt"
"log"
"net/url"
"path"
"time"
"github.com/miaomiaotech/photobox-lite/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 genImgPathUrl(hash, format string) ImagePathUrl {
now := time.Now()
if format == "jpeg" {
format = "jpg"
}
suffix := path.Join(now.Format(dateFormat), fmt.Sprintf("%v.%v", hash, format))
origin, thumb := path.Join("origin", suffix), path.Join("thumb", imageupload.ReplaceFileExt(suffix, "jpg"))
return ImagePathUrl{
OriginPath: origin,
ThumbPath: thumb,
OriginURL: joinURI(ImageDomain, origin),
ThumbURL: joinURI(ImageDomain, thumb),
}
}
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()
}