File size: 1,472 Bytes
7107f0b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
package baiduphoto
import (
"fmt"
"math"
"math/rand"
"strings"
"time"
"github.com/alist-org/alist/v3/pkg/utils"
)
// Tid生成
func getTid() string {
return fmt.Sprintf("3%d%.0f", time.Now().Unix(), math.Floor(9000000*rand.Float64()+1000000))
}
func toTime(t int64) *time.Time {
tm := time.Unix(t, 0)
return &tm
}
func fsidsFormatNotUk(ids ...int64) string {
buf := utils.MustSliceConvert(ids, func(id int64) string {
return fmt.Sprintf(`{"fsid":%d}`, id)
})
return fmt.Sprintf("[%s]", strings.Join(buf, ","))
}
func getFileName(path string) string {
return path[strings.LastIndex(path, "/")+1:]
}
func MustString(str string, err error) string {
return str
}
/*
* 处理文件变化
* 最大程度利用重复数据
**/
func copyFile(file *AlbumFile, cf *CopyFile) *File {
return &File{
Fsid: cf.Fsid,
Path: cf.Path,
Ctime: cf.Ctime,
Mtime: cf.Ctime,
Size: file.Size,
Thumburl: file.Thumburl,
}
}
func moveFileToAlbumFile(file *File, album *Album, uk int64) *AlbumFile {
return &AlbumFile{
File: *file,
AlbumID: album.AlbumID,
Tid: album.Tid,
Uk: uk,
}
}
func renameAlbum(album *Album, newName string) *Album {
return &Album{
AlbumID: album.AlbumID,
Tid: album.Tid,
JoinTime: album.JoinTime,
CreationTime: album.CreationTime,
Title: newName,
Mtime: time.Now().Unix(),
}
}
func BoolToIntStr(b bool) string {
if b {
return "1"
}
return "0"
}
|