2019-06-15 20:03:54 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2019-11-11 21:10:41 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2019-06-15 20:03:54 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/photoprism"
|
|
|
|
)
|
|
|
|
|
|
|
|
var indexer *photoprism.Indexer
|
|
|
|
|
|
|
|
func initIndexer(conf *config.Config) {
|
|
|
|
if indexer != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
tensorFlow := photoprism.NewTensorFlow(conf)
|
|
|
|
|
|
|
|
indexer = photoprism.NewIndexer(conf, tensorFlow)
|
|
|
|
}
|
|
|
|
|
|
|
|
// POST /api/v1/index
|
|
|
|
func Index(router *gin.RouterGroup, conf *config.Config) {
|
|
|
|
router.POST("/index", func(c *gin.Context) {
|
2019-11-11 21:10:41 +01:00
|
|
|
if Unauthorized(c, conf) {
|
|
|
|
c.AbortWithStatusJSON(http.StatusUnauthorized, ErrUnauthorized)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-06-15 20:03:54 +02:00
|
|
|
start := time.Now()
|
|
|
|
path := conf.OriginalsPath()
|
|
|
|
|
|
|
|
log.Infof("indexing photos in %s", path)
|
|
|
|
|
|
|
|
initIndexer(conf)
|
|
|
|
|
|
|
|
indexer.IndexAll()
|
|
|
|
|
|
|
|
elapsed := time.Since(start)
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"message": fmt.Sprintf("indexing completed in %s", elapsed)})
|
|
|
|
})
|
|
|
|
}
|