Files
multiarch-docker-images/archivist/internal/tools/routes.go
T
1224ff916d Archivist : page Outils + outil « Recherche des fichiers perdus » (US-40, US-41) (#16)
* Add tools page with find-lost-files consistency tool (US-40, US-41)

Co-authored-by: napnap75 <napnap75@users.noreply.github.com>

* tools page: hide the job panel when there is nothing to show, guard against undefined rendering

Co-authored-by: napnap75 <napnap75@users.noreply.github.com>

* inbox: leave non-PDF objects in place, never imported (US-12)

Co-authored-by: napnap75 <napnap75@users.noreply.github.com>

---------

Co-authored-by: Vibe Nuage Agent <vibe@mistral.ai>
Co-authored-by: napnap75 <napnap75@users.noreply.github.com>
2026-11-12 19:35:56 +01:00

56 lines
1.8 KiB
Go

// Routes.go binds the tools-page application routes: the tool list, the
// run trigger, the live job state and the cancel action. Superuser-only,
// like every /api/archivist route.
package tools
import (
"ganigeorgiev.com/pocketbase/pocketbase/core"
)
// BindRoutes registers the tools routes on the PocketBase router.
func BindRoutes(app core.App, s3 S3Store) {
app.OnServe().BindFunc(func(e *core.ServeEvent) error {
e.Router.GET("/api/archivist/tools", func(re *core.RequestEvent) error {
if !re.HasSuperuserAuth() {
return re.ForbiddenError("superusers only", nil)
}
job := LatestJob()
var state map[string]any
if job != nil {
state = job.State()
}
return re.JSON(200, map[string]any{"tools": Descriptors(), "job": state})
})
e.Router.POST("/api/archivist/tools/{id}/run", func(re *core.RequestEvent) error {
if !re.HasSuperuserAuth() {
return re.ForbiddenError("superusers only", nil)
}
job, err := Start(re.App, s3, re.Request.PathValue("id"))
if err != nil {
return re.JSON(409, map[string]any{"message": err.Error()})
}
return re.JSON(200, job.State())
})
e.Router.GET("/api/archivist/tools/jobs/{id}", func(re *core.RequestEvent) error {
if !re.HasSuperuserAuth() {
return re.ForbiddenError("superusers only", nil)
}
job := JobByID(re.Request.PathValue("id"))
if job == nil {
return re.JSON(404, map[string]any{"message": "job not found"})
}
return re.JSON(200, job.State())
})
e.Router.POST("/api/archivist/tools/jobs/{id}/cancel", func(re *core.RequestEvent) error {
if !re.HasSuperuserAuth() {
return re.ForbiddenError("superusers only", nil)
}
if !Cancel(re.Request.PathValue("id")) {
return re.JSON(404, map[string]any{"message": "no running job with this id"})
}
return re.JSON(200, map[string]any{"status": "cancelling"})
})
return e.Next()
})
}