2020-02-26 16:50:28 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2020-06-25 12:54:04 +00:00
|
|
|
"github.com/photoprism/photoprism/internal/acl"
|
2020-02-26 16:50:28 +00:00
|
|
|
"github.com/photoprism/photoprism/internal/query"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GET /api/v1/files/:hash
|
|
|
|
//
|
|
|
|
// Parameters:
|
2020-04-08 11:24:06 +00:00
|
|
|
// hash: string SHA-1 hash of the file
|
2020-06-25 12:54:04 +00:00
|
|
|
func GetFile(router *gin.RouterGroup) {
|
2020-02-26 16:50:28 +00:00
|
|
|
router.GET("/files/:hash", func(c *gin.Context) {
|
2020-06-25 12:54:04 +00:00
|
|
|
s := Auth(SessionID(c), acl.ResourceFiles, acl.ActionRead)
|
|
|
|
|
|
|
|
if s.Invalid() {
|
2020-02-26 16:50:28 +00:00
|
|
|
c.AbortWithStatusJSON(http.StatusUnauthorized, ErrUnauthorized)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-05-08 13:41:01 +00:00
|
|
|
p, err := query.FileByHash(c.Param("hash"))
|
2020-02-26 16:50:28 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
c.AbortWithStatusJSON(http.StatusNotFound, ErrPhotoNotFound)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, p)
|
|
|
|
})
|
|
|
|
}
|