2020-06-22 20:15:08 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
2020-06-25 14:54:04 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/service"
|
2020-06-22 20:15:08 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func shareHandler(c *gin.Context, conf *config.Config) {
|
|
|
|
token := c.Param("token")
|
|
|
|
links := entity.FindLinks(token, "")
|
|
|
|
|
|
|
|
if len(links) == 0 {
|
|
|
|
log.Warnf("sharing: invalid token %s", txt.Quote(token))
|
|
|
|
c.Redirect(http.StatusTemporaryRedirect, "/")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-06-25 01:20:58 +02:00
|
|
|
clientConfig := conf.GuestConfig()
|
2020-06-22 20:15:08 +02:00
|
|
|
|
|
|
|
c.HTML(http.StatusOK, "share.tmpl", gin.H{"config": clientConfig})
|
|
|
|
}
|
|
|
|
|
2020-06-25 14:54:04 +02:00
|
|
|
func InitShare(router *gin.RouterGroup) {
|
|
|
|
conf := service.Config()
|
|
|
|
|
2020-06-22 20:15:08 +02:00
|
|
|
router.GET("/:token", func(c *gin.Context) {
|
|
|
|
shareHandler(c, conf)
|
|
|
|
})
|
|
|
|
|
|
|
|
router.GET("/:token/*uid", func(c *gin.Context) {
|
|
|
|
shareHandler(c, conf)
|
|
|
|
})
|
|
|
|
}
|