chore: 初始化提交
This commit is contained in:
commit
943c0a0e5a
71 files changed
+7122
No files matched your search
@@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// Canvas 一张画布。节点与连线以 JSON 存储,前端直接使用 React Flow 的结构。
|
||||
type Canvas struct {
|
||||
ID string `gorm:"primaryKey;size:64" json:"id"`
|
||||
Name string `gorm:"size:255;not null" json:"name"`
|
||||
Nodes JSONList `gorm:"type:text" json:"nodes"`
|
||||
Edges JSONList `gorm:"type:text" json:"edges"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// JSONList 以文本列存储 JSON 数组,序列化到 HTTP 响应时保持数组形态。
|
||||
type JSONList json.RawMessage
|
||||
|
||||
func (j JSONList) MarshalJSON() ([]byte, error) {
|
||||
if len(j) == 0 {
|
||||
return []byte("[]"), nil
|
||||
}
|
||||
return json.RawMessage(j), nil
|
||||
}
|
||||
|
||||
func (j JSONList) Value() (driver.Value, error) {
|
||||
if len(j) == 0 {
|
||||
return "[]", nil
|
||||
}
|
||||
return string(j), nil
|
||||
}
|
||||
|
||||
func (j *JSONList) Scan(src any) error {
|
||||
switch value := src.(type) {
|
||||
case nil:
|
||||
*j = nil
|
||||
case []byte:
|
||||
*j = append((*j)[:0], value...)
|
||||
case string:
|
||||
*j = append((*j)[:0], value...)
|
||||
default:
|
||||
return fmt.Errorf("JSONList 无法解析 %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// JSONMap 以文本列存储 JSON 对象。
|
||||
type JSONMap map[string]any
|
||||
|
||||
func (m JSONMap) Value() (driver.Value, error) {
|
||||
if m == nil {
|
||||
return "null", nil
|
||||
}
|
||||
encoded, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return string(encoded), nil
|
||||
}
|
||||
|
||||
func (m *JSONMap) Scan(src any) error {
|
||||
var raw []byte
|
||||
switch value := src.(type) {
|
||||
case nil:
|
||||
*m = nil
|
||||
return nil
|
||||
case []byte:
|
||||
raw = value
|
||||
case string:
|
||||
raw = []byte(value)
|
||||
default:
|
||||
return fmt.Errorf("JSONMap 无法解析 %T", src)
|
||||
}
|
||||
|
||||
if len(raw) == 0 {
|
||||
*m = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
var decoded map[string]any
|
||||
if err := json.Unmarshal(raw, &decoded); err != nil {
|
||||
return err
|
||||
}
|
||||
*m = decoded
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// 任务状态机固定为以下取值,不要新增中间态。
|
||||
const (
|
||||
TaskStatusPending = "pending"
|
||||
TaskStatusRunning = "running"
|
||||
TaskStatusSucceeded = "succeeded"
|
||||
TaskStatusFailed = "failed"
|
||||
TaskStatusCanceled = "canceled"
|
||||
)
|
||||
|
||||
// Task 一次生成任务。长耗时动作一律走任务表,不阻塞 HTTP 请求。
|
||||
type Task struct {
|
||||
ID string `gorm:"primaryKey;size:64" json:"id"`
|
||||
CanvasID string `gorm:"index;size:64;not null" json:"canvasId"`
|
||||
NodeID string `gorm:"size:64" json:"nodeId"`
|
||||
Kind string `gorm:"size:32;not null" json:"kind"`
|
||||
Status string `gorm:"size:16;not null;index" json:"status"`
|
||||
Progress float64 `json:"progress"`
|
||||
Params JSONMap `gorm:"type:text" json:"params"`
|
||||
Result JSONMap `gorm:"type:text" json:"result,omitempty"`
|
||||
Error string `gorm:"type:text" json:"error,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
Reference in new issue
Block a user