🚧 密码逻辑
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// build tree
|
// build tree
|
||||||
@@ -20,19 +21,29 @@ func BuildTree() error {
|
|||||||
if err := tx.Error; err != nil {
|
if err := tx.Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := BuildOne(conf.Conf.AliDrive.RootFolder, "/root/", tx); err != nil {
|
if err := BuildOne(conf.Conf.AliDrive.RootFolder, "/root/", tx, ""); err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return tx.Commit().Error
|
return tx.Commit().Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildOne(parent string, path string, tx *gorm.DB) error {
|
func BuildOne(parent string, path string, tx *gorm.DB, parentPassword string) error {
|
||||||
files, err := alidrive.GetList(parent, conf.Conf.AliDrive.MaxFilesCount, "", "", "")
|
files, err := alidrive.GetList(parent, conf.Conf.AliDrive.MaxFilesCount, "", "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, file := range files.Items {
|
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{
|
newFile := File{
|
||||||
ParentPath: path,
|
ParentPath: path,
|
||||||
FileExtension: file.FileExtension,
|
FileExtension: file.FileExtension,
|
||||||
@@ -43,13 +54,14 @@ func BuildOne(parent string, path string, tx *gorm.DB) error {
|
|||||||
Category: file.Category,
|
Category: file.Category,
|
||||||
ContentType: file.ContentType,
|
ContentType: file.ContentType,
|
||||||
Size: file.Size,
|
Size: file.Size,
|
||||||
|
Password: password,
|
||||||
}
|
}
|
||||||
log.Debugf("插入file:%+v", newFile)
|
log.Debugf("插入file:%+v", newFile)
|
||||||
if err := tx.Create(&newFile).Error; err != nil {
|
if err := tx.Create(&newFile).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if file.Type == "folder" {
|
if file.Type == "folder" {
|
||||||
if err := BuildOne(file.FileId, fmt.Sprintf("%s%s/", path, file.Name), tx); err != nil {
|
if err := BuildOne(file.FileId, fmt.Sprintf("%s%s/", path, file.Name), tx, password); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,3 +11,11 @@ func TestSplit(t *testing.T) {
|
|||||||
strs := strings.Split(drive_id, "/")
|
strs := strings.Split(drive_id, "/")
|
||||||
fmt.Println(strs)
|
fmt.Println(strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPassword(t *testing.T) {
|
||||||
|
fullName:="hello.password-xhf"
|
||||||
|
index:=strings.Index(fullName,".password-")
|
||||||
|
name:=fullName[:index]
|
||||||
|
password:=fullName[index+10:]
|
||||||
|
fmt.Printf("name:%s, password:%s\n",name,password)
|
||||||
|
}
|
@@ -16,3 +16,4 @@ func TestWriteYml(t *testing.T) {
|
|||||||
alidrive.RefreshToken()
|
alidrive.RefreshToken()
|
||||||
utils.WriteToYml("../conf.yml", conf.Conf)
|
utils.WriteToYml("../conf.yml", conf.Conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user