Раскладка файлов после распознавния
This commit is contained in:
+38
-17
@@ -46,11 +46,13 @@ type Deps struct {
|
||||
Ingestor Ingestor
|
||||
Commander Commander
|
||||
Reader Reader
|
||||
Reviewer Reviewer
|
||||
}
|
||||
|
||||
type server struct {
|
||||
deps Deps
|
||||
index *template.Template
|
||||
deps Deps
|
||||
index *template.Template
|
||||
review *template.Template
|
||||
}
|
||||
|
||||
// NewRouter собирает HTTP-обработчик сервиса.
|
||||
@@ -59,7 +61,13 @@ func NewRouter(d Deps) (http.Handler, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s := &server{deps: d, index: index}
|
||||
review, err := template.New("review.html").
|
||||
Funcs(template.FuncMap{"add": func(a, b int) int { return a + b }}).
|
||||
ParseFS(web.FS, "templates/review.html")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s := &server{deps: d, index: index, review: review}
|
||||
|
||||
r := chi.NewRouter()
|
||||
r.Use(middleware.RequestID)
|
||||
@@ -73,6 +81,15 @@ func NewRouter(d Deps) (http.Handler, error) {
|
||||
r.Post("/ui/downloads", s.handleUIAdd)
|
||||
r.Post("/ui/downloads/{id}/cancel", s.handleUICancel)
|
||||
|
||||
// Веб-UI: ревью раскладки.
|
||||
r.Get("/review/{id}", s.handleReview)
|
||||
r.Post("/ui/downloads/{id}/apply", s.handleApply)
|
||||
r.Post("/ui/downloads/{id}/refine", s.handleRefine)
|
||||
r.Post("/ui/downloads/{id}/type", s.handleSetType)
|
||||
r.Post("/ui/downloads/{id}/ignore", s.handleIgnore)
|
||||
r.Post("/ui/downloads/{id}/defer", s.handleDefer)
|
||||
r.Post("/ui/downloads/{id}/undo", s.handleUndo)
|
||||
|
||||
// REST API.
|
||||
r.Route("/api", func(r chi.Router) {
|
||||
r.Get("/downloads", s.handleAPIList)
|
||||
@@ -97,13 +114,15 @@ type indexView struct {
|
||||
}
|
||||
|
||||
type downloadView struct {
|
||||
ID int64
|
||||
Source string
|
||||
Infohash string
|
||||
Context string
|
||||
State string
|
||||
Error string
|
||||
Terminal bool
|
||||
ID int64
|
||||
Source string
|
||||
Infohash string
|
||||
Context string
|
||||
State string
|
||||
Error string
|
||||
Terminal bool
|
||||
Reviewable bool // review/deferred — есть экран ревью
|
||||
Undoable bool // done — можно откатить раскладку
|
||||
}
|
||||
|
||||
func (s *server) handleIndex(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -272,13 +291,15 @@ func toDTO(d store.Download) downloadDTO {
|
||||
|
||||
func toView(d store.Download) downloadView {
|
||||
return downloadView{
|
||||
ID: d.ID,
|
||||
Source: shorten(d.SourceRef, 64),
|
||||
Infohash: d.Infohash.String,
|
||||
Context: d.Context,
|
||||
State: string(d.State),
|
||||
Error: d.ErrorMsg.String,
|
||||
Terminal: d.State.IsTerminal(),
|
||||
ID: d.ID,
|
||||
Source: shorten(d.SourceRef, 64),
|
||||
Infohash: d.Infohash.String,
|
||||
Context: d.Context,
|
||||
State: string(d.State),
|
||||
Error: d.ErrorMsg.String,
|
||||
Terminal: d.State.IsTerminal(),
|
||||
Reviewable: d.State == store.StateReview || d.State == store.StateDeferred,
|
||||
Undoable: d.State == store.StateDone,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user