fux
This commit is contained in:
1 parent
fd83a7c523
commit
edbbf127ba
12 files changed
+246
-207
No files matched your search
@@ -120,21 +120,13 @@ func (s *Server) handleCompanyContentCosts(w http.ResponseWriter, r *http.Reques
|
||||
Error(w, http.StatusUnauthorized, "unauthorized")
|
||||
return
|
||||
}
|
||||
rates, err := s.Billing.ContentRates(r.Context(), cid)
|
||||
if err != nil {
|
||||
LogAndError(w, http.StatusInternalServerError, "could not load credit costs", err)
|
||||
return
|
||||
}
|
||||
out := make(map[string]float64, len(rates))
|
||||
for key, units := range rates {
|
||||
out[key] = float64(units) / 10000
|
||||
}
|
||||
mode := "outputs"
|
||||
if _, ok := rates["product"]; ok {
|
||||
mode = "product"
|
||||
}
|
||||
// Flat charge for one product in one selected language. Never derive a
|
||||
// displayed estimate from per-output admin rates or the EUR/credit value.
|
||||
w.Header().Set("Cache-Control", "private, no-store")
|
||||
JSON(w, http.StatusOK, map[string]any{"mode": mode, "credits": out})
|
||||
JSON(w, http.StatusOK, map[string]any{
|
||||
"mode": "product",
|
||||
"credits": map[string]float64{"product": 1},
|
||||
})
|
||||
}
|
||||
|
||||
// Monetary credit valuation is an admin reference rate. Stripe invoices, pack
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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