Skip to content

Commit

Permalink
🐛 fix: #101 分次请求文件
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Apr 30, 2021
1 parent 427244d commit b20f071
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
2 changes: 1 addition & 1 deletion conf.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ server:
password: password #用于重建目录
ali_drive:
api_url: https://api.aliyundrive.com/v2
max_files_count: 3000
max_files_count: 50 #重建目录时每次请求的文件
drives:
- refresh_token: xxx #refresh_token
root_folder: root #根目录的file_id
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Path(c *gin.Context) {
if err != nil {
// folder model not exist
if file == nil {
c.JSON(200, MetaResponse(404, "path not found."))
c.JSON(200, MetaResponse(404, "path not found.(第一次请先点击网页底部rebuild)"))
return
}
c.JSON(200, MetaResponse(500, err.Error()))
Expand Down
69 changes: 38 additions & 31 deletions server/models/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,42 +62,49 @@ func BuildOne(parent string, path string, tx *gorm.DB, parentPassword string, dr
if depth == 0 {
return nil
}
files, err := alidrive.GetList(parent, conf.Conf.AliDrive.MaxFilesCount, "", "", "", drive)
if err != nil {
return err
}
for _, file := range files.Items {
name := file.Name
if strings.HasSuffix(name, ".hide") {
continue
}
password := parentPassword
if strings.Contains(name, ".password-") {
index := strings.Index(name, ".password-")
name = file.Name[:index]
password = file.Name[index+10:]
marker := "first"
for marker != "" {
if marker == "first" {
marker = ""
}
newFile := File{
Dir: path,
FileExtension: file.FileExtension,
FileId: file.FileId,
Name: name,
Type: file.Type,
UpdatedAt: file.UpdatedAt,
Category: file.Category,
ContentType: file.ContentType,
Size: file.Size,
Password: password,
ContentHash: file.ContentHash,
}
log.Debugf("插入file:%+v", newFile)
if err := tx.Create(&newFile).Error; err != nil {
files, err := alidrive.GetList(parent, conf.Conf.AliDrive.MaxFilesCount, marker, "", "", drive)
if err != nil {
return err
}
if file.Type == "folder" {
if err := BuildOne(file.FileId, fmt.Sprintf("%s%s/", path, name), tx, password, drive, depth-1); err != nil {
marker = files.NextMarker
for _, file := range files.Items {
name := file.Name
if strings.HasSuffix(name, ".hide") {
continue
}
password := parentPassword
if strings.Contains(name, ".password-") {
index := strings.Index(name, ".password-")
name = file.Name[:index]
password = file.Name[index+10:]
}
newFile := File{
Dir: path,
FileExtension: file.FileExtension,
FileId: file.FileId,
Name: name,
Type: file.Type,
UpdatedAt: file.UpdatedAt,
Category: file.Category,
ContentType: file.ContentType,
Size: file.Size,
Password: password,
ContentHash: file.ContentHash,
}
log.Debugf("插入file:%+v", newFile)
if err := tx.Create(&newFile).Error; err != nil {
return err
}
if file.Type == "folder" {
if err := BuildOne(file.FileId, fmt.Sprintf("%s%s/", path, name), tx, password, drive, depth-1); err != nil {
return err
}
}
}
}
return nil
Expand Down

0 comments on commit b20f071

Please sign in to comment.