Skip to content

Commit e36c68e

Browse files
committed
feat(api): add virtual_path field on fs/list and fs/get responses
The existing `path` field on ObjResp/ObjLabelResp returns whatever the storage driver writes into model.Object.Path, and that contract has quietly diverged across drivers: - Local sets it to the physical disk path (e.g. `/data/data/com.termux/files/home/storage/download/foo.tar.gz`) - Cloud drivers (Quark / Baidu / 115 / …) leave it empty - Some other drivers fill it with their own internal id-like path Clients that need the canonical alist virtual path (e.g. for `share`, `fs/copy`, navigation) cannot rely on `path` alone. The frontend has been working around this with branchy code such as `pathJoin(getCurrentPath(), name)` in some places and `obj.path` in others; one such mismatch caused a share regression on Local mounts whose root_folder_path differs from the mount path (visible as `failed get storage: storage not found; rawPath: ...`). Add a `virtual_path` field that is always the alist virtual path for the object: - `toObjsResp` -> `FixAndCleanPath(stdpath.Join(parent, obj.Name))` - `FsGet` -> `FixAndCleanPath(reqPath)` `path` is left untouched for backwards compatibility. Clients should prefer `virtual_path` for anything that talks to other alist APIs.
1 parent f4445c5 commit e36c68e

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

‎server/handles/fsread.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type DirReq struct {
3535
type ObjResp struct {
3636
Id string `json:"id"`
3737
Path string `json:"path"`
38+
VirtualPath string `json:"virtual_path"`
3839
Name string `json:"name"`
3940
Size int64 `json:"size"`
4041
IsDir bool `json:"is_dir"`
@@ -65,6 +66,7 @@ type FsListResp struct {
6566
type ObjLabelResp struct {
6667
Id string `json:"id"`
6768
Path string `json:"path"`
69+
VirtualPath string `json:"virtual_path"`
6870
Name string `json:"name"`
6971
Size int64 `json:"size"`
7072
IsDir bool `json:"is_dir"`
@@ -318,6 +320,7 @@ func toObjsResp(objs []model.Obj, parent string, encrypt bool) []ObjLabelResp {
318320
resp = append(resp, ObjLabelResp{
319321
Id: obj.GetID(),
320322
Path: obj.GetPath(),
323+
VirtualPath: utils.FixAndCleanPath(stdpath.Join(parent, obj.GetName())),
321324
Name: obj.GetName(),
322325
Size: obj.GetSize(),
323326
IsDir: obj.IsDir(),
@@ -452,6 +455,7 @@ func FsGet(c *gin.Context) {
452455
ObjResp: ObjResp{
453456
Id: obj.GetID(),
454457
Path: obj.GetPath(),
458+
VirtualPath: utils.FixAndCleanPath(reqPath),
455459
Name: obj.GetName(),
456460
Size: obj.GetSize(),
457461
IsDir: obj.IsDir(),

0 commit comments

Comments
 (0)