2020-02-26 17:50:28 +01:00
|
|
|
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:
|
2020-04-08 13:24:06 +02:00
|
|
|
// hash: string SHA-1 hash of the file
|
2020-02-26 17:50:28 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
c.AbortWithStatusJSON(http.StatusNotFound, ErrPhotoNotFound)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, p)
|
|
|
|
})
|
|
|
|
}
|