199 lines
7.1 KiB
Go
199 lines
7.1 KiB
Go
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"`
|
|
SourceURL string `json:"sourceUrl"`
|
|
Branch string `json:"branch"`
|
|
AutoUpdate bool `json:"autoUpdate"`
|
|
InstallDate time.Time `json:"installDate"`
|
|
LastEnabled time.Time `json:"lastEnabled"`
|
|
LastUpdateCheck *time.Time `json:"lastUpdateCheck"`
|
|
AvailableVersion string `json:"availableVersion"`
|
|
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,
|
|
SourceURL: ext.SourceURL,
|
|
Branch: ext.Branch,
|
|
AutoUpdate: ext.AutoUpdate,
|
|
InstallDate: ext.InstallDate,
|
|
LastEnabled: ext.LastEnabled,
|
|
LastUpdateCheck: ext.LastUpdateCheck,
|
|
AvailableVersion: ext.AvailableVersion,
|
|
UsageCount: ext.UsageCount,
|
|
ErrorCount: ext.ErrorCount,
|
|
LoadTime: ext.LoadTime,
|
|
Metadata: metadata,
|
|
CreatedAt: ext.CreatedAt,
|
|
UpdatedAt: ext.UpdatedAt,
|
|
}
|
|
}
|