Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
f0181d92cd | |||
5ac6a30c56 | |||
96d8a382e8 | |||
7c32af4649 | |||
03dbb3a403 | |||
a570e4c7a0 | |||
539c47bd3b | |||
b6d9018ebd | |||
c929888e39 | |||
af946ff13e |
@ -164,7 +164,7 @@ func (d *Pan123) Remove(ctx context.Context, obj model.Obj) error {
|
|||||||
"operation": true,
|
"operation": true,
|
||||||
"fileTrashInfoList": []File{f},
|
"fileTrashInfoList": []File{f},
|
||||||
}
|
}
|
||||||
_, err := d.request("https://www.123pan.com/a/api/file/trash", http.MethodPost, func(req *resty.Request) {
|
_, err := d.request("https://www.123pan.com/b/api/file/trash", http.MethodPost, func(req *resty.Request) {
|
||||||
req.SetBody(data)
|
req.SetBody(data)
|
||||||
}, nil)
|
}, nil)
|
||||||
return err
|
return err
|
||||||
|
@ -93,6 +93,7 @@ func (d *AliyundriveShare) Link(ctx context.Context, file model.Obj, args model.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
var u string
|
||||||
if e.Code != "" {
|
if e.Code != "" {
|
||||||
if e.Code == "AccessTokenInvalid" {
|
if e.Code == "AccessTokenInvalid" {
|
||||||
err = d.refreshToken()
|
err = d.refreshToken()
|
||||||
@ -100,14 +101,47 @@ func (d *AliyundriveShare) Link(ctx context.Context, file model.Obj, args model.
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return d.Link(ctx, file, args)
|
return d.Link(ctx, file, args)
|
||||||
|
} else if e.Code == "ForbiddenNoPermission.File" {
|
||||||
|
data = utils.MergeMap(data, base.Json{
|
||||||
|
// Only ten minutes valid
|
||||||
|
"expire_sec": 600,
|
||||||
|
"share_id": d.ShareId,
|
||||||
|
})
|
||||||
|
var resp ShareLinkResp
|
||||||
|
var e2 ErrorResp
|
||||||
|
_, err = base.RestyClient.R().
|
||||||
|
SetError(&e2).SetBody(data).SetResult(&resp).
|
||||||
|
SetHeader("content-type", "application/json").
|
||||||
|
SetHeader("Authorization", "Bearer\t"+d.AccessToken).
|
||||||
|
SetHeader("x-share-token", d.ShareToken).
|
||||||
|
Post("https://api.aliyundrive.com/v2/file/get_share_link_download_url")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if e2.Code != "" {
|
||||||
|
if e2.Code == "AccessTokenInvalid" || e2.Code == "ShareLinkTokenInvalid" {
|
||||||
|
err = d.getShareToken()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return d.Link(ctx, file, args)
|
||||||
|
} else {
|
||||||
|
return nil, errors.New(e2.Code + ":" + e2.Message)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
u = resp.DownloadUrl
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return nil, errors.New(e.Code + ":" + e.Message)
|
||||||
}
|
}
|
||||||
return nil, errors.New(e.Message)
|
} else {
|
||||||
|
u = utils.Json.Get(res.Body(), "url").ToString()
|
||||||
}
|
}
|
||||||
return &model.Link{
|
return &model.Link{
|
||||||
Header: http.Header{
|
Header: http.Header{
|
||||||
"Referer": []string{"https://www.aliyundrive.com/"},
|
"Referer": []string{"https://www.aliyundrive.com/"},
|
||||||
},
|
},
|
||||||
URL: utils.Json.Get(res.Body(), "url").ToString(),
|
URL: u,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +50,8 @@ func fileToObj(f File) *model.ObjThumb {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//type ShareLinkResp struct {
|
type ShareLinkResp struct {
|
||||||
// DownloadUrl string `json:"download_url"`
|
DownloadUrl string `json:"download_url"`
|
||||||
// Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
// Thumbnail string `json:"thumbnail"`
|
Thumbnail string `json:"thumbnail"`
|
||||||
//}
|
}
|
||||||
|
@ -80,7 +80,7 @@ func (d *AliyundriveShare) getFiles(fileId string) ([]File, error) {
|
|||||||
}
|
}
|
||||||
log.Debugf("aliyundrive share get files: %s", res.String())
|
log.Debugf("aliyundrive share get files: %s", res.String())
|
||||||
if e.Code != "" {
|
if e.Code != "" {
|
||||||
if e.Code == "AccessTokenInvalid" {
|
if e.Code == "AccessTokenInvalid" || e.Code == "ShareLinkTokenInvalid" {
|
||||||
err = d.getShareToken()
|
err = d.getShareToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -333,6 +333,7 @@ func (d *BaiduPhoto) linkAlbum(ctx context.Context, file model.Obj, args model.L
|
|||||||
URL: res.Header().Get("location"),
|
URL: res.Header().Get("location"),
|
||||||
Header: http.Header{
|
Header: http.Header{
|
||||||
"User-Agent": []string{headers["User-Agent"]},
|
"User-Agent": []string{headers["User-Agent"]},
|
||||||
|
"Referer": []string{"https://photo.baidu.com/"},
|
||||||
},
|
},
|
||||||
//Expiration: &exp,
|
//Expiration: &exp,
|
||||||
}
|
}
|
||||||
@ -369,6 +370,7 @@ func (d *BaiduPhoto) linkFile(ctx context.Context, file model.Obj, args model.Li
|
|||||||
URL: downloadUrl.Dlink,
|
URL: downloadUrl.Dlink,
|
||||||
Header: http.Header{
|
Header: http.Header{
|
||||||
"User-Agent": []string{headers["User-Agent"]},
|
"User-Agent": []string{headers["User-Agent"]},
|
||||||
|
"Referer": []string{"https://photo.baidu.com/"},
|
||||||
},
|
},
|
||||||
//Expiration: &exp,
|
//Expiration: &exp,
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,8 @@ func InitAria2() {
|
|||||||
go func() {
|
go func() {
|
||||||
_, err := aria2.InitClient(2)
|
_, err := aria2.InitClient(2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Log.Errorf("failed to init aria2 client: %+v", err)
|
//utils.Log.Errorf("failed to init aria2 client: %+v", err)
|
||||||
|
utils.Log.Infof("Aria2 not ready.")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func initSettings() {
|
|||||||
// insert new items
|
// insert new items
|
||||||
for i := range initialSettingItems {
|
for i := range initialSettingItems {
|
||||||
v := initialSettingItems[i]
|
v := initialSettingItems[i]
|
||||||
_, err := db.GetSettingItemByKey(v.Key)
|
stored, err := db.GetSettingItemByKey(v.Key)
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) || v.Key == conf.VERSION {
|
if errors.Is(err, gorm.ErrRecordNotFound) || v.Key == conf.VERSION {
|
||||||
err = db.SaveSettingItem(v)
|
err = db.SaveSettingItem(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -42,6 +42,12 @@ func initSettings() {
|
|||||||
}
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
log.Fatalf("failed get setting: %+v", err)
|
log.Fatalf("failed get setting: %+v", err)
|
||||||
|
} else {
|
||||||
|
v.Value = stored.Value
|
||||||
|
err = db.SaveSettingItem(v)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed resave setting: %+v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,14 +71,14 @@ func InitialSettings() []model.SettingItem {
|
|||||||
initialSettingItems = []model.SettingItem{
|
initialSettingItems = []model.SettingItem{
|
||||||
// site settings
|
// site settings
|
||||||
{Key: conf.VERSION, Value: conf.Version, Type: conf.TypeString, Group: model.SITE, Flag: model.READONLY},
|
{Key: conf.VERSION, Value: conf.Version, Type: conf.TypeString, Group: model.SITE, Flag: model.READONLY},
|
||||||
{Key: conf.ApiUrl, Value: "", Type: conf.TypeString, Group: model.SITE},
|
//{Key: conf.ApiUrl, Value: "", Type: conf.TypeString, Group: model.SITE},
|
||||||
{Key: conf.BasePath, Value: "", Type: conf.TypeString, Group: model.SITE},
|
//{Key: conf.BasePath, Value: "", Type: conf.TypeString, Group: model.SITE},
|
||||||
{Key: conf.SiteTitle, Value: "AList", Type: conf.TypeString, Group: model.SITE},
|
{Key: conf.SiteTitle, Value: "AList", Type: conf.TypeString, Group: model.SITE},
|
||||||
{Key: conf.Announcement, Value: "### repo\nhttps://github.com/alist-org/alist", Type: conf.TypeText, Group: model.SITE},
|
{Key: conf.Announcement, Value: "### repo\nhttps://github.com/alist-org/alist", Type: conf.TypeText, Group: model.SITE},
|
||||||
{Key: "pagination_type", Value: "all", Type: conf.TypeSelect, Options: "all,pagination,load_more,auto_load_more", Group: model.SITE},
|
{Key: "pagination_type", Value: "all", Type: conf.TypeSelect, Options: "all,pagination,load_more,auto_load_more", Group: model.SITE},
|
||||||
{Key: "default_page_size", Value: "30", Type: conf.TypeNumber, Group: model.SITE},
|
{Key: "default_page_size", Value: "30", Type: conf.TypeNumber, Group: model.SITE},
|
||||||
// style settings
|
// style settings
|
||||||
{Key: conf.Logo, Value: "https://cdn.jsdelivr.net/gh/alist-org/logo@main/logo.svg", Type: conf.TypeString, Group: model.STYLE},
|
{Key: conf.Logo, Value: "https://cdn.jsdelivr.net/gh/alist-org/logo@main/logo.svg", Type: conf.TypeText, Group: model.STYLE},
|
||||||
{Key: conf.Favicon, Value: "https://cdn.jsdelivr.net/gh/alist-org/logo@main/logo.svg", Type: conf.TypeString, Group: model.STYLE},
|
{Key: conf.Favicon, Value: "https://cdn.jsdelivr.net/gh/alist-org/logo@main/logo.svg", Type: conf.TypeString, Group: model.STYLE},
|
||||||
{Key: conf.MainColor, Value: "#1890ff", Type: conf.TypeString, Group: model.STYLE},
|
{Key: conf.MainColor, Value: "#1890ff", Type: conf.TypeString, Group: model.STYLE},
|
||||||
{Key: "home_icon", Value: "🏠", Type: conf.TypeString, Group: model.STYLE},
|
{Key: "home_icon", Value: "🏠", Type: conf.TypeString, Group: model.STYLE},
|
||||||
@ -107,7 +113,7 @@ func InitialSettings() []model.SettingItem {
|
|||||||
// global settings
|
// global settings
|
||||||
{Key: conf.HideFiles, Value: "/\\/README.md/i", Type: conf.TypeText, Group: model.GLOBAL},
|
{Key: conf.HideFiles, Value: "/\\/README.md/i", Type: conf.TypeText, Group: model.GLOBAL},
|
||||||
{Key: "package_download", Value: "true", Type: conf.TypeBool, Group: model.GLOBAL},
|
{Key: "package_download", Value: "true", Type: conf.TypeBool, Group: model.GLOBAL},
|
||||||
{Key: conf.CustomizeHead,Value:`<script src="https://polyfill.io/v3/polyfill.min.js?features=String.prototype.replaceAll"></script>`, Type: conf.TypeText, Group: model.GLOBAL, Flag: model.PRIVATE},
|
{Key: conf.CustomizeHead, Value: `<script src="https://polyfill.io/v3/polyfill.min.js?features=String.prototype.replaceAll"></script>`, Type: conf.TypeText, Group: model.GLOBAL, Flag: model.PRIVATE},
|
||||||
{Key: conf.CustomizeBody, Type: conf.TypeText, Group: model.GLOBAL, Flag: model.PRIVATE},
|
{Key: conf.CustomizeBody, Type: conf.TypeText, Group: model.GLOBAL, Flag: model.PRIVATE},
|
||||||
{Key: conf.LinkExpiration, Value: "0", Type: conf.TypeNumber, Group: model.GLOBAL, Flag: model.PRIVATE},
|
{Key: conf.LinkExpiration, Value: "0", Type: conf.TypeNumber, Group: model.GLOBAL, Flag: model.PRIVATE},
|
||||||
{Key: conf.PrivacyRegs, Value: `(?:(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])
|
{Key: conf.PrivacyRegs, Value: `(?:(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])
|
||||||
|
@ -23,7 +23,7 @@ type Scheme struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type LogConfig struct {
|
type LogConfig struct {
|
||||||
Enable bool `json:"enable" env:"log_enable"`
|
Enable bool `json:"enable" env:"LOG_ENABLE"`
|
||||||
Name string `json:"name" env:"LOG_NAME"`
|
Name string `json:"name" env:"LOG_NAME"`
|
||||||
MaxSize int `json:"max_size" env:"MAX_SIZE"`
|
MaxSize int `json:"max_size" env:"MAX_SIZE"`
|
||||||
MaxBackups int `json:"max_backups" env:"MAX_BACKUPS"`
|
MaxBackups int `json:"max_backups" env:"MAX_BACKUPS"`
|
||||||
@ -32,16 +32,16 @@ type LogConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Force bool `json:"force"`
|
Force bool `json:"force" env:"FORCE"`
|
||||||
Address string `json:"address" env:"ADDR"`
|
Address string `json:"address" env:"ADDR"`
|
||||||
Port int `json:"port" env:"PORT"`
|
Port int `json:"port" env:"PORT"`
|
||||||
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
|
SiteURL string `json:"site_url" env:"SITE_URL"`
|
||||||
// CaCheExpiration int `json:"cache_expiration" env:"CACHE_EXPIRATION"`
|
Cdn string `json:"cdn" env:"CDN"`
|
||||||
Cdn string `json:"cdn" env:"CDN"`
|
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
|
||||||
Database Database `json:"database"`
|
Database Database `json:"database"`
|
||||||
Scheme Scheme `json:"scheme"`
|
Scheme Scheme `json:"scheme"`
|
||||||
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
|
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
|
||||||
Log LogConfig `json:"log"`
|
Log LogConfig `json:"log"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultConfig() *Config {
|
func DefaultConfig() *Config {
|
||||||
|
@ -58,7 +58,7 @@ func SortFiles(objs []Obj, orderBy, orderDirection string) {
|
|||||||
}
|
}
|
||||||
return objs[i].GetSize() <= objs[j].GetSize()
|
return objs[i].GetSize() <= objs[j].GetSize()
|
||||||
}
|
}
|
||||||
case "updated_at":
|
case "modified":
|
||||||
if orderDirection == "desc" {
|
if orderDirection == "desc" {
|
||||||
return objs[i].ModTime().After(objs[j].ModTime())
|
return objs[i].ModTime().After(objs[j].ModTime())
|
||||||
}
|
}
|
||||||
|
@ -10,15 +10,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GetApiUrl(r *http.Request) string {
|
func GetApiUrl(r *http.Request) string {
|
||||||
api := setting.GetStr(conf.ApiUrl)
|
api := conf.Conf.SiteURL
|
||||||
protocol := "http"
|
if api == "" {
|
||||||
if r != nil {
|
api = setting.GetStr(conf.ApiUrl)
|
||||||
|
}
|
||||||
|
if r != nil && api == "" {
|
||||||
|
protocol := "http"
|
||||||
if r.TLS != nil {
|
if r.TLS != nil {
|
||||||
protocol = "https"
|
protocol = "https"
|
||||||
}
|
}
|
||||||
if api == "" {
|
api = fmt.Sprintf("%s://%s", protocol, r.Host)
|
||||||
api = fmt.Sprintf("%s://%s", protocol, r.Host)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
strings.TrimSuffix(api, "/")
|
strings.TrimSuffix(api, "/")
|
||||||
return api
|
return api
|
||||||
|
36
server/static/config.go
Normal file
36
server/static/config.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package static
|
||||||
|
|
||||||
|
import (
|
||||||
|
stdpath "path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
|
"github.com/alist-org/alist/v3/internal/setting"
|
||||||
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SiteConfig struct {
|
||||||
|
ApiURL string
|
||||||
|
BasePath string
|
||||||
|
Cdn string
|
||||||
|
}
|
||||||
|
|
||||||
|
func getSiteConfig() SiteConfig {
|
||||||
|
siteConfig := SiteConfig{
|
||||||
|
ApiURL: conf.Conf.SiteURL,
|
||||||
|
BasePath: stdpath.Base(conf.Conf.SiteURL),
|
||||||
|
Cdn: strings.ReplaceAll(strings.TrimSuffix(conf.Conf.Cdn, "/"), "$version", conf.WebVersion),
|
||||||
|
}
|
||||||
|
// try to get old config
|
||||||
|
if siteConfig.ApiURL == "" {
|
||||||
|
siteConfig.ApiURL = setting.GetStr(conf.ApiUrl)
|
||||||
|
siteConfig.BasePath = setting.GetStr(conf.BasePath)
|
||||||
|
}
|
||||||
|
if siteConfig.BasePath != "" {
|
||||||
|
siteConfig.BasePath = utils.StandardizePath(siteConfig.BasePath)
|
||||||
|
}
|
||||||
|
if siteConfig.Cdn == "" {
|
||||||
|
siteConfig.Cdn = siteConfig.BasePath
|
||||||
|
}
|
||||||
|
return siteConfig
|
||||||
|
}
|
@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/alist-org/alist/v3/cmd/flags"
|
"github.com/alist-org/alist/v3/cmd/flags"
|
||||||
"github.com/alist-org/alist/v3/internal/conf"
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
"github.com/alist-org/alist/v3/internal/setting"
|
"github.com/alist-org/alist/v3/internal/setting"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
|
||||||
"github.com/alist-org/alist/v3/public"
|
"github.com/alist-org/alist/v3/public"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -26,16 +25,7 @@ func InitIndex() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func UpdateIndex() {
|
func UpdateIndex() {
|
||||||
cdn := strings.TrimSuffix(conf.Conf.Cdn, "/")
|
siteConfig := getSiteConfig()
|
||||||
cdn = strings.ReplaceAll(cdn, "$version", conf.WebVersion)
|
|
||||||
basePath := setting.GetStr(conf.BasePath)
|
|
||||||
if basePath != "" {
|
|
||||||
basePath = utils.StandardizePath(basePath)
|
|
||||||
}
|
|
||||||
if cdn == "" {
|
|
||||||
cdn = basePath
|
|
||||||
}
|
|
||||||
apiUrl := setting.GetStr(conf.ApiUrl)
|
|
||||||
favicon := setting.GetStr(conf.Favicon)
|
favicon := setting.GetStr(conf.Favicon)
|
||||||
title := setting.GetStr(conf.SiteTitle)
|
title := setting.GetStr(conf.SiteTitle)
|
||||||
customizeHead := setting.GetStr(conf.CustomizeHead)
|
customizeHead := setting.GetStr(conf.CustomizeHead)
|
||||||
@ -45,9 +35,9 @@ func UpdateIndex() {
|
|||||||
replaceMap1 := map[string]string{
|
replaceMap1 := map[string]string{
|
||||||
"https://jsd.nn.ci/gh/alist-org/logo@main/logo.svg": favicon,
|
"https://jsd.nn.ci/gh/alist-org/logo@main/logo.svg": favicon,
|
||||||
"Loading...": title,
|
"Loading...": title,
|
||||||
"cdn: undefined": fmt.Sprintf("cdn: '%s'", cdn),
|
"cdn: undefined": fmt.Sprintf("cdn: '%s'", siteConfig.Cdn),
|
||||||
"base_path: undefined": fmt.Sprintf("base_path: '%s'", basePath),
|
"base_path: undefined": fmt.Sprintf("base_path: '%s'", siteConfig.BasePath),
|
||||||
"api: undefined": fmt.Sprintf("api: '%s'", apiUrl),
|
"api: undefined": fmt.Sprintf("api: '%s'", siteConfig.ApiURL),
|
||||||
"main_color: undefined": fmt.Sprintf("main_color: '%s'", mainColor),
|
"main_color: undefined": fmt.Sprintf("main_color: '%s'", mainColor),
|
||||||
}
|
}
|
||||||
for k, v := range replaceMap1 {
|
for k, v := range replaceMap1 {
|
||||||
|
Reference in New Issue
Block a user