fux
This commit is contained in:
1 parent
fd83a7c523
commit
edbbf127ba
12 files changed
+246
-207
No files matched your search
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/billing"
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/catalog"
|
||||
"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"
|
||||
@@ -22,6 +23,7 @@ type v1StartProcessRequest struct {
|
||||
RawProductIDs []string `json:"raw_product_ids"`
|
||||
ProcessingType json.RawMessage `json:"processing_type"`
|
||||
ProcessingTypes []string `json:"processing_types"`
|
||||
Language string `json:"language"`
|
||||
Items []catalog.V1ProcessItem `json:"items"`
|
||||
}
|
||||
|
||||
@@ -143,7 +145,34 @@ func (s *Server) handleV1StartProcess(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
jobs, err := s.startV1Jobs(r.Context(), cid, uid, rawIDs, storageType)
|
||||
var jobs []processing.Job
|
||||
var err error
|
||||
if strings.TrimSpace(body.Language) != "" {
|
||||
lang := company.NormalizeLanguage(body.Language)
|
||||
if !company.IsAllowedLanguage(lang) {
|
||||
v1Err(w, http.StatusBadRequest, "validation_error", "unsupported processing language")
|
||||
return
|
||||
}
|
||||
enabled := company.LoadContentLanguages(r.Context(), s.Pool, cid)
|
||||
allowed := false
|
||||
for _, candidate := range enabled {
|
||||
if candidate == lang {
|
||||
allowed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !allowed {
|
||||
v1Err(w, http.StatusBadRequest, "validation_error", "language not enabled for this company")
|
||||
return
|
||||
}
|
||||
if s.testStartJobs != nil {
|
||||
jobs, err = s.startV1Jobs(r.Context(), cid, uid, rawIDs, storageType)
|
||||
} else {
|
||||
jobs, err = s.Processing.StartAPIJobWithTypesInLanguage(r.Context(), cid, uid, rawIDs, storageType, nil, lang)
|
||||
}
|
||||
} else {
|
||||
jobs, err = s.startV1Jobs(r.Context(), cid, uid, rawIDs, storageType)
|
||||
}
|
||||
if err != nil {
|
||||
v1ErrFromProcessing(w, err)
|
||||
return
|
||||
@@ -411,10 +440,6 @@ func (s *Server) assertV1ProcessGates(ctx context.Context, companyID uuid.UUID,
|
||||
RequiresAI: billing.ProcessingTypeRequiresAI(processingType) || billing.ProcessingTypeIsEmailCampaignAI(processingType),
|
||||
RequiresEPREL: billing.ProcessingTypeRequiresEPREL(processingType),
|
||||
}
|
||||
if rates, err := s.Billing.ContentRates(ctx, companyID); err == nil {
|
||||
if units, err := billing.ContentDebitUnits(nil, processingType, rates); err == nil {
|
||||
opts.CreditsPerProduct = float64(units) / 10000
|
||||
}
|
||||
}
|
||||
opts.CreditsPerProduct = 1
|
||||
return s.Billing.AssertCanStartProcessing(ctx, companyID, batchSize, opts)
|
||||
}
|
||||
Reference in new issue
Block a user