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