722d7dd421
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
31 lines
655 B
Go
31 lines
655 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/photoprism/photoprism/internal/config"
|
|
"github.com/photoprism/photoprism/internal/query"
|
|
)
|
|
|
|
// GET /api/v1/files/:hash
|
|
//
|
|
// Parameters:
|
|
// 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) {
|
|
c.AbortWithStatusJSON(http.StatusUnauthorized, ErrUnauthorized)
|
|
return
|
|
}
|
|
|
|
p, err := query.FileByHash(c.Param("hash"))
|
|
|
|
if err != nil {
|
|
c.AbortWithStatusJSON(http.StatusNotFound, ErrPhotoNotFound)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, p)
|
|
})
|
|
}
|