107 lines
3.9 KiB
Go
107 lines
3.9 KiB
Go
package response
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"git.echol.cn/loser/st/server/model/app"
|
|
)
|
|
|
|
// RegexScriptResponse 正则脚本响应
|
|
type RegexScriptResponse struct {
|
|
ID uint `json:"id"`
|
|
UserID uint `json:"userId"`
|
|
ScriptName string `json:"scriptName"`
|
|
Description string `json:"description"`
|
|
FindRegex string `json:"findRegex"`
|
|
ReplaceString string `json:"replaceString"`
|
|
Enabled bool `json:"enabled"`
|
|
IsGlobal bool `json:"isGlobal"`
|
|
TrimStrings bool `json:"trimStrings"`
|
|
OnlyFormat bool `json:"onlyFormat"`
|
|
RunOnEdit bool `json:"runOnEdit"`
|
|
SubstituteRegex bool `json:"substituteRegex"`
|
|
MinDepth *int `json:"minDepth"`
|
|
MaxDepth *int `json:"maxDepth"`
|
|
Placement string `json:"placement"`
|
|
AffectMinDepth *int `json:"affectMinDepth"`
|
|
AffectMaxDepth *int `json:"affectMaxDepth"`
|
|
LinkedChars []string `json:"linkedChars"`
|
|
ScriptData map[string]interface{} `json:"scriptData"`
|
|
UsageCount int `json:"usageCount"`
|
|
LastUsedAt *int64 `json:"lastUsedAt"`
|
|
CreatedAt int64 `json:"createdAt"`
|
|
UpdatedAt int64 `json:"updatedAt"`
|
|
}
|
|
|
|
// RegexScriptListResponse 正则脚本列表响应
|
|
type RegexScriptListResponse struct {
|
|
List []RegexScriptResponse `json:"list"`
|
|
Total int64 `json:"total"`
|
|
Page int `json:"page"`
|
|
PageSize int `json:"pageSize"`
|
|
}
|
|
|
|
// TestRegexScriptResponse 测试正则脚本响应
|
|
type TestRegexScriptResponse struct {
|
|
Success bool `json:"success"`
|
|
Input string `json:"input"`
|
|
Output string `json:"output"`
|
|
MatchedCount int `json:"matchedCount"`
|
|
Matches []string `json:"matches"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
// ApplyRegexScriptsResponse 应用正则脚本响应
|
|
type ApplyRegexScriptsResponse struct {
|
|
OriginalText string `json:"originalText"`
|
|
ProcessedText string `json:"processedText"`
|
|
AppliedCount int `json:"appliedCount"`
|
|
AppliedScripts []uint `json:"appliedScripts"` // 应用的脚本ID列表
|
|
}
|
|
|
|
// RegexScriptExportData 正则脚本导出数据
|
|
type RegexScriptExportData struct {
|
|
Version string `json:"version"` // 导出格式版本
|
|
Scripts []RegexScriptResponse `json:"scripts"`
|
|
ExportedAt int64 `json:"exportedAt"`
|
|
}
|
|
|
|
// ToRegexScriptResponse 将 AIRegexScript 转换为 RegexScriptResponse
|
|
func ToRegexScriptResponse(script *app.AIRegexScript) RegexScriptResponse {
|
|
var scriptData map[string]interface{}
|
|
if len(script.ScriptData) > 0 {
|
|
_ = json.Unmarshal(script.ScriptData, &scriptData)
|
|
}
|
|
|
|
linkedChars := []string{}
|
|
if script.LinkedChars != nil {
|
|
linkedChars = script.LinkedChars
|
|
}
|
|
|
|
return RegexScriptResponse{
|
|
ID: script.ID,
|
|
UserID: script.UserID,
|
|
ScriptName: script.ScriptName,
|
|
Description: script.Description,
|
|
FindRegex: script.FindRegex,
|
|
ReplaceString: script.ReplaceString,
|
|
Enabled: script.Enabled,
|
|
IsGlobal: script.IsGlobal,
|
|
TrimStrings: script.TrimStrings,
|
|
OnlyFormat: script.OnlyFormat,
|
|
RunOnEdit: script.RunOnEdit,
|
|
SubstituteRegex: script.SubstituteRegex,
|
|
MinDepth: script.MinDepth,
|
|
MaxDepth: script.MaxDepth,
|
|
Placement: script.Placement,
|
|
AffectMinDepth: script.AffectMinDepth,
|
|
AffectMaxDepth: script.AffectMaxDepth,
|
|
LinkedChars: linkedChars,
|
|
ScriptData: scriptData,
|
|
UsageCount: script.UsageCount,
|
|
LastUsedAt: script.LastUsedAt,
|
|
CreatedAt: script.CreatedAt.Unix(),
|
|
UpdatedAt: script.UpdatedAt.Unix(),
|
|
}
|
|
}
|