mirror of
https://github.com/AlistGo/alist.git
synced 2025-04-21 20:18:47 +08:00
chore: change fs get and list resp
This commit is contained in:
parent
c8f10703b7
commit
7903ed1f52
@ -12,6 +12,7 @@ import (
|
||||
var initialSettingItems = []model.SettingItem{
|
||||
// site settings
|
||||
{Key: "version", Value: conf.Version, Type: conf.TypeString, Group: model.SITE, Flag: model.READONLY},
|
||||
{Key: "base_url", Value: "", Type: conf.TypeString, Group: model.SITE},
|
||||
{Key: "site_title", Value: "AList", Type: conf.TypeString, Group: model.SITE},
|
||||
{Key: "site_logo", Value: "https://cdn.jsdelivr.net/gh/alist-org/logo@main/logo.svg", Type: conf.TypeString, Group: model.SITE},
|
||||
{Key: "favicon", Value: "https://cdn.jsdelivr.net/gh/alist-org/logo@main/logo.svg", Type: conf.TypeString, Group: model.SITE},
|
||||
|
@ -5,8 +5,15 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func GetByKey(key string) string {
|
||||
return db.GetSettingsMap()[key]
|
||||
func GetByKey(key string, defaultValue ...string) string {
|
||||
val, ok := db.GetSettingsMap()[key]
|
||||
if !ok {
|
||||
if len(defaultValue) > 0 {
|
||||
return defaultValue[0]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
func GetIntSetting(key string, defaultVal int) int {
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"github.com/alist-org/alist/v3/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
stdpath "path"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FsGetReq struct {
|
||||
@ -16,11 +15,8 @@ type FsGetReq struct {
|
||||
}
|
||||
|
||||
type FsGetResp struct {
|
||||
Name string `json:"name"`
|
||||
Size int64 `json:"size"`
|
||||
IsDir bool `json:"is_dir"`
|
||||
Modified time.Time `json:"modified"`
|
||||
URL string `json:"url"`
|
||||
ObjResp
|
||||
RawURL string `json:"raw_url"`
|
||||
}
|
||||
|
||||
func FsGet(c *gin.Context) {
|
||||
@ -43,9 +39,12 @@ func FsGet(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c, FsGetResp{
|
||||
Name: data.GetName(),
|
||||
Size: data.GetSize(),
|
||||
IsDir: data.IsDir(),
|
||||
Modified: data.ModTime(),
|
||||
ObjResp: ObjResp{
|
||||
Name: data.GetName(),
|
||||
Size: data.GetSize(),
|
||||
IsDir: data.IsDir(),
|
||||
Modified: data.ModTime(),
|
||||
},
|
||||
// TODO: set raw url
|
||||
})
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/fs"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/internal/setting"
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
"github.com/alist-org/alist/v3/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -22,6 +24,7 @@ type ObjResp struct {
|
||||
Size int64 `json:"size"`
|
||||
IsDir bool `json:"is_dir"`
|
||||
Modified time.Time `json:"modified"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
type FsListResp struct {
|
||||
@ -50,8 +53,9 @@ func FsList(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
total, objs := pagination(objs, &req.PageReq)
|
||||
baseURL := setting.GetByKey("base_url", c.Request.Host)
|
||||
common.SuccessResp(c, FsListResp{
|
||||
Content: toObjResp(objs),
|
||||
Content: toObjResp(objs, req.Path, baseURL),
|
||||
Total: int64(total),
|
||||
})
|
||||
}
|
||||
@ -87,7 +91,7 @@ func pagination(objs []model.Obj, req *common.PageReq) (int, []model.Obj) {
|
||||
return total, objs[start:end]
|
||||
}
|
||||
|
||||
func toObjResp(objs []model.Obj) []ObjResp {
|
||||
func toObjResp(objs []model.Obj, path string, baseURL string) []ObjResp {
|
||||
var resp []ObjResp
|
||||
for _, obj := range objs {
|
||||
resp = append(resp, ObjResp{
|
||||
@ -95,6 +99,8 @@ func toObjResp(objs []model.Obj) []ObjResp {
|
||||
Size: obj.GetSize(),
|
||||
IsDir: obj.IsDir(),
|
||||
Modified: obj.ModTime(),
|
||||
// TODO: sign url
|
||||
URL: fmt.Sprintf("%s/d%s", baseURL, stdpath.Join(path, obj.GetName())),
|
||||
})
|
||||
}
|
||||
return resp
|
||||
|
Loading…
x
Reference in New Issue
Block a user