1d89858e4c
* Backend: Add API endpoint for getting files by sha1 hash * Test: Add test for Api.GetFile
33 lines
706 B
Go
33 lines
706 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 The sha1 hash of a 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
|
|
}
|
|
|
|
q := query.New(conf.OriginalsPath(), conf.Db())
|
|
p, err := q.FindFileByHash(c.Param("hash"))
|
|
|
|
if err != nil {
|
|
c.AbortWithStatusJSON(http.StatusNotFound, ErrPhotoNotFound)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, p)
|
|
})
|
|
}
|