新增正则和扩展模块

This commit is contained in:
2026-02-11 23:44:09 +08:00
parent 2bca8e2788
commit 4e611d3a5e
47 changed files with 10058 additions and 49 deletions

View File

@@ -0,0 +1,188 @@
package response
import (
"encoding/json"
"git.echol.cn/loser/st/server/model/app"
"time"
)
// ExtensionResponse 扩展响应
type ExtensionResponse struct {
ID uint `json:"id"`
UserID uint `json:"userId"`
Name string `json:"name"`
DisplayName string `json:"displayName"`
Version string `json:"version"`
Author string `json:"author"`
Description string `json:"description"`
Homepage string `json:"homepage"`
Repository string `json:"repository"`
License string `json:"license"`
Tags []string `json:"tags"`
ExtensionType string `json:"extensionType"`
Category string `json:"category"`
Dependencies map[string]string `json:"dependencies"`
Conflicts []string `json:"conflicts"`
ManifestData map[string]interface{} `json:"manifestData"`
ScriptPath string `json:"scriptPath"`
StylePath string `json:"stylePath"`
AssetsPaths []string `json:"assetsPaths"`
Settings map[string]interface{} `json:"settings"`
Options map[string]interface{} `json:"options"`
IsEnabled bool `json:"isEnabled"`
IsInstalled bool `json:"isInstalled"`
IsSystemExt bool `json:"isSystemExt"`
InstallSource string `json:"installSource"`
InstallDate time.Time `json:"installDate"`
LastEnabled time.Time `json:"lastEnabled"`
UsageCount int `json:"usageCount"`
ErrorCount int `json:"errorCount"`
LoadTime int `json:"loadTime"`
Metadata map[string]interface{} `json:"metadata"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// ExtensionListResponse 扩展列表响应
type ExtensionListResponse struct {
List []ExtensionResponse `json:"list"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
}
// ExtensionManifestResponse manifest.json 响应
type ExtensionManifestResponse struct {
Name string `json:"name"`
DisplayName string `json:"display_name,omitempty"`
Version string `json:"version"`
Description string `json:"description"`
Author string `json:"author"`
Homepage string `json:"homepage,omitempty"`
Repository string `json:"repository,omitempty"`
License string `json:"license,omitempty"`
Tags []string `json:"tags,omitempty"`
Type string `json:"type,omitempty"`
Category string `json:"category,omitempty"`
Dependencies map[string]string `json:"dependencies,omitempty"`
Conflicts []string `json:"conflicts,omitempty"`
Entry string `json:"entry,omitempty"`
Style string `json:"style,omitempty"`
Assets []string `json:"assets,omitempty"`
Settings map[string]interface{} `json:"settings,omitempty"`
Options map[string]interface{} `json:"options,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
// ExtensionStatsResponse 扩展统计响应
type ExtensionStatsResponse struct {
ExtensionID uint `json:"extensionId"`
ExtensionName string `json:"extensionName"`
UsageCount int `json:"usageCount"`
ErrorCount int `json:"errorCount"`
LoadTime int `json:"loadTime"`
LastUsed time.Time `json:"lastUsed"`
}
// ToExtensionResponse 转换为扩展响应
func ToExtensionResponse(ext *app.AIExtension) ExtensionResponse {
var tags []string
if ext.Tags != nil {
_ = json.Unmarshal([]byte(ext.Tags), &tags)
}
if tags == nil {
tags = []string{}
}
var dependencies map[string]string
if ext.Dependencies != nil {
_ = json.Unmarshal([]byte(ext.Dependencies), &dependencies)
}
if dependencies == nil {
dependencies = map[string]string{}
}
var conflicts []string
if ext.Conflicts != nil {
_ = json.Unmarshal([]byte(ext.Conflicts), &conflicts)
}
if conflicts == nil {
conflicts = []string{}
}
var manifestData map[string]interface{}
if ext.ManifestData != nil {
_ = json.Unmarshal([]byte(ext.ManifestData), &manifestData)
}
if manifestData == nil {
manifestData = map[string]interface{}{}
}
var assetsPaths []string
if ext.AssetsPaths != nil {
_ = json.Unmarshal([]byte(ext.AssetsPaths), &assetsPaths)
}
if assetsPaths == nil {
assetsPaths = []string{}
}
var settings map[string]interface{}
if ext.Settings != nil {
_ = json.Unmarshal([]byte(ext.Settings), &settings)
}
if settings == nil {
settings = map[string]interface{}{}
}
var options map[string]interface{}
if ext.Options != nil {
_ = json.Unmarshal([]byte(ext.Options), &options)
}
if options == nil {
options = map[string]interface{}{}
}
var metadata map[string]interface{}
if ext.Metadata != nil {
_ = json.Unmarshal([]byte(ext.Metadata), &metadata)
}
if metadata == nil {
metadata = map[string]interface{}{}
}
return ExtensionResponse{
ID: ext.ID,
UserID: ext.UserID,
Name: ext.Name,
DisplayName: ext.DisplayName,
Version: ext.Version,
Author: ext.Author,
Description: ext.Description,
Homepage: ext.Homepage,
Repository: ext.Repository,
License: ext.License,
Tags: tags,
ExtensionType: ext.ExtensionType,
Category: ext.Category,
Dependencies: dependencies,
Conflicts: conflicts,
ManifestData: manifestData,
ScriptPath: ext.ScriptPath,
StylePath: ext.StylePath,
AssetsPaths: assetsPaths,
Settings: settings,
Options: options,
IsEnabled: ext.IsEnabled,
IsInstalled: ext.IsInstalled,
IsSystemExt: ext.IsSystemExt,
InstallSource: ext.InstallSource,
InstallDate: ext.InstallDate,
LastEnabled: ext.LastEnabled,
UsageCount: ext.UsageCount,
ErrorCount: ext.ErrorCount,
LoadTime: ext.LoadTime,
Metadata: metadata,
CreatedAt: ext.CreatedAt,
UpdatedAt: ext.UpdatedAt,
}
}

View File

@@ -0,0 +1,106 @@
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(),
}
}