diff --git a/pkg/app/model/file.go b/pkg/app/model/file.go index 5b1f009..28ddaab 100644 --- a/pkg/app/model/file.go +++ b/pkg/app/model/file.go @@ -73,11 +73,11 @@ func (model *File) GetPath(id interface{}) string { json.Unmarshal([]byte(getId), &jsonData) // 如果为map if mapData, ok := jsonData.(map[string]interface{}); ok { - path = mapData["path"].(string) + path = mapData["url"].(string) } // 如果为数组,返回第一个key的path if arrayData, ok := jsonData.([]map[string]interface{}); ok { - path = arrayData[0]["path"].(string) + path = arrayData[0]["url"].(string) } } @@ -110,6 +110,48 @@ func (model *File) GetPath(id interface{}) string { return "" } +// 获取多文件路径 +func (model *File) GetPaths(id interface{}) []string { + var paths []string + http, path := "", "" + webSiteDomain := (&Config{}).GetValue("WEB_SITE_DOMAIN") + WebConfig := (&Config{}).GetValue("SSL_OPEN") + if webSiteDomain != "" { + if WebConfig == "1" { + http = "https://" + } else { + http = "http://" + } + } + + if getId, ok := id.(string); ok { + // json字符串 + if strings.Contains(getId, "{") { + var jsonData interface{} + json.Unmarshal([]byte(getId), &jsonData) + // 如果为数组,返回第一个key的path + if arrayData, ok := jsonData.([]map[string]interface{}); ok { + for _, v := range arrayData { + path = v["path"].(string) + if strings.Contains(path, "//") { + paths = append(paths, v["path"].(string)) + } else { + if strings.Contains(path, "./") { + path = strings.Replace(path, "./website/", "/", -1) + } + if path != "" { + path = http + webSiteDomain + path + } + paths = append(paths, path) + } + } + } + } + } + + return paths +} + // 获取Excel文件数据 func (model *File) GetExcelData(fileId int) (data [][]interface{}, Error error) { filePath := "" diff --git a/pkg/app/model/picture.go b/pkg/app/model/picture.go index aa34396..4de5996 100644 --- a/pkg/app/model/picture.go +++ b/pkg/app/model/picture.go @@ -171,3 +171,45 @@ func (model *Picture) GetPath(id interface{}) string { return http + webSiteDomain + "/admin/default.png" } + +// 获取多图片路径 +func (model *Picture) GetPaths(id interface{}) []string { + var paths []string + http, path := "", "" + webSiteDomain := (&Config{}).GetValue("WEB_SITE_DOMAIN") + WebConfig := (&Config{}).GetValue("SSL_OPEN") + if webSiteDomain != "" { + if WebConfig == "1" { + http = "https://" + } else { + http = "http://" + } + } + + if getId, ok := id.(string); ok { + // json字符串 + if strings.Contains(getId, "{") { + var jsonData interface{} + json.Unmarshal([]byte(getId), &jsonData) + // 如果为数组,返回第一个key的path + if arrayData, ok := jsonData.([]map[string]interface{}); ok { + for _, v := range arrayData { + path = v["url"].(string) + if strings.Contains(path, "//") { + paths = append(paths, v["url"].(string)) + } else { + if strings.Contains(path, "./") { + path = strings.Replace(path, "./website/", "/", -1) + } + if path != "" { + path = http + webSiteDomain + path + } + paths = append(paths, path) + } + } + } + } + } + + return paths +} diff --git a/pkg/builder/engine.go b/pkg/builder/engine.go index 059976e..7fbf936 100644 --- a/pkg/builder/engine.go +++ b/pkg/builder/engine.go @@ -19,7 +19,7 @@ const ( AppName = "QuarkGo" // Version of current package - Version = "1.1.23" + Version = "1.1.24" // 静态文件URL RespositoryURL = "https://github.com/quarkcms/quark-go/tree/main/website/"