新增功能: - 新增 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>
1005 lines
30 KiB
Go
1005 lines
30 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/soracachefile"
|
|
)
|
|
|
|
// SoraCacheFileCreate is the builder for creating a SoraCacheFile entity.
|
|
type SoraCacheFileCreate struct {
|
|
config
|
|
mutation *SoraCacheFileMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetTaskID sets the "task_id" field.
|
|
func (_c *SoraCacheFileCreate) SetTaskID(v string) *SoraCacheFileCreate {
|
|
_c.mutation.SetTaskID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableTaskID sets the "task_id" field if the given value is not nil.
|
|
func (_c *SoraCacheFileCreate) SetNillableTaskID(v *string) *SoraCacheFileCreate {
|
|
if v != nil {
|
|
_c.SetTaskID(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetAccountID sets the "account_id" field.
|
|
func (_c *SoraCacheFileCreate) SetAccountID(v int64) *SoraCacheFileCreate {
|
|
_c.mutation.SetAccountID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_c *SoraCacheFileCreate) SetUserID(v int64) *SoraCacheFileCreate {
|
|
_c.mutation.SetUserID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetMediaType sets the "media_type" field.
|
|
func (_c *SoraCacheFileCreate) SetMediaType(v string) *SoraCacheFileCreate {
|
|
_c.mutation.SetMediaType(v)
|
|
return _c
|
|
}
|
|
|
|
// SetOriginalURL sets the "original_url" field.
|
|
func (_c *SoraCacheFileCreate) SetOriginalURL(v string) *SoraCacheFileCreate {
|
|
_c.mutation.SetOriginalURL(v)
|
|
return _c
|
|
}
|
|
|
|
// SetCachePath sets the "cache_path" field.
|
|
func (_c *SoraCacheFileCreate) SetCachePath(v string) *SoraCacheFileCreate {
|
|
_c.mutation.SetCachePath(v)
|
|
return _c
|
|
}
|
|
|
|
// SetCacheURL sets the "cache_url" field.
|
|
func (_c *SoraCacheFileCreate) SetCacheURL(v string) *SoraCacheFileCreate {
|
|
_c.mutation.SetCacheURL(v)
|
|
return _c
|
|
}
|
|
|
|
// SetSizeBytes sets the "size_bytes" field.
|
|
func (_c *SoraCacheFileCreate) SetSizeBytes(v int64) *SoraCacheFileCreate {
|
|
_c.mutation.SetSizeBytes(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableSizeBytes sets the "size_bytes" field if the given value is not nil.
|
|
func (_c *SoraCacheFileCreate) SetNillableSizeBytes(v *int64) *SoraCacheFileCreate {
|
|
if v != nil {
|
|
_c.SetSizeBytes(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *SoraCacheFileCreate) SetCreatedAt(v time.Time) *SoraCacheFileCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *SoraCacheFileCreate) SetNillableCreatedAt(v *time.Time) *SoraCacheFileCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the SoraCacheFileMutation object of the builder.
|
|
func (_c *SoraCacheFileCreate) Mutation() *SoraCacheFileMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the SoraCacheFile in the database.
|
|
func (_c *SoraCacheFileCreate) Save(ctx context.Context) (*SoraCacheFile, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *SoraCacheFileCreate) SaveX(ctx context.Context) *SoraCacheFile {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *SoraCacheFileCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *SoraCacheFileCreate) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_c *SoraCacheFileCreate) defaults() {
|
|
if _, ok := _c.mutation.SizeBytes(); !ok {
|
|
v := soracachefile.DefaultSizeBytes
|
|
_c.mutation.SetSizeBytes(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := soracachefile.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *SoraCacheFileCreate) check() error {
|
|
if v, ok := _c.mutation.TaskID(); ok {
|
|
if err := soracachefile.TaskIDValidator(v); err != nil {
|
|
return &ValidationError{Name: "task_id", err: fmt.Errorf(`ent: validator failed for field "SoraCacheFile.task_id": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.AccountID(); !ok {
|
|
return &ValidationError{Name: "account_id", err: errors.New(`ent: missing required field "SoraCacheFile.account_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.UserID(); !ok {
|
|
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "SoraCacheFile.user_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.MediaType(); !ok {
|
|
return &ValidationError{Name: "media_type", err: errors.New(`ent: missing required field "SoraCacheFile.media_type"`)}
|
|
}
|
|
if v, ok := _c.mutation.MediaType(); ok {
|
|
if err := soracachefile.MediaTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "media_type", err: fmt.Errorf(`ent: validator failed for field "SoraCacheFile.media_type": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.OriginalURL(); !ok {
|
|
return &ValidationError{Name: "original_url", err: errors.New(`ent: missing required field "SoraCacheFile.original_url"`)}
|
|
}
|
|
if _, ok := _c.mutation.CachePath(); !ok {
|
|
return &ValidationError{Name: "cache_path", err: errors.New(`ent: missing required field "SoraCacheFile.cache_path"`)}
|
|
}
|
|
if _, ok := _c.mutation.CacheURL(); !ok {
|
|
return &ValidationError{Name: "cache_url", err: errors.New(`ent: missing required field "SoraCacheFile.cache_url"`)}
|
|
}
|
|
if _, ok := _c.mutation.SizeBytes(); !ok {
|
|
return &ValidationError{Name: "size_bytes", err: errors.New(`ent: missing required field "SoraCacheFile.size_bytes"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SoraCacheFile.created_at"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *SoraCacheFileCreate) sqlSave(ctx context.Context) (*SoraCacheFile, error) {
|
|
if err := _c.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := _c.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
id := _spec.ID.Value.(int64)
|
|
_node.ID = int64(id)
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *SoraCacheFileCreate) createSpec() (*SoraCacheFile, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &SoraCacheFile{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(soracachefile.Table, sqlgraph.NewFieldSpec(soracachefile.FieldID, field.TypeInt64))
|
|
)
|
|
_spec.OnConflict = _c.conflict
|
|
if value, ok := _c.mutation.TaskID(); ok {
|
|
_spec.SetField(soracachefile.FieldTaskID, field.TypeString, value)
|
|
_node.TaskID = &value
|
|
}
|
|
if value, ok := _c.mutation.AccountID(); ok {
|
|
_spec.SetField(soracachefile.FieldAccountID, field.TypeInt64, value)
|
|
_node.AccountID = value
|
|
}
|
|
if value, ok := _c.mutation.UserID(); ok {
|
|
_spec.SetField(soracachefile.FieldUserID, field.TypeInt64, value)
|
|
_node.UserID = value
|
|
}
|
|
if value, ok := _c.mutation.MediaType(); ok {
|
|
_spec.SetField(soracachefile.FieldMediaType, field.TypeString, value)
|
|
_node.MediaType = value
|
|
}
|
|
if value, ok := _c.mutation.OriginalURL(); ok {
|
|
_spec.SetField(soracachefile.FieldOriginalURL, field.TypeString, value)
|
|
_node.OriginalURL = value
|
|
}
|
|
if value, ok := _c.mutation.CachePath(); ok {
|
|
_spec.SetField(soracachefile.FieldCachePath, field.TypeString, value)
|
|
_node.CachePath = value
|
|
}
|
|
if value, ok := _c.mutation.CacheURL(); ok {
|
|
_spec.SetField(soracachefile.FieldCacheURL, field.TypeString, value)
|
|
_node.CacheURL = value
|
|
}
|
|
if value, ok := _c.mutation.SizeBytes(); ok {
|
|
_spec.SetField(soracachefile.FieldSizeBytes, field.TypeInt64, value)
|
|
_node.SizeBytes = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(soracachefile.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.SoraCacheFile.Create().
|
|
// SetTaskID(v).
|
|
// OnConflict(
|
|
// // Update the row with the new values
|
|
// // the was proposed for insertion.
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// // Override some of the fields with custom
|
|
// // update values.
|
|
// Update(func(u *ent.SoraCacheFileUpsert) {
|
|
// SetTaskID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *SoraCacheFileCreate) OnConflict(opts ...sql.ConflictOption) *SoraCacheFileUpsertOne {
|
|
_c.conflict = opts
|
|
return &SoraCacheFileUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.SoraCacheFile.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *SoraCacheFileCreate) OnConflictColumns(columns ...string) *SoraCacheFileUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &SoraCacheFileUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// SoraCacheFileUpsertOne is the builder for "upsert"-ing
|
|
// one SoraCacheFile node.
|
|
SoraCacheFileUpsertOne struct {
|
|
create *SoraCacheFileCreate
|
|
}
|
|
|
|
// SoraCacheFileUpsert is the "OnConflict" setter.
|
|
SoraCacheFileUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetTaskID sets the "task_id" field.
|
|
func (u *SoraCacheFileUpsert) SetTaskID(v string) *SoraCacheFileUpsert {
|
|
u.Set(soracachefile.FieldTaskID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateTaskID sets the "task_id" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsert) UpdateTaskID() *SoraCacheFileUpsert {
|
|
u.SetExcluded(soracachefile.FieldTaskID)
|
|
return u
|
|
}
|
|
|
|
// ClearTaskID clears the value of the "task_id" field.
|
|
func (u *SoraCacheFileUpsert) ClearTaskID() *SoraCacheFileUpsert {
|
|
u.SetNull(soracachefile.FieldTaskID)
|
|
return u
|
|
}
|
|
|
|
// SetAccountID sets the "account_id" field.
|
|
func (u *SoraCacheFileUpsert) SetAccountID(v int64) *SoraCacheFileUpsert {
|
|
u.Set(soracachefile.FieldAccountID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateAccountID sets the "account_id" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsert) UpdateAccountID() *SoraCacheFileUpsert {
|
|
u.SetExcluded(soracachefile.FieldAccountID)
|
|
return u
|
|
}
|
|
|
|
// AddAccountID adds v to the "account_id" field.
|
|
func (u *SoraCacheFileUpsert) AddAccountID(v int64) *SoraCacheFileUpsert {
|
|
u.Add(soracachefile.FieldAccountID, v)
|
|
return u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *SoraCacheFileUpsert) SetUserID(v int64) *SoraCacheFileUpsert {
|
|
u.Set(soracachefile.FieldUserID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsert) UpdateUserID() *SoraCacheFileUpsert {
|
|
u.SetExcluded(soracachefile.FieldUserID)
|
|
return u
|
|
}
|
|
|
|
// AddUserID adds v to the "user_id" field.
|
|
func (u *SoraCacheFileUpsert) AddUserID(v int64) *SoraCacheFileUpsert {
|
|
u.Add(soracachefile.FieldUserID, v)
|
|
return u
|
|
}
|
|
|
|
// SetMediaType sets the "media_type" field.
|
|
func (u *SoraCacheFileUpsert) SetMediaType(v string) *SoraCacheFileUpsert {
|
|
u.Set(soracachefile.FieldMediaType, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateMediaType sets the "media_type" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsert) UpdateMediaType() *SoraCacheFileUpsert {
|
|
u.SetExcluded(soracachefile.FieldMediaType)
|
|
return u
|
|
}
|
|
|
|
// SetOriginalURL sets the "original_url" field.
|
|
func (u *SoraCacheFileUpsert) SetOriginalURL(v string) *SoraCacheFileUpsert {
|
|
u.Set(soracachefile.FieldOriginalURL, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateOriginalURL sets the "original_url" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsert) UpdateOriginalURL() *SoraCacheFileUpsert {
|
|
u.SetExcluded(soracachefile.FieldOriginalURL)
|
|
return u
|
|
}
|
|
|
|
// SetCachePath sets the "cache_path" field.
|
|
func (u *SoraCacheFileUpsert) SetCachePath(v string) *SoraCacheFileUpsert {
|
|
u.Set(soracachefile.FieldCachePath, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCachePath sets the "cache_path" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsert) UpdateCachePath() *SoraCacheFileUpsert {
|
|
u.SetExcluded(soracachefile.FieldCachePath)
|
|
return u
|
|
}
|
|
|
|
// SetCacheURL sets the "cache_url" field.
|
|
func (u *SoraCacheFileUpsert) SetCacheURL(v string) *SoraCacheFileUpsert {
|
|
u.Set(soracachefile.FieldCacheURL, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCacheURL sets the "cache_url" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsert) UpdateCacheURL() *SoraCacheFileUpsert {
|
|
u.SetExcluded(soracachefile.FieldCacheURL)
|
|
return u
|
|
}
|
|
|
|
// SetSizeBytes sets the "size_bytes" field.
|
|
func (u *SoraCacheFileUpsert) SetSizeBytes(v int64) *SoraCacheFileUpsert {
|
|
u.Set(soracachefile.FieldSizeBytes, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateSizeBytes sets the "size_bytes" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsert) UpdateSizeBytes() *SoraCacheFileUpsert {
|
|
u.SetExcluded(soracachefile.FieldSizeBytes)
|
|
return u
|
|
}
|
|
|
|
// AddSizeBytes adds v to the "size_bytes" field.
|
|
func (u *SoraCacheFileUpsert) AddSizeBytes(v int64) *SoraCacheFileUpsert {
|
|
u.Add(soracachefile.FieldSizeBytes, v)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *SoraCacheFileUpsert) SetCreatedAt(v time.Time) *SoraCacheFileUpsert {
|
|
u.Set(soracachefile.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsert) UpdateCreatedAt() *SoraCacheFileUpsert {
|
|
u.SetExcluded(soracachefile.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.SoraCacheFile.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *SoraCacheFileUpsertOne) UpdateNewValues() *SoraCacheFileUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.SoraCacheFile.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *SoraCacheFileUpsertOne) Ignore() *SoraCacheFileUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
|
return u
|
|
}
|
|
|
|
// DoNothing configures the conflict_action to `DO NOTHING`.
|
|
// Supported only by SQLite and PostgreSQL.
|
|
func (u *SoraCacheFileUpsertOne) DoNothing() *SoraCacheFileUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the SoraCacheFileCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *SoraCacheFileUpsertOne) Update(set func(*SoraCacheFileUpsert)) *SoraCacheFileUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&SoraCacheFileUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetTaskID sets the "task_id" field.
|
|
func (u *SoraCacheFileUpsertOne) SetTaskID(v string) *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetTaskID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateTaskID sets the "task_id" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertOne) UpdateTaskID() *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateTaskID()
|
|
})
|
|
}
|
|
|
|
// ClearTaskID clears the value of the "task_id" field.
|
|
func (u *SoraCacheFileUpsertOne) ClearTaskID() *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.ClearTaskID()
|
|
})
|
|
}
|
|
|
|
// SetAccountID sets the "account_id" field.
|
|
func (u *SoraCacheFileUpsertOne) SetAccountID(v int64) *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetAccountID(v)
|
|
})
|
|
}
|
|
|
|
// AddAccountID adds v to the "account_id" field.
|
|
func (u *SoraCacheFileUpsertOne) AddAccountID(v int64) *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.AddAccountID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateAccountID sets the "account_id" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertOne) UpdateAccountID() *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateAccountID()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *SoraCacheFileUpsertOne) SetUserID(v int64) *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// AddUserID adds v to the "user_id" field.
|
|
func (u *SoraCacheFileUpsertOne) AddUserID(v int64) *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.AddUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertOne) UpdateUserID() *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetMediaType sets the "media_type" field.
|
|
func (u *SoraCacheFileUpsertOne) SetMediaType(v string) *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetMediaType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateMediaType sets the "media_type" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertOne) UpdateMediaType() *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateMediaType()
|
|
})
|
|
}
|
|
|
|
// SetOriginalURL sets the "original_url" field.
|
|
func (u *SoraCacheFileUpsertOne) SetOriginalURL(v string) *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetOriginalURL(v)
|
|
})
|
|
}
|
|
|
|
// UpdateOriginalURL sets the "original_url" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertOne) UpdateOriginalURL() *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateOriginalURL()
|
|
})
|
|
}
|
|
|
|
// SetCachePath sets the "cache_path" field.
|
|
func (u *SoraCacheFileUpsertOne) SetCachePath(v string) *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetCachePath(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCachePath sets the "cache_path" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertOne) UpdateCachePath() *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateCachePath()
|
|
})
|
|
}
|
|
|
|
// SetCacheURL sets the "cache_url" field.
|
|
func (u *SoraCacheFileUpsertOne) SetCacheURL(v string) *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetCacheURL(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCacheURL sets the "cache_url" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertOne) UpdateCacheURL() *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateCacheURL()
|
|
})
|
|
}
|
|
|
|
// SetSizeBytes sets the "size_bytes" field.
|
|
func (u *SoraCacheFileUpsertOne) SetSizeBytes(v int64) *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetSizeBytes(v)
|
|
})
|
|
}
|
|
|
|
// AddSizeBytes adds v to the "size_bytes" field.
|
|
func (u *SoraCacheFileUpsertOne) AddSizeBytes(v int64) *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.AddSizeBytes(v)
|
|
})
|
|
}
|
|
|
|
// UpdateSizeBytes sets the "size_bytes" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertOne) UpdateSizeBytes() *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateSizeBytes()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *SoraCacheFileUpsertOne) SetCreatedAt(v time.Time) *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertOne) UpdateCreatedAt() *SoraCacheFileUpsertOne {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *SoraCacheFileUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for SoraCacheFileCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *SoraCacheFileUpsertOne) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// Exec executes the UPSERT query and returns the inserted/updated ID.
|
|
func (u *SoraCacheFileUpsertOne) ID(ctx context.Context) (id int64, err error) {
|
|
node, err := u.create.Save(ctx)
|
|
if err != nil {
|
|
return id, err
|
|
}
|
|
return node.ID, nil
|
|
}
|
|
|
|
// IDX is like ID, but panics if an error occurs.
|
|
func (u *SoraCacheFileUpsertOne) IDX(ctx context.Context) int64 {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// SoraCacheFileCreateBulk is the builder for creating many SoraCacheFile entities in bulk.
|
|
type SoraCacheFileCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*SoraCacheFileCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the SoraCacheFile entities in the database.
|
|
func (_c *SoraCacheFileCreateBulk) Save(ctx context.Context) ([]*SoraCacheFile, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*SoraCacheFile, len(_c.builders))
|
|
mutators := make([]Mutator, len(_c.builders))
|
|
for i := range _c.builders {
|
|
func(i int, root context.Context) {
|
|
builder := _c.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*SoraCacheFileMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
if err := builder.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
builder.mutation = mutation
|
|
var err error
|
|
nodes[i], specs[i] = builder.createSpec()
|
|
if i < len(mutators)-1 {
|
|
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
spec.OnConflict = _c.conflict
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
}
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &nodes[i].ID
|
|
if specs[i].ID.Value != nil {
|
|
id := specs[i].ID.Value.(int64)
|
|
nodes[i].ID = int64(id)
|
|
}
|
|
mutation.done = true
|
|
return nodes[i], nil
|
|
})
|
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
|
mut = builder.hooks[i](mut)
|
|
}
|
|
mutators[i] = mut
|
|
}(i, ctx)
|
|
}
|
|
if len(mutators) > 0 {
|
|
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_c *SoraCacheFileCreateBulk) SaveX(ctx context.Context) []*SoraCacheFile {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *SoraCacheFileCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *SoraCacheFileCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.SoraCacheFile.CreateBulk(builders...).
|
|
// OnConflict(
|
|
// // Update the row with the new values
|
|
// // the was proposed for insertion.
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// // Override some of the fields with custom
|
|
// // update values.
|
|
// Update(func(u *ent.SoraCacheFileUpsert) {
|
|
// SetTaskID(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *SoraCacheFileCreateBulk) OnConflict(opts ...sql.ConflictOption) *SoraCacheFileUpsertBulk {
|
|
_c.conflict = opts
|
|
return &SoraCacheFileUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.SoraCacheFile.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *SoraCacheFileCreateBulk) OnConflictColumns(columns ...string) *SoraCacheFileUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &SoraCacheFileUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// SoraCacheFileUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of SoraCacheFile nodes.
|
|
type SoraCacheFileUpsertBulk struct {
|
|
create *SoraCacheFileCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.SoraCacheFile.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *SoraCacheFileUpsertBulk) UpdateNewValues() *SoraCacheFileUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.SoraCacheFile.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *SoraCacheFileUpsertBulk) Ignore() *SoraCacheFileUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
|
return u
|
|
}
|
|
|
|
// DoNothing configures the conflict_action to `DO NOTHING`.
|
|
// Supported only by SQLite and PostgreSQL.
|
|
func (u *SoraCacheFileUpsertBulk) DoNothing() *SoraCacheFileUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the SoraCacheFileCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *SoraCacheFileUpsertBulk) Update(set func(*SoraCacheFileUpsert)) *SoraCacheFileUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&SoraCacheFileUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetTaskID sets the "task_id" field.
|
|
func (u *SoraCacheFileUpsertBulk) SetTaskID(v string) *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetTaskID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateTaskID sets the "task_id" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertBulk) UpdateTaskID() *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateTaskID()
|
|
})
|
|
}
|
|
|
|
// ClearTaskID clears the value of the "task_id" field.
|
|
func (u *SoraCacheFileUpsertBulk) ClearTaskID() *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.ClearTaskID()
|
|
})
|
|
}
|
|
|
|
// SetAccountID sets the "account_id" field.
|
|
func (u *SoraCacheFileUpsertBulk) SetAccountID(v int64) *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetAccountID(v)
|
|
})
|
|
}
|
|
|
|
// AddAccountID adds v to the "account_id" field.
|
|
func (u *SoraCacheFileUpsertBulk) AddAccountID(v int64) *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.AddAccountID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateAccountID sets the "account_id" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertBulk) UpdateAccountID() *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateAccountID()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *SoraCacheFileUpsertBulk) SetUserID(v int64) *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// AddUserID adds v to the "user_id" field.
|
|
func (u *SoraCacheFileUpsertBulk) AddUserID(v int64) *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.AddUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertBulk) UpdateUserID() *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetMediaType sets the "media_type" field.
|
|
func (u *SoraCacheFileUpsertBulk) SetMediaType(v string) *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetMediaType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateMediaType sets the "media_type" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertBulk) UpdateMediaType() *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateMediaType()
|
|
})
|
|
}
|
|
|
|
// SetOriginalURL sets the "original_url" field.
|
|
func (u *SoraCacheFileUpsertBulk) SetOriginalURL(v string) *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetOriginalURL(v)
|
|
})
|
|
}
|
|
|
|
// UpdateOriginalURL sets the "original_url" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertBulk) UpdateOriginalURL() *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateOriginalURL()
|
|
})
|
|
}
|
|
|
|
// SetCachePath sets the "cache_path" field.
|
|
func (u *SoraCacheFileUpsertBulk) SetCachePath(v string) *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetCachePath(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCachePath sets the "cache_path" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertBulk) UpdateCachePath() *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateCachePath()
|
|
})
|
|
}
|
|
|
|
// SetCacheURL sets the "cache_url" field.
|
|
func (u *SoraCacheFileUpsertBulk) SetCacheURL(v string) *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetCacheURL(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCacheURL sets the "cache_url" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertBulk) UpdateCacheURL() *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateCacheURL()
|
|
})
|
|
}
|
|
|
|
// SetSizeBytes sets the "size_bytes" field.
|
|
func (u *SoraCacheFileUpsertBulk) SetSizeBytes(v int64) *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetSizeBytes(v)
|
|
})
|
|
}
|
|
|
|
// AddSizeBytes adds v to the "size_bytes" field.
|
|
func (u *SoraCacheFileUpsertBulk) AddSizeBytes(v int64) *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.AddSizeBytes(v)
|
|
})
|
|
}
|
|
|
|
// UpdateSizeBytes sets the "size_bytes" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertBulk) UpdateSizeBytes() *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateSizeBytes()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *SoraCacheFileUpsertBulk) SetCreatedAt(v time.Time) *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *SoraCacheFileUpsertBulk) UpdateCreatedAt() *SoraCacheFileUpsertBulk {
|
|
return u.Update(func(s *SoraCacheFileUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *SoraCacheFileUpsertBulk) Exec(ctx context.Context) error {
|
|
if u.create.err != nil {
|
|
return u.create.err
|
|
}
|
|
for i, b := range u.create.builders {
|
|
if len(b.conflict) != 0 {
|
|
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the SoraCacheFileCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for SoraCacheFileCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *SoraCacheFileUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|