114 lines
4.7 KiB
Go
114 lines
4.7 KiB
Go
package response
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"git.echol.cn/loser/st/server/model/app"
|
|
)
|
|
|
|
// 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"`
|
|
ScriptPath string `json:"scriptPath"`
|
|
StylePath string `json:"stylePath"`
|
|
AssetPaths []string `json:"assetPaths"`
|
|
ManifestData map[string]interface{} `json:"manifestData"`
|
|
Settings map[string]interface{} `json:"settings"`
|
|
Options map[string]interface{} `json:"options"`
|
|
Metadata map[string]interface{} `json:"metadata"`
|
|
IsEnabled bool `json:"isEnabled"`
|
|
IsInstalled bool `json:"isInstalled"`
|
|
IsSystemExt bool `json:"isSystemExt"`
|
|
InstallSource string `json:"installSource"`
|
|
SourceURL string `json:"sourceUrl"`
|
|
Branch string `json:"branch"`
|
|
AutoUpdate bool `json:"autoUpdate"`
|
|
LastUpdateCheck *int64 `json:"lastUpdateCheck"`
|
|
AvailableVersion string `json:"availableVersion"`
|
|
InstallDate *int64 `json:"installDate"`
|
|
LastEnabled *int64 `json:"lastEnabled"`
|
|
UsageCount int `json:"usageCount"`
|
|
ErrorCount int `json:"errorCount"`
|
|
LoadTime int `json:"loadTime"`
|
|
CreatedAt int64 `json:"createdAt"`
|
|
UpdatedAt int64 `json:"updatedAt"`
|
|
}
|
|
|
|
// ExtensionListResponse 扩展列表响应
|
|
type ExtensionListResponse struct {
|
|
List []ExtensionResponse `json:"list"`
|
|
Total int64 `json:"total"`
|
|
Page int `json:"page"`
|
|
PageSize int `json:"pageSize"`
|
|
}
|
|
|
|
// unmarshalJSONB 通用 JSONB 反序列化辅助函数
|
|
func unmarshalJSONB[T any](data []byte, fallback T) T {
|
|
if len(data) == 0 {
|
|
return fallback
|
|
}
|
|
var result T
|
|
if err := json.Unmarshal(data, &result); err != nil {
|
|
return fallback
|
|
}
|
|
return result
|
|
}
|
|
|
|
// ToExtensionResponse 将 AIExtension 转换为 ExtensionResponse
|
|
func ToExtensionResponse(ext *app.AIExtension) ExtensionResponse {
|
|
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: unmarshalJSONB(ext.Tags, []string{}),
|
|
ExtensionType: ext.ExtensionType,
|
|
Category: ext.Category,
|
|
Dependencies: unmarshalJSONB(ext.Dependencies, map[string]string{}),
|
|
Conflicts: unmarshalJSONB(ext.Conflicts, []string{}),
|
|
ScriptPath: ext.ScriptPath,
|
|
StylePath: ext.StylePath,
|
|
AssetPaths: unmarshalJSONB(ext.AssetPaths, []string{}),
|
|
ManifestData: unmarshalJSONB(ext.ManifestData, map[string]interface{}{}),
|
|
Settings: unmarshalJSONB(ext.Settings, map[string]interface{}{}),
|
|
Options: unmarshalJSONB(ext.Options, map[string]interface{}{}),
|
|
Metadata: unmarshalJSONB(ext.Metadata, map[string]interface{}{}),
|
|
IsEnabled: ext.IsEnabled,
|
|
IsInstalled: ext.IsInstalled,
|
|
IsSystemExt: ext.IsSystemExt,
|
|
InstallSource: ext.InstallSource,
|
|
SourceURL: ext.SourceURL,
|
|
Branch: ext.Branch,
|
|
AutoUpdate: ext.AutoUpdate,
|
|
LastUpdateCheck: ext.LastUpdateCheck,
|
|
AvailableVersion: ext.AvailableVersion,
|
|
InstallDate: ext.InstallDate,
|
|
LastEnabled: ext.LastEnabled,
|
|
UsageCount: ext.UsageCount,
|
|
ErrorCount: ext.ErrorCount,
|
|
LoadTime: ext.LoadTime,
|
|
CreatedAt: ext.CreatedAt.Unix(),
|
|
UpdatedAt: ext.UpdatedAt.Unix(),
|
|
}
|
|
}
|