新增功能: - 新增 Sora 账号管理和 OAuth 认证 - 新增 Sora 视频/图片生成 API 网关 - 新增 Sora 任务调度和缓存机制 - 新增 Sora 使用统计和计费支持 - 前端增加 Sora 平台配置界面 安全修复(代码审核): - [SEC-001] 限制媒体下载响应体大小(图片 20MB、视频 200MB),防止 DoS 攻击 - [SEC-002] 限制 SDK API 响应大小(1MB),防止内存耗尽 - [SEC-003] 修复 SSRF 风险,添加 URL 验证并强制使用代理配置 BUG 修复(代码审核): - [BUG-001] 修复 for 循环内 defer 累积导致的资源泄漏 - [BUG-002] 修复图片并发槽位获取失败时已持有锁未释放的永久泄漏 性能优化(代码审核): - [PERF-001] 添加 Sentinel Token 缓存(3 分钟有效期),减少 PoW 计算开销 技术细节: - 使用 io.LimitReader 限制所有外部输入的大小 - 添加 urlvalidator 验证防止 SSRF 攻击 - 使用 sync.Map 实现线程安全的包级缓存 - 优化并发槽位管理,添加 releaseAll 模式防止泄漏 影响范围: - 后端:新增 Sora 相关数据模型、服务、网关和管理接口 - 前端:新增 Sora 平台配置、账号管理和监控界面 - 配置:新增 Sora 相关配置项和环境变量 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
711 lines
21 KiB
Go
711 lines
21 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/Wei-Shaw/sub2api/ent/predicate"
|
|
"github.com/Wei-Shaw/sub2api/ent/soratask"
|
|
)
|
|
|
|
// SoraTaskUpdate is the builder for updating SoraTask entities.
|
|
type SoraTaskUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *SoraTaskMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the SoraTaskUpdate builder.
|
|
func (_u *SoraTaskUpdate) Where(ps ...predicate.SoraTask) *SoraTaskUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetTaskID sets the "task_id" field.
|
|
func (_u *SoraTaskUpdate) SetTaskID(v string) *SoraTaskUpdate {
|
|
_u.mutation.SetTaskID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTaskID sets the "task_id" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdate) SetNillableTaskID(v *string) *SoraTaskUpdate {
|
|
if v != nil {
|
|
_u.SetTaskID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetAccountID sets the "account_id" field.
|
|
func (_u *SoraTaskUpdate) SetAccountID(v int64) *SoraTaskUpdate {
|
|
_u.mutation.ResetAccountID()
|
|
_u.mutation.SetAccountID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAccountID sets the "account_id" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdate) SetNillableAccountID(v *int64) *SoraTaskUpdate {
|
|
if v != nil {
|
|
_u.SetAccountID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddAccountID adds value to the "account_id" field.
|
|
func (_u *SoraTaskUpdate) AddAccountID(v int64) *SoraTaskUpdate {
|
|
_u.mutation.AddAccountID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetModel sets the "model" field.
|
|
func (_u *SoraTaskUpdate) SetModel(v string) *SoraTaskUpdate {
|
|
_u.mutation.SetModel(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableModel sets the "model" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdate) SetNillableModel(v *string) *SoraTaskUpdate {
|
|
if v != nil {
|
|
_u.SetModel(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPrompt sets the "prompt" field.
|
|
func (_u *SoraTaskUpdate) SetPrompt(v string) *SoraTaskUpdate {
|
|
_u.mutation.SetPrompt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePrompt sets the "prompt" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdate) SetNillablePrompt(v *string) *SoraTaskUpdate {
|
|
if v != nil {
|
|
_u.SetPrompt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *SoraTaskUpdate) SetStatus(v string) *SoraTaskUpdate {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdate) SetNillableStatus(v *string) *SoraTaskUpdate {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetProgress sets the "progress" field.
|
|
func (_u *SoraTaskUpdate) SetProgress(v float64) *SoraTaskUpdate {
|
|
_u.mutation.ResetProgress()
|
|
_u.mutation.SetProgress(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableProgress sets the "progress" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdate) SetNillableProgress(v *float64) *SoraTaskUpdate {
|
|
if v != nil {
|
|
_u.SetProgress(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddProgress adds value to the "progress" field.
|
|
func (_u *SoraTaskUpdate) AddProgress(v float64) *SoraTaskUpdate {
|
|
_u.mutation.AddProgress(v)
|
|
return _u
|
|
}
|
|
|
|
// SetResultUrls sets the "result_urls" field.
|
|
func (_u *SoraTaskUpdate) SetResultUrls(v string) *SoraTaskUpdate {
|
|
_u.mutation.SetResultUrls(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableResultUrls sets the "result_urls" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdate) SetNillableResultUrls(v *string) *SoraTaskUpdate {
|
|
if v != nil {
|
|
_u.SetResultUrls(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearResultUrls clears the value of the "result_urls" field.
|
|
func (_u *SoraTaskUpdate) ClearResultUrls() *SoraTaskUpdate {
|
|
_u.mutation.ClearResultUrls()
|
|
return _u
|
|
}
|
|
|
|
// SetErrorMessage sets the "error_message" field.
|
|
func (_u *SoraTaskUpdate) SetErrorMessage(v string) *SoraTaskUpdate {
|
|
_u.mutation.SetErrorMessage(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdate) SetNillableErrorMessage(v *string) *SoraTaskUpdate {
|
|
if v != nil {
|
|
_u.SetErrorMessage(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearErrorMessage clears the value of the "error_message" field.
|
|
func (_u *SoraTaskUpdate) ClearErrorMessage() *SoraTaskUpdate {
|
|
_u.mutation.ClearErrorMessage()
|
|
return _u
|
|
}
|
|
|
|
// SetRetryCount sets the "retry_count" field.
|
|
func (_u *SoraTaskUpdate) SetRetryCount(v int) *SoraTaskUpdate {
|
|
_u.mutation.ResetRetryCount()
|
|
_u.mutation.SetRetryCount(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRetryCount sets the "retry_count" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdate) SetNillableRetryCount(v *int) *SoraTaskUpdate {
|
|
if v != nil {
|
|
_u.SetRetryCount(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddRetryCount adds value to the "retry_count" field.
|
|
func (_u *SoraTaskUpdate) AddRetryCount(v int) *SoraTaskUpdate {
|
|
_u.mutation.AddRetryCount(v)
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *SoraTaskUpdate) SetCreatedAt(v time.Time) *SoraTaskUpdate {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdate) SetNillableCreatedAt(v *time.Time) *SoraTaskUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCompletedAt sets the "completed_at" field.
|
|
func (_u *SoraTaskUpdate) SetCompletedAt(v time.Time) *SoraTaskUpdate {
|
|
_u.mutation.SetCompletedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCompletedAt sets the "completed_at" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdate) SetNillableCompletedAt(v *time.Time) *SoraTaskUpdate {
|
|
if v != nil {
|
|
_u.SetCompletedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearCompletedAt clears the value of the "completed_at" field.
|
|
func (_u *SoraTaskUpdate) ClearCompletedAt() *SoraTaskUpdate {
|
|
_u.mutation.ClearCompletedAt()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the SoraTaskMutation object of the builder.
|
|
func (_u *SoraTaskUpdate) Mutation() *SoraTaskMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *SoraTaskUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *SoraTaskUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *SoraTaskUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *SoraTaskUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *SoraTaskUpdate) check() error {
|
|
if v, ok := _u.mutation.TaskID(); ok {
|
|
if err := soratask.TaskIDValidator(v); err != nil {
|
|
return &ValidationError{Name: "task_id", err: fmt.Errorf(`ent: validator failed for field "SoraTask.task_id": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Model(); ok {
|
|
if err := soratask.ModelValidator(v); err != nil {
|
|
return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "SoraTask.model": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Status(); ok {
|
|
if err := soratask.StatusValidator(v); err != nil {
|
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "SoraTask.status": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *SoraTaskUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(soratask.Table, soratask.Columns, sqlgraph.NewFieldSpec(soratask.FieldID, field.TypeInt64))
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.TaskID(); ok {
|
|
_spec.SetField(soratask.FieldTaskID, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.AccountID(); ok {
|
|
_spec.SetField(soratask.FieldAccountID, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedAccountID(); ok {
|
|
_spec.AddField(soratask.FieldAccountID, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.Model(); ok {
|
|
_spec.SetField(soratask.FieldModel, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Prompt(); ok {
|
|
_spec.SetField(soratask.FieldPrompt, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(soratask.FieldStatus, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Progress(); ok {
|
|
_spec.SetField(soratask.FieldProgress, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedProgress(); ok {
|
|
_spec.AddField(soratask.FieldProgress, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.ResultUrls(); ok {
|
|
_spec.SetField(soratask.FieldResultUrls, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ResultUrlsCleared() {
|
|
_spec.ClearField(soratask.FieldResultUrls, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.ErrorMessage(); ok {
|
|
_spec.SetField(soratask.FieldErrorMessage, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ErrorMessageCleared() {
|
|
_spec.ClearField(soratask.FieldErrorMessage, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.RetryCount(); ok {
|
|
_spec.SetField(soratask.FieldRetryCount, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedRetryCount(); ok {
|
|
_spec.AddField(soratask.FieldRetryCount, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(soratask.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.CompletedAt(); ok {
|
|
_spec.SetField(soratask.FieldCompletedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.CompletedAtCleared() {
|
|
_spec.ClearField(soratask.FieldCompletedAt, field.TypeTime)
|
|
}
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{soratask.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// SoraTaskUpdateOne is the builder for updating a single SoraTask entity.
|
|
type SoraTaskUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *SoraTaskMutation
|
|
}
|
|
|
|
// SetTaskID sets the "task_id" field.
|
|
func (_u *SoraTaskUpdateOne) SetTaskID(v string) *SoraTaskUpdateOne {
|
|
_u.mutation.SetTaskID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTaskID sets the "task_id" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdateOne) SetNillableTaskID(v *string) *SoraTaskUpdateOne {
|
|
if v != nil {
|
|
_u.SetTaskID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetAccountID sets the "account_id" field.
|
|
func (_u *SoraTaskUpdateOne) SetAccountID(v int64) *SoraTaskUpdateOne {
|
|
_u.mutation.ResetAccountID()
|
|
_u.mutation.SetAccountID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAccountID sets the "account_id" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdateOne) SetNillableAccountID(v *int64) *SoraTaskUpdateOne {
|
|
if v != nil {
|
|
_u.SetAccountID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddAccountID adds value to the "account_id" field.
|
|
func (_u *SoraTaskUpdateOne) AddAccountID(v int64) *SoraTaskUpdateOne {
|
|
_u.mutation.AddAccountID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetModel sets the "model" field.
|
|
func (_u *SoraTaskUpdateOne) SetModel(v string) *SoraTaskUpdateOne {
|
|
_u.mutation.SetModel(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableModel sets the "model" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdateOne) SetNillableModel(v *string) *SoraTaskUpdateOne {
|
|
if v != nil {
|
|
_u.SetModel(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPrompt sets the "prompt" field.
|
|
func (_u *SoraTaskUpdateOne) SetPrompt(v string) *SoraTaskUpdateOne {
|
|
_u.mutation.SetPrompt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePrompt sets the "prompt" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdateOne) SetNillablePrompt(v *string) *SoraTaskUpdateOne {
|
|
if v != nil {
|
|
_u.SetPrompt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *SoraTaskUpdateOne) SetStatus(v string) *SoraTaskUpdateOne {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdateOne) SetNillableStatus(v *string) *SoraTaskUpdateOne {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetProgress sets the "progress" field.
|
|
func (_u *SoraTaskUpdateOne) SetProgress(v float64) *SoraTaskUpdateOne {
|
|
_u.mutation.ResetProgress()
|
|
_u.mutation.SetProgress(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableProgress sets the "progress" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdateOne) SetNillableProgress(v *float64) *SoraTaskUpdateOne {
|
|
if v != nil {
|
|
_u.SetProgress(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddProgress adds value to the "progress" field.
|
|
func (_u *SoraTaskUpdateOne) AddProgress(v float64) *SoraTaskUpdateOne {
|
|
_u.mutation.AddProgress(v)
|
|
return _u
|
|
}
|
|
|
|
// SetResultUrls sets the "result_urls" field.
|
|
func (_u *SoraTaskUpdateOne) SetResultUrls(v string) *SoraTaskUpdateOne {
|
|
_u.mutation.SetResultUrls(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableResultUrls sets the "result_urls" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdateOne) SetNillableResultUrls(v *string) *SoraTaskUpdateOne {
|
|
if v != nil {
|
|
_u.SetResultUrls(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearResultUrls clears the value of the "result_urls" field.
|
|
func (_u *SoraTaskUpdateOne) ClearResultUrls() *SoraTaskUpdateOne {
|
|
_u.mutation.ClearResultUrls()
|
|
return _u
|
|
}
|
|
|
|
// SetErrorMessage sets the "error_message" field.
|
|
func (_u *SoraTaskUpdateOne) SetErrorMessage(v string) *SoraTaskUpdateOne {
|
|
_u.mutation.SetErrorMessage(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdateOne) SetNillableErrorMessage(v *string) *SoraTaskUpdateOne {
|
|
if v != nil {
|
|
_u.SetErrorMessage(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearErrorMessage clears the value of the "error_message" field.
|
|
func (_u *SoraTaskUpdateOne) ClearErrorMessage() *SoraTaskUpdateOne {
|
|
_u.mutation.ClearErrorMessage()
|
|
return _u
|
|
}
|
|
|
|
// SetRetryCount sets the "retry_count" field.
|
|
func (_u *SoraTaskUpdateOne) SetRetryCount(v int) *SoraTaskUpdateOne {
|
|
_u.mutation.ResetRetryCount()
|
|
_u.mutation.SetRetryCount(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRetryCount sets the "retry_count" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdateOne) SetNillableRetryCount(v *int) *SoraTaskUpdateOne {
|
|
if v != nil {
|
|
_u.SetRetryCount(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddRetryCount adds value to the "retry_count" field.
|
|
func (_u *SoraTaskUpdateOne) AddRetryCount(v int) *SoraTaskUpdateOne {
|
|
_u.mutation.AddRetryCount(v)
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *SoraTaskUpdateOne) SetCreatedAt(v time.Time) *SoraTaskUpdateOne {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdateOne) SetNillableCreatedAt(v *time.Time) *SoraTaskUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCompletedAt sets the "completed_at" field.
|
|
func (_u *SoraTaskUpdateOne) SetCompletedAt(v time.Time) *SoraTaskUpdateOne {
|
|
_u.mutation.SetCompletedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCompletedAt sets the "completed_at" field if the given value is not nil.
|
|
func (_u *SoraTaskUpdateOne) SetNillableCompletedAt(v *time.Time) *SoraTaskUpdateOne {
|
|
if v != nil {
|
|
_u.SetCompletedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearCompletedAt clears the value of the "completed_at" field.
|
|
func (_u *SoraTaskUpdateOne) ClearCompletedAt() *SoraTaskUpdateOne {
|
|
_u.mutation.ClearCompletedAt()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the SoraTaskMutation object of the builder.
|
|
func (_u *SoraTaskUpdateOne) Mutation() *SoraTaskMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the SoraTaskUpdate builder.
|
|
func (_u *SoraTaskUpdateOne) Where(ps ...predicate.SoraTask) *SoraTaskUpdateOne {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (_u *SoraTaskUpdateOne) Select(field string, fields ...string) *SoraTaskUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated SoraTask entity.
|
|
func (_u *SoraTaskUpdateOne) Save(ctx context.Context) (*SoraTask, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *SoraTaskUpdateOne) SaveX(ctx context.Context) *SoraTask {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *SoraTaskUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *SoraTaskUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *SoraTaskUpdateOne) check() error {
|
|
if v, ok := _u.mutation.TaskID(); ok {
|
|
if err := soratask.TaskIDValidator(v); err != nil {
|
|
return &ValidationError{Name: "task_id", err: fmt.Errorf(`ent: validator failed for field "SoraTask.task_id": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Model(); ok {
|
|
if err := soratask.ModelValidator(v); err != nil {
|
|
return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "SoraTask.model": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Status(); ok {
|
|
if err := soratask.StatusValidator(v); err != nil {
|
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "SoraTask.status": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *SoraTaskUpdateOne) sqlSave(ctx context.Context) (_node *SoraTask, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(soratask.Table, soratask.Columns, sqlgraph.NewFieldSpec(soratask.FieldID, field.TypeInt64))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SoraTask.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := _u.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, soratask.FieldID)
|
|
for _, f := range fields {
|
|
if !soratask.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != soratask.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.TaskID(); ok {
|
|
_spec.SetField(soratask.FieldTaskID, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.AccountID(); ok {
|
|
_spec.SetField(soratask.FieldAccountID, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedAccountID(); ok {
|
|
_spec.AddField(soratask.FieldAccountID, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.Model(); ok {
|
|
_spec.SetField(soratask.FieldModel, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Prompt(); ok {
|
|
_spec.SetField(soratask.FieldPrompt, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(soratask.FieldStatus, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Progress(); ok {
|
|
_spec.SetField(soratask.FieldProgress, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedProgress(); ok {
|
|
_spec.AddField(soratask.FieldProgress, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.ResultUrls(); ok {
|
|
_spec.SetField(soratask.FieldResultUrls, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ResultUrlsCleared() {
|
|
_spec.ClearField(soratask.FieldResultUrls, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.ErrorMessage(); ok {
|
|
_spec.SetField(soratask.FieldErrorMessage, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ErrorMessageCleared() {
|
|
_spec.ClearField(soratask.FieldErrorMessage, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.RetryCount(); ok {
|
|
_spec.SetField(soratask.FieldRetryCount, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedRetryCount(); ok {
|
|
_spec.AddField(soratask.FieldRetryCount, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(soratask.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.CompletedAt(); ok {
|
|
_spec.SetField(soratask.FieldCompletedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.CompletedAtCleared() {
|
|
_spec.ClearField(soratask.FieldCompletedAt, field.TypeTime)
|
|
}
|
|
_node = &SoraTask{config: _u.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{soratask.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|