check file exists
This commit is contained in:
parent
2361ac8f17
commit
65355f0ea0
@ -143,3 +143,23 @@ func (s *Service) FileCreateChunk(c *gin.Context) {
|
||||
"checksum": chunk.Sum,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Service) FileExists(c *gin.Context) {
|
||||
checksum := c.Param("checksum")
|
||||
if len(checksum) != 40 {
|
||||
s.Error(c, http.StatusBadRequest, photoserrors.ErrStoreBadChecksum)
|
||||
return
|
||||
}
|
||||
|
||||
var fileExists int64
|
||||
if err := s.DB.Model(&models.File{}).Where("checksum = ?", checksum).Count(&fileExists).Error; err != nil {
|
||||
s.Error(c, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
if fileExists > 0 {
|
||||
c.Status(http.StatusOK)
|
||||
} else {
|
||||
c.Status(http.StatusNotFound)
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ func (s *Service) SetupRoutes() {
|
||||
album.Use(s.RequireSession)
|
||||
album.POST("", s.FileCreate)
|
||||
album.POST("/chunk", s.FileCreateChunk)
|
||||
album.HEAD("/:checksum", s.FileExists)
|
||||
|
||||
s.Gin.NoRoute(func(c *gin.Context) {
|
||||
s.Error(c, http.StatusNotFound, photoserrors.ErrReqNotFound)
|
||||
|
Loading…
x
Reference in New Issue
Block a user