2020-02-26 17:50:28 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2022-04-15 09:42:07 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/clean"
|
2021-12-14 18:34:52 +01:00
|
|
|
|
2020-02-26 17:50:28 +01:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2021-11-26 14:28:50 +01:00
|
|
|
// GetFile returns file details as JSON.
|
2020-02-26 17:50:28 +01:00
|
|
|
//
|
2021-11-26 14:28:50 +01:00
|
|
|
// Route: GET /api/v1/files/:hash
|
|
|
|
// Params:
|
|
|
|
// - 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
|
|
|
|
}
|
|
|
|
|
2022-04-15 09:42:07 +02:00
|
|
|
p, err := query.FileByHash(clean.Token(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)
|
|
|
|
})
|
|
|
|
}
|