feat: impl list

This commit is contained in:
Andy Hsu 2024-01-03 22:27:47 +08:00
parent 9a356ec9d6
commit 7868a1a524
2 changed files with 74 additions and 14 deletions

View File

@ -3,10 +3,14 @@ package template
import (
"context"
"net/http"
"strconv"
"time"
"github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/errs"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus"
)
@ -37,7 +41,51 @@ func (d *ILanZou) Drop(ctx context.Context) error {
}
func (d *ILanZou) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
offset := 1
limit := 60
var res []ListItem
for {
var resp ListResp
_, err := d.proved("/record/file/list", http.MethodGet, func(req *resty.Request) {
req.SetQueryParams(map[string]string{
"type": "0",
"folderId": dir.GetID(),
"offset": strconv.Itoa(offset),
"limit": strconv.Itoa(limit),
}).SetResult(&resp)
})
if err != nil {
return nil, err
}
res = append(res, resp.List...)
if resp.TotalPage <= resp.Offset {
break
}
offset++
}
return utils.SliceConvert(res, func(f ListItem) (model.Obj, error) {
updTime, err := time.ParseInLocation("2006-01-02 15:04:05", f.UpdTime, time.Local)
if err != nil {
return nil, err
}
obj := model.Object{
ID: strconv.FormatInt(f.FileId, 10),
//Path: "",
Name: f.FileName,
Size: f.FileSize * 1024,
Modified: updTime,
Ctime: updTime,
IsFolder: false,
//HashInfo: utils.HashInfo{},
}
if f.FileType == 2 {
obj.IsFolder = true
obj.Size = 0
obj.ID = strconv.FormatInt(f.FolderId, 10)
obj.Name = f.FolderName
}
return &obj, nil
})
}
func (d *ILanZou) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {

View File

@ -11,17 +11,29 @@ type ListResp struct {
}
type ListItem struct {
IconId int `json:"iconId"`
IsAmt int `json:"isAmt"`
FolderDesc string `json:"folderDesc"`
AddTime string `json:"addTime"`
FolderId int `json:"folderId"`
ParentId int `json:"parentId"`
NoteType int `json:"noteType"`
UpdTime string `json:"updTime"`
IsShare int `json:"isShare"`
FolderIcon string `json:"folderIcon"`
FolderName string `json:"folderName"`
FileType int `json:"fileType"`
Status int `json:"status"`
IconId int `json:"iconId"`
IsAmt int `json:"isAmt"`
FolderDesc string `json:"folderDesc,omitempty"`
AddTime string `json:"addTime"`
FolderId int64 `json:"folderId"`
ParentId int64 `json:"parentId"`
ParentName string `json:"parentName"`
NoteType int `json:"noteType,omitempty"`
UpdTime string `json:"updTime"`
IsShare int `json:"isShare"`
FolderIcon string `json:"folderIcon,omitempty"`
FolderName string `json:"folderName,omitempty"`
FileType int `json:"fileType"`
Status int `json:"status"`
IsFileShare int `json:"isFileShare,omitempty"`
FileName string `json:"fileName,omitempty"`
FileStars float64 `json:"fileStars,omitempty"`
IsFileDownload int `json:"isFileDownload,omitempty"`
FileComments int `json:"fileComments,omitempty"`
FileSize int64 `json:"fileSize,omitempty"`
FileIcon string `json:"fileIcon,omitempty"`
FileDownloads int `json:"fileDownloads,omitempty"`
FileUrl interface{} `json:"fileUrl"`
FileLikes int `json:"fileLikes,omitempty"`
FileId int64 `json:"fileId,omitempty"`
}