feat(custom): CNY native billing, daily check-in button, subscription plans page, usage docs and promo banner
Based on QuantumNous/new-api v1.0.0-rc.36 (shallow history squashed). - CNY quota display mode: RMB-denominated top-up and crediting across Epay/Waffo channels - New CheckinButton in both authenticated and public headers (Turnstile supported) - New /subscribe page with public plan snapshot, Alipay/balance payment, auto group upgrade/reset - New /docs 12-section beginner guide with anchor navigation - New home PromoBanner linking to /docs; i18n synced (en/zh/zh-TW/fr/ja/ru/vi) - README: document custom features, live demo https://ai.88531.cn
This commit is contained in:
commit
14a9acd368
2368 files changed
+551035
No files matched your search
@@ -0,0 +1,61 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
"github.com/QuantumNous/new-api/dto"
|
||||
"github.com/QuantumNous/new-api/model"
|
||||
)
|
||||
|
||||
// BuildTaskPluginView converts a persisted task into the deliberately narrow
|
||||
// public shape permitted at JavaScript plugin boundaries.
|
||||
func BuildTaskPluginView(task *model.Task) (dto.TaskView, error) {
|
||||
createdAt := task.CreatedAt
|
||||
if createdAt == 0 {
|
||||
createdAt = task.SubmitTime
|
||||
}
|
||||
view := dto.TaskView{
|
||||
TaskID: task.TaskID,
|
||||
Platform: string(task.Platform),
|
||||
Status: string(task.Status),
|
||||
Progress: task.Progress,
|
||||
FailReason: task.FailReason,
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: task.UpdatedAt,
|
||||
FinishedAt: task.FinishTime,
|
||||
}
|
||||
if len(task.Data) > 0 {
|
||||
if err := common.Unmarshal(task.Data, &view.Data); err != nil {
|
||||
return dto.TaskView{}, err
|
||||
}
|
||||
view.Data = replacePrivateTaskID(view.Data, task.PrivateData.UpstreamTaskID, task.TaskID)
|
||||
}
|
||||
return view, nil
|
||||
}
|
||||
|
||||
// replacePrivateTaskID rewrites exact private IDs only in known task-ID fields.
|
||||
// Map keys and opaque strings, including URLs containing the ID, are preserved.
|
||||
func replacePrivateTaskID(value any, privateTaskID, publicTaskID string) any {
|
||||
if privateTaskID == "" || privateTaskID == publicTaskID {
|
||||
return value
|
||||
}
|
||||
switch typed := value.(type) {
|
||||
case []any:
|
||||
replaced := make([]any, len(typed))
|
||||
for index, item := range typed {
|
||||
replaced[index] = replacePrivateTaskID(item, privateTaskID, publicTaskID)
|
||||
}
|
||||
return replaced
|
||||
case map[string]any:
|
||||
replaced := make(map[string]any, len(typed))
|
||||
for key, item := range typed {
|
||||
if (key == "id" || key == "task_id" || key == "taskId") && item == privateTaskID {
|
||||
replaced[key] = publicTaskID
|
||||
continue
|
||||
}
|
||||
replaced[key] = replacePrivateTaskID(item, privateTaskID, publicTaskID)
|
||||
}
|
||||
return replaced
|
||||
default:
|
||||
return value
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user