Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
dc73c2e97d | |||
a624121095 | |||
9d9c79179b | |||
b7479651e1 | |||
2fc0ccbfe0 | |||
f86ad1dce4 | |||
f0181d92cd | |||
5ac6a30c56 | |||
96d8a382e8 | |||
7c32af4649 | |||
03dbb3a403 | |||
a570e4c7a0 | |||
539c47bd3b | |||
b6d9018ebd | |||
c929888e39 | |||
af946ff13e |
1
.github/workflows/issue_close_inactive.yml
vendored
1
.github/workflows/issue_close_inactive.yml
vendored
@ -3,6 +3,7 @@ name: Close inactive
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 0 */7 * *"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
close-inactive:
|
||||
|
1
.github/workflows/issue_close_question.yml
vendored
1
.github/workflows/issue_close_question.yml
vendored
@ -3,6 +3,7 @@ name: Close need info
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 0 */7 * *"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
close-need-info:
|
||||
|
@ -164,7 +164,7 @@ func (d *Pan123) Remove(ctx context.Context, obj model.Obj) error {
|
||||
"operation": true,
|
||||
"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)
|
||||
}, nil)
|
||||
return err
|
||||
|
@ -93,6 +93,7 @@ func (d *AliyundriveShare) Link(ctx context.Context, file model.Obj, args model.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var u string
|
||||
if e.Code != "" {
|
||||
if e.Code == "AccessTokenInvalid" {
|
||||
err = d.refreshToken()
|
||||
@ -100,14 +101,47 @@ func (d *AliyundriveShare) Link(ctx context.Context, file model.Obj, args model.
|
||||
return nil, err
|
||||
}
|
||||
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{
|
||||
Header: http.Header{
|
||||
"Referer": []string{"https://www.aliyundrive.com/"},
|
||||
},
|
||||
URL: utils.Json.Get(res.Body(), "url").ToString(),
|
||||
URL: u,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -50,8 +50,8 @@ func fileToObj(f File) *model.ObjThumb {
|
||||
}
|
||||
}
|
||||
|
||||
//type ShareLinkResp struct {
|
||||
// DownloadUrl string `json:"download_url"`
|
||||
// Url string `json:"url"`
|
||||
// Thumbnail string `json:"thumbnail"`
|
||||
//}
|
||||
type ShareLinkResp struct {
|
||||
DownloadUrl string `json:"download_url"`
|
||||
Url string `json:"url"`
|
||||
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())
|
||||
if e.Code != "" {
|
||||
if e.Code == "AccessTokenInvalid" {
|
||||
if e.Code == "AccessTokenInvalid" || e.Code == "ShareLinkTokenInvalid" {
|
||||
err = d.getShareToken()
|
||||
if err != nil {
|
||||
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"),
|
||||
Header: http.Header{
|
||||
"User-Agent": []string{headers["User-Agent"]},
|
||||
"Referer": []string{"https://photo.baidu.com/"},
|
||||
},
|
||||
//Expiration: &exp,
|
||||
}
|
||||
@ -369,6 +370,7 @@ func (d *BaiduPhoto) linkFile(ctx context.Context, file model.Obj, args model.Li
|
||||
URL: downloadUrl.Dlink,
|
||||
Header: http.Header{
|
||||
"User-Agent": []string{headers["User-Agent"]},
|
||||
"Referer": []string{"https://photo.baidu.com/"},
|
||||
},
|
||||
//Expiration: &exp,
|
||||
}
|
||||
|
@ -6,10 +6,9 @@ import (
|
||||
)
|
||||
|
||||
func InitAria2() {
|
||||
go func() {
|
||||
_, err := aria2.InitClient(2)
|
||||
if err != nil {
|
||||
utils.Log.Errorf("failed to init aria2 client: %+v", err)
|
||||
}
|
||||
}()
|
||||
_, err := aria2.InitClient(2)
|
||||
if err != nil {
|
||||
//utils.Log.Errorf("failed to init aria2 client: %+v", err)
|
||||
utils.Log.Infof("Aria2 not ready.")
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@ -25,7 +24,7 @@ func InitConfig() {
|
||||
log.Fatalf("failed to create default config file")
|
||||
}
|
||||
} else {
|
||||
configBytes, err := ioutil.ReadFile(flags.Config)
|
||||
configBytes, err := os.ReadFile(flags.Config)
|
||||
if err != nil {
|
||||
log.Fatalf("reading config file error: %+v", err)
|
||||
}
|
||||
@ -39,7 +38,7 @@ func InitConfig() {
|
||||
if err != nil {
|
||||
log.Fatalf("marshal config error: %+v", err)
|
||||
}
|
||||
err = ioutil.WriteFile(flags.Config, confBody, 0777)
|
||||
err = os.WriteFile(flags.Config, confBody, 0777)
|
||||
if err != nil {
|
||||
log.Fatalf("update config struct error: %+v", err)
|
||||
}
|
||||
@ -59,7 +58,7 @@ func InitConfig() {
|
||||
if err != nil {
|
||||
log.Errorln("failed delete temp file:", err)
|
||||
}
|
||||
err = os.MkdirAll(conf.Conf.TempDir, 0700)
|
||||
err = os.MkdirAll(conf.Conf.TempDir, 0777)
|
||||
if err != nil {
|
||||
log.Fatalf("create temp dir error: %+v", err)
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func initSettings() {
|
||||
// insert new items
|
||||
for i := range initialSettingItems {
|
||||
v := initialSettingItems[i]
|
||||
_, err := db.GetSettingItemByKey(v.Key)
|
||||
stored, err := db.GetSettingItemByKey(v.Key)
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) || v.Key == conf.VERSION {
|
||||
err = db.SaveSettingItem(v)
|
||||
if err != nil {
|
||||
@ -42,6 +42,12 @@ func initSettings() {
|
||||
}
|
||||
} else if err != nil {
|
||||
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{
|
||||
// site settings
|
||||
{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.BasePath, 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.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: "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},
|
||||
// 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.MainColor, Value: "#1890ff", 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
|
||||
{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: 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.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])
|
||||
|
@ -23,7 +23,7 @@ type Scheme 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"`
|
||||
MaxSize int `json:"max_size" env:"MAX_SIZE"`
|
||||
MaxBackups int `json:"max_backups" env:"MAX_BACKUPS"`
|
||||
@ -32,32 +32,32 @@ type LogConfig struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Force bool `json:"force"`
|
||||
Address string `json:"address" env:"ADDR"`
|
||||
Port int `json:"port" env:"PORT"`
|
||||
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
|
||||
// CaCheExpiration int `json:"cache_expiration" env:"CACHE_EXPIRATION"`
|
||||
Cdn string `json:"cdn" env:"CDN"`
|
||||
Database Database `json:"database"`
|
||||
Scheme Scheme `json:"scheme"`
|
||||
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
|
||||
Log LogConfig `json:"log"`
|
||||
Force bool `json:"force" env:"FORCE"`
|
||||
Address string `json:"address" env:"ADDR"`
|
||||
Port int `json:"port" env:"PORT"`
|
||||
SiteURL string `json:"site_url" env:"SITE_URL"`
|
||||
Cdn string `json:"cdn" env:"CDN"`
|
||||
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
|
||||
TokenExpiresIn int `json:"token_expires_in" env:"TOKEN_EXPIRES_IN"`
|
||||
Database Database `json:"database"`
|
||||
Scheme Scheme `json:"scheme"`
|
||||
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
|
||||
Log LogConfig `json:"log"`
|
||||
}
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Address: "0.0.0.0",
|
||||
Port: 5244,
|
||||
JwtSecret: random.String(16),
|
||||
Cdn: "",
|
||||
TempDir: "data/temp",
|
||||
Address: "0.0.0.0",
|
||||
Port: 5244,
|
||||
JwtSecret: random.String(16),
|
||||
TokenExpiresIn: 48,
|
||||
TempDir: "data/temp",
|
||||
Database: Database{
|
||||
Type: "sqlite3",
|
||||
Port: 0,
|
||||
TablePrefix: "x_",
|
||||
DBFile: "data/data.db",
|
||||
},
|
||||
// CaCheExpiration: 30,
|
||||
Log: LogConfig{
|
||||
Enable: true,
|
||||
Name: "log/log.log",
|
||||
|
@ -58,7 +58,7 @@ func SortFiles(objs []Obj, orderBy, orderDirection string) {
|
||||
}
|
||||
return objs[i].GetSize() <= objs[j].GetSize()
|
||||
}
|
||||
case "updated_at":
|
||||
case "modified":
|
||||
if orderDirection == "desc" {
|
||||
return objs[i].ModTime().After(objs[j].ModTime())
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package common
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@ -18,7 +19,7 @@ func GenerateToken(username string) (tokenString string, err error) {
|
||||
claim := UserClaims{
|
||||
Username: username,
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(12 * time.Hour)),
|
||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Duration(conf.Conf.TokenExpiresIn) * time.Hour)),
|
||||
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||
NotBefore: jwt.NewNumericDate(time.Now()),
|
||||
}}
|
||||
|
@ -10,15 +10,17 @@ import (
|
||||
)
|
||||
|
||||
func GetApiUrl(r *http.Request) string {
|
||||
api := setting.GetStr(conf.ApiUrl)
|
||||
protocol := "http"
|
||||
if r != nil {
|
||||
api := conf.Conf.SiteURL
|
||||
if api == "" {
|
||||
api = setting.GetStr(conf.ApiUrl)
|
||||
}
|
||||
if r != nil && api == "" {
|
||||
protocol := "http"
|
||||
if r.TLS != nil {
|
||||
protocol = "https"
|
||||
}
|
||||
if api == "" {
|
||||
api = fmt.Sprintf("%s://%s", protocol, r.Host)
|
||||
}
|
||||
api = fmt.Sprintf("%s://%s", protocol, r.Host)
|
||||
|
||||
}
|
||||
strings.TrimSuffix(api, "/")
|
||||
return api
|
||||
|
40
server/static/config.go
Normal file
40
server/static/config.go
Normal file
@ -0,0 +1,40 @@
|
||||
package static
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"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 {
|
||||
u, err := url.Parse(conf.Conf.SiteURL)
|
||||
if err != nil {
|
||||
utils.Log.Fatalf("can't parse site_url: %+v", err)
|
||||
}
|
||||
siteConfig := SiteConfig{
|
||||
ApiURL: conf.Conf.SiteURL,
|
||||
BasePath: u.Path,
|
||||
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/internal/conf"
|
||||
"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/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -22,20 +21,19 @@ func InitIndex() {
|
||||
log.Fatalf("failed to read index.html: %v", err)
|
||||
}
|
||||
conf.RawIndexHtml = string(index)
|
||||
siteConfig := getSiteConfig()
|
||||
replaceMap := map[string]string{
|
||||
"cdn: undefined": fmt.Sprintf("cdn: '%s'", siteConfig.Cdn),
|
||||
"base_path: undefined": fmt.Sprintf("base_path: '%s'", siteConfig.BasePath),
|
||||
"api: undefined": fmt.Sprintf("api: '%s'", siteConfig.ApiURL),
|
||||
}
|
||||
for k, v := range replaceMap {
|
||||
conf.RawIndexHtml = strings.Replace(conf.RawIndexHtml, k, v, 1)
|
||||
}
|
||||
UpdateIndex()
|
||||
}
|
||||
|
||||
func UpdateIndex() {
|
||||
cdn := strings.TrimSuffix(conf.Conf.Cdn, "/")
|
||||
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)
|
||||
title := setting.GetStr(conf.SiteTitle)
|
||||
customizeHead := setting.GetStr(conf.CustomizeHead)
|
||||
@ -45,9 +43,6 @@ func UpdateIndex() {
|
||||
replaceMap1 := map[string]string{
|
||||
"https://jsd.nn.ci/gh/alist-org/logo@main/logo.svg": favicon,
|
||||
"Loading...": title,
|
||||
"cdn: undefined": fmt.Sprintf("cdn: '%s'", cdn),
|
||||
"base_path: undefined": fmt.Sprintf("base_path: '%s'", basePath),
|
||||
"api: undefined": fmt.Sprintf("api: '%s'", apiUrl),
|
||||
"main_color: undefined": fmt.Sprintf("main_color: '%s'", mainColor),
|
||||
}
|
||||
for k, v := range replaceMap1 {
|
||||
|
Reference in New Issue
Block a user