mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 08:44:04 +01:00
Initial API and entities for link sharing
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
@@ -5,13 +5,15 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/event"
|
||||
"github.com/photoprism/photoprism/internal/query"
|
||||
"github.com/photoprism/photoprism/pkg/txt"
|
||||
)
|
||||
|
||||
// GET /api/v1/files/:hash
|
||||
//
|
||||
// Parameters:
|
||||
// hash: string The sha1 hash of a file
|
||||
// hash: string SHA-1 hash of the file
|
||||
func GetFile(router *gin.RouterGroup, conf *config.Config) {
|
||||
router.GET("/files/:hash", func(c *gin.Context) {
|
||||
if Unauthorized(c, conf) {
|
||||
@@ -30,3 +32,37 @@ func GetFile(router *gin.RouterGroup, conf *config.Config) {
|
||||
c.JSON(http.StatusOK, p)
|
||||
})
|
||||
}
|
||||
|
||||
// POST /api/v1/files/:hash/link
|
||||
//
|
||||
// Parameters:
|
||||
// hash: string SHA-1 hash of the file
|
||||
func LinkFile(router *gin.RouterGroup, conf *config.Config) {
|
||||
router.POST("/files/:hash/link", func(c *gin.Context) {
|
||||
if Unauthorized(c, conf) {
|
||||
c.AbortWithStatusJSON(http.StatusUnauthorized, ErrUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
db := conf.Db()
|
||||
q := query.New(db)
|
||||
|
||||
m, err := q.FileByUUID(c.Param("hash"))
|
||||
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusNotFound, ErrAlbumNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
if link, err := newLink(c); err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": txt.UcFirst(err.Error())})
|
||||
return
|
||||
} else {
|
||||
db.Model(&m).Association("Links").Append(link)
|
||||
}
|
||||
|
||||
event.Success("created file share link")
|
||||
|
||||
c.JSON(http.StatusOK, m)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user