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{
|
var initialSettingItems = []model.SettingItem{
|
||||||
// site settings
|
// site settings
|
||||||
{Key: "version", Value: conf.Version, Type: conf.TypeString, Group: model.SITE, Flag: model.READONLY},
|
{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_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: "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},
|
{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"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetByKey(key string) string {
|
func GetByKey(key string, defaultValue ...string) string {
|
||||||
return db.GetSettingsMap()[key]
|
val, ok := db.GetSettingsMap()[key]
|
||||||
|
if !ok {
|
||||||
|
if len(defaultValue) > 0 {
|
||||||
|
return defaultValue[0]
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetIntSetting(key string, defaultVal int) int {
|
func GetIntSetting(key string, defaultVal int) int {
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/alist-org/alist/v3/server/common"
|
"github.com/alist-org/alist/v3/server/common"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
stdpath "path"
|
stdpath "path"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type FsGetReq struct {
|
type FsGetReq struct {
|
||||||
@ -16,11 +15,8 @@ type FsGetReq struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FsGetResp struct {
|
type FsGetResp struct {
|
||||||
Name string `json:"name"`
|
ObjResp
|
||||||
Size int64 `json:"size"`
|
RawURL string `json:"raw_url"`
|
||||||
IsDir bool `json:"is_dir"`
|
|
||||||
Modified time.Time `json:"modified"`
|
|
||||||
URL string `json:"url"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FsGet(c *gin.Context) {
|
func FsGet(c *gin.Context) {
|
||||||
@ -43,9 +39,12 @@ func FsGet(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
common.SuccessResp(c, FsGetResp{
|
common.SuccessResp(c, FsGetResp{
|
||||||
Name: data.GetName(),
|
ObjResp: ObjResp{
|
||||||
Size: data.GetSize(),
|
Name: data.GetName(),
|
||||||
IsDir: data.IsDir(),
|
Size: data.GetSize(),
|
||||||
Modified: data.ModTime(),
|
IsDir: data.IsDir(),
|
||||||
|
Modified: data.ModTime(),
|
||||||
|
},
|
||||||
|
// TODO: set raw url
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/alist-org/alist/v3/internal/db"
|
"github.com/alist-org/alist/v3/internal/db"
|
||||||
"github.com/alist-org/alist/v3/internal/fs"
|
"github.com/alist-org/alist/v3/internal/fs"
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"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/pkg/utils"
|
||||||
"github.com/alist-org/alist/v3/server/common"
|
"github.com/alist-org/alist/v3/server/common"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -22,6 +24,7 @@ type ObjResp struct {
|
|||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
IsDir bool `json:"is_dir"`
|
IsDir bool `json:"is_dir"`
|
||||||
Modified time.Time `json:"modified"`
|
Modified time.Time `json:"modified"`
|
||||||
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FsListResp struct {
|
type FsListResp struct {
|
||||||
@ -50,8 +53,9 @@ func FsList(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
total, objs := pagination(objs, &req.PageReq)
|
total, objs := pagination(objs, &req.PageReq)
|
||||||
|
baseURL := setting.GetByKey("base_url", c.Request.Host)
|
||||||
common.SuccessResp(c, FsListResp{
|
common.SuccessResp(c, FsListResp{
|
||||||
Content: toObjResp(objs),
|
Content: toObjResp(objs, req.Path, baseURL),
|
||||||
Total: int64(total),
|
Total: int64(total),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -87,7 +91,7 @@ func pagination(objs []model.Obj, req *common.PageReq) (int, []model.Obj) {
|
|||||||
return total, objs[start:end]
|
return total, objs[start:end]
|
||||||
}
|
}
|
||||||
|
|
||||||
func toObjResp(objs []model.Obj) []ObjResp {
|
func toObjResp(objs []model.Obj, path string, baseURL string) []ObjResp {
|
||||||
var resp []ObjResp
|
var resp []ObjResp
|
||||||
for _, obj := range objs {
|
for _, obj := range objs {
|
||||||
resp = append(resp, ObjResp{
|
resp = append(resp, ObjResp{
|
||||||
@ -95,6 +99,8 @@ func toObjResp(objs []model.Obj) []ObjResp {
|
|||||||
Size: obj.GetSize(),
|
Size: obj.GetSize(),
|
||||||
IsDir: obj.IsDir(),
|
IsDir: obj.IsDir(),
|
||||||
Modified: obj.ModTime(),
|
Modified: obj.ModTime(),
|
||||||
|
// TODO: sign url
|
||||||
|
URL: fmt.Sprintf("%s/d%s", baseURL, stdpath.Join(path, obj.GetName())),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return resp
|
return resp
|
||||||
|
Loading…
x
Reference in New Issue
Block a user