/
share.go
69 lines (52 loc) Β· 1.83 KB
/
share.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package api
import (
"net/http"
"path"
"github.com/gin-gonic/gin"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/get"
"github.com/photoprism/photoprism/internal/query"
"github.com/photoprism/photoprism/pkg/clean"
)
// Shares handles link share
//
// GET /s/:token/...
func Shares(router *gin.RouterGroup) {
router.GET("/:token", func(c *gin.Context) {
conf := get.Config()
token := clean.Token(c.Param("token"))
links := entity.FindValidLinks(token, "")
if len(links) == 0 {
log.Debugf("share: invalid token")
c.Redirect(http.StatusTemporaryRedirect, conf.BaseUri(""))
return
}
clientConfig := conf.ClientShare()
clientConfig.SiteUrl = clientConfig.SiteUrl + path.Join("s", token)
uri := conf.BaseUri("/library/albums")
c.HTML(http.StatusOK, "share.gohtml", gin.H{"shared": gin.H{"token": token, "uri": uri}, "config": clientConfig})
})
router.GET("/:token/:shared", func(c *gin.Context) {
conf := get.Config()
token := clean.Token(c.Param("token"))
shared := clean.Token(c.Param("shared"))
links := entity.FindValidLinks(token, shared)
if len(links) < 1 {
log.Debugf("share: invalid token or slug")
c.Redirect(http.StatusTemporaryRedirect, conf.BaseUri(""))
return
}
uid := links[0].ShareUID
clientConfig := conf.ClientShare()
clientConfig.SiteUrl = clientConfig.SiteUrl + path.Join("s", token, uid)
clientConfig.SitePreview = clientConfig.SiteUrl + "/preview"
if a, err := query.AlbumByUID(uid); err == nil {
clientConfig.SiteCaption = a.AlbumTitle
if a.AlbumDescription != "" {
clientConfig.SiteDescription = a.AlbumDescription
}
}
uri := conf.BaseUri(path.Join("/library/albums", uid, shared))
c.HTML(http.StatusOK, "share.gohtml", gin.H{"shared": gin.H{"token": token, "uri": uri}, "config": clientConfig})
})
}