fux
This commit is contained in:
1 parent
fd83a7c523
commit
edbbf127ba
12 files changed
+246
-207
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/billing"
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/company"
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/processing"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/google/uuid"
|
||||
@@ -19,6 +20,7 @@ type startProcessingJobRequest struct {
|
||||
RawProductIDs []string `json:"raw_product_ids"`
|
||||
ProcessingType string `json:"processing_type"`
|
||||
ProcessingTypes []string `json:"processing_types"`
|
||||
Language string `json:"language"`
|
||||
}
|
||||
|
||||
func (s *Server) handleStartProcessingJob(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -49,14 +51,36 @@ func (s *Server) handleStartProcessingJob(w http.ResponseWriter, r *http.Request
|
||||
return
|
||||
}
|
||||
}
|
||||
// If unspecified, resolve the company's primary language. Do not turn a
|
||||
// single-language request into an all-company-language job.
|
||||
targetLang := company.NormalizeLanguage(body.Language)
|
||||
if targetLang == "" {
|
||||
targetLang = company.LoadLanguage(r.Context(), s.Pool, cid)
|
||||
}
|
||||
if !company.IsAllowedLanguage(targetLang) {
|
||||
Error(w, http.StatusBadRequest, "unsupported processing language")
|
||||
return
|
||||
}
|
||||
enabled := company.LoadContentLanguages(r.Context(), s.Pool, cid)
|
||||
allowed := false
|
||||
for _, lang := range enabled {
|
||||
if lang == targetLang {
|
||||
allowed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !allowed {
|
||||
Error(w, http.StatusBadRequest, "language not enabled for this company")
|
||||
return
|
||||
}
|
||||
// The shared handler serves session dashboard jobs and /api/v1/process.
|
||||
// Public API results should be directly visible in the Processed catalog tab.
|
||||
var jobs []processing.Job
|
||||
var err error
|
||||
if strings.HasPrefix(r.URL.Path, "/api/v1/") {
|
||||
jobs, err = s.Processing.StartAPIJobWithTypes(r.Context(), cid, uid, ids, body.ProcessingType, body.ProcessingTypes)
|
||||
jobs, err = s.Processing.StartAPIJobWithTypesInLanguage(r.Context(), cid, uid, ids, body.ProcessingType, body.ProcessingTypes, targetLang)
|
||||
} else {
|
||||
jobs, err = s.Processing.StartJobWithTypes(r.Context(), cid, uid, ids, body.ProcessingType, body.ProcessingTypes)
|
||||
jobs, err = s.Processing.StartJobWithTypesInLanguage(r.Context(), cid, uid, ids, body.ProcessingType, body.ProcessingTypes, targetLang)
|
||||
}
|
||||
if err != nil {
|
||||
if writePlanGate(w, err) {
|
||||
|
||||
Reference in new issue
Block a user