Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
f31fc9155a | |||
d3db012dd0 | |||
74b86ef5e5 | |||
6be90429ad | |||
a6bbff2199 | |||
3827d3ed67 | |||
e242867f41 | |||
e09a75a87c | |||
e0a80b1477 |
@ -1,6 +1,6 @@
|
||||
package alidrive
|
||||
|
||||
// list request bean
|
||||
// ListReq list request bean
|
||||
type ListReq struct {
|
||||
DriveId string `json:"drive_id"`
|
||||
Fields string `json:"fields"`
|
||||
@ -14,7 +14,7 @@ type ListReq struct {
|
||||
VideoThumbnailProcess string `json:"video_thumbnail_process"`
|
||||
}
|
||||
|
||||
// get request bean
|
||||
// GetReq get request bean
|
||||
type GetReq struct {
|
||||
DriveId string `json:"drive_id"`
|
||||
FileId string `json:"file_id"`
|
||||
@ -22,7 +22,7 @@ type GetReq struct {
|
||||
VideoThumbnailProcess string `json:"video_thumbnail_process"`
|
||||
}
|
||||
|
||||
// download request bean
|
||||
// DownloadReq download request bean
|
||||
type DownloadReq struct {
|
||||
DriveId string `json:"drive_id"`
|
||||
FileId string `json:"file_id"`
|
||||
@ -30,7 +30,7 @@ type DownloadReq struct {
|
||||
FileName string `json:"file_name"`
|
||||
}
|
||||
|
||||
// search request bean
|
||||
// SearchReq search request bean
|
||||
type SearchReq struct {
|
||||
DriveId string `json:"drive_id"`
|
||||
ImageThumbnailProcess string `json:"image_thumbnail_process"`
|
||||
@ -44,32 +44,32 @@ type SearchReq struct {
|
||||
VideoThumbnailProcess string `json:"video_thumbnail_process"`
|
||||
}
|
||||
|
||||
// token_login request bean
|
||||
// TokenLoginReq token_login request bean
|
||||
type TokenLoginReq struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
// get_token request bean
|
||||
// GetTokenReq get_token request bean
|
||||
type GetTokenReq struct {
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
// refresh_token request bean
|
||||
// RefreshTokenReq refresh_token request bean
|
||||
type RefreshTokenReq struct {
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
GrantType string `json:"grant_type"`
|
||||
}
|
||||
|
||||
// office_preview_url request bean
|
||||
// OfficePreviewUrlReq office_preview_url request bean
|
||||
type OfficePreviewUrlReq struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
DriveId string `json:"drive_id"`
|
||||
FileId string `json:"file_id"`
|
||||
}
|
||||
|
||||
// video preview url request bean
|
||||
// VideoPreviewUrlReq video preview url request bean
|
||||
type VideoPreviewUrlReq struct {
|
||||
DriveId string `json:"drive_id"`
|
||||
FileId string `json:"file_id"`
|
||||
ExpireSec int `json:"expire_sec"`
|
||||
}
|
||||
}
|
@ -14,7 +14,9 @@ func ReadConf(config string) bool {
|
||||
log.Infof("读取配置文件...")
|
||||
if !utils.Exists(config) {
|
||||
log.Infof("找不到配置文件:%s", config)
|
||||
return false
|
||||
if !Write(config) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
confFile, err := ioutil.ReadFile(config)
|
||||
if err != nil {
|
||||
@ -31,3 +33,52 @@ func ReadConf(config string) bool {
|
||||
conf.Origins = strings.Split(conf.Conf.Server.SiteUrl, ",")
|
||||
return true
|
||||
}
|
||||
func Write(path string) bool {
|
||||
log.Infof("创建默认配置文件")
|
||||
file, err := utils.CreatNestedFile(path)
|
||||
if err != nil {
|
||||
log.Errorf("无法创建配置文件, %s", err)
|
||||
return false
|
||||
}
|
||||
defer func() {
|
||||
_ = file.Close()
|
||||
}()
|
||||
str := `
|
||||
info:
|
||||
title: AList #标题
|
||||
logo: "" #网站logo 如果填写,则会替换掉默认的
|
||||
footer_text: Xhofe's Blog #网页底部文字
|
||||
footer_url: https://www.nn.ci #网页底部文字链接
|
||||
music_img: https://img.xhofe.top/2020/12/19/0f8b57866bdb5.gif #预览音乐文件时的图片
|
||||
check_update: true #前端是否显示更新
|
||||
script: #自定义脚本,可以是脚本的链接,也可以直接是脚本内容
|
||||
autoplay: true #视频是否自动播放
|
||||
preview:
|
||||
text: [txt,htm,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,yml,go,sh,c,cpp,h,hpp] #要预览的文本文件的后缀,可以自行添加
|
||||
server:
|
||||
address: "0.0.0.0"
|
||||
port: "5244"
|
||||
search: true
|
||||
static: dist
|
||||
site_url: '*'
|
||||
password: password #用于重建目录
|
||||
ali_drive:
|
||||
api_url: https://api.aliyundrive.com/v2
|
||||
max_files_count: 100
|
||||
drives:
|
||||
- refresh_token: xxx #refresh_token
|
||||
root_folder: root #根目录的file_id
|
||||
name: drive0 #盘名,多个盘不可重复,这里只是示例,不是一定要叫这个名字,可随意修改
|
||||
password: pass #该盘密码,空('')则不设密码,修改需要重建生效
|
||||
hide: false #是否在主页隐藏该盘,不可全部隐藏,至少暴露一个
|
||||
database:
|
||||
type: sqlite3
|
||||
dBFile: alist.db
|
||||
`
|
||||
_, err = file.WriteString(str)
|
||||
if err != nil {
|
||||
log.Errorf("无法写入配置文件, %s", err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ var (
|
||||
var Conf = new(Config)
|
||||
|
||||
const (
|
||||
VERSION = "v1.0.4"
|
||||
VERSION = "v1.0.5"
|
||||
|
||||
ImageThumbnailProcess = "image/resize,w_50"
|
||||
VideoThumbnailProcess = "video/snapshot,t_0,f_jpg,w_50"
|
||||
|
@ -1,24 +1,25 @@
|
||||
package controllers
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Data interface{} `json:"data"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// common meta response
|
||||
func MetaResponse(code int, msg string) gin.H {
|
||||
return gin.H{
|
||||
"meta": gin.H{
|
||||
"code": code,
|
||||
"msg": msg,
|
||||
},
|
||||
// MetaResponse common meta response
|
||||
func MetaResponse(code int, msg string) Response {
|
||||
return Response{
|
||||
Code: code,
|
||||
Data: nil,
|
||||
Message: msg,
|
||||
}
|
||||
}
|
||||
|
||||
// common data response
|
||||
func DataResponse(data interface{}) gin.H {
|
||||
return gin.H{
|
||||
"meta": gin.H{
|
||||
"code": 200,
|
||||
"msg": "success",
|
||||
},
|
||||
"data": data,
|
||||
// DataResponse common data response
|
||||
func DataResponse(data interface{}) Response {
|
||||
return Response{
|
||||
Code: 200,
|
||||
Data: data,
|
||||
Message: "ok",
|
||||
}
|
||||
}
|
||||
|
@ -74,10 +74,35 @@ func BuildOne(parent string, path string, tx *gorm.DB, parentPassword string, dr
|
||||
marker = files.NextMarker
|
||||
for _, file := range files.Items {
|
||||
name := file.Name
|
||||
password := parentPassword
|
||||
if strings.HasSuffix(name, ".hide") {
|
||||
continue
|
||||
}
|
||||
password := parentPassword
|
||||
if strings.Contains(name, ".ln-") {
|
||||
index := strings.Index(name, ".ln-")
|
||||
name = file.Name[:index]
|
||||
fileId := file.Name[index+4:]
|
||||
newFile := File{
|
||||
Dir: path,
|
||||
FileExtension: "",
|
||||
FileId: fileId,
|
||||
Name: name,
|
||||
Type: "folder",
|
||||
UpdatedAt: file.UpdatedAt,
|
||||
Category: "",
|
||||
ContentType: "",
|
||||
Size: 0,
|
||||
Password: password,
|
||||
}
|
||||
log.Debugf("插入file:%+v", newFile)
|
||||
if err = tx.Create(&newFile).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err = BuildOne(fileId, fmt.Sprintf("%s%s/", path, name), tx, password, drive, depth-1); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
if strings.Contains(name, ".password-") {
|
||||
index := strings.Index(name, ".password-")
|
||||
name = file.Name[:index]
|
||||
|
Reference in New Issue
Block a user