Compare commits
31 Commits
v2.0.0-bet
...
v2.0.0-bet
Author | SHA1 | Date | |
---|---|---|---|
f4affb2c69 | |||
17af21079f | |||
f7d35ec925 | |||
a8730e82b5 | |||
6275e27d1b | |||
e70353704f | |||
be5b1e42d4 | |||
7d08cbc4a9 | |||
1542878d66 | |||
ac8f5d5737 | |||
9ed5b6e581 | |||
db7bff2d61 | |||
7970e737f0 | |||
d4523d52ee | |||
ac8476702c | |||
12f68eaed9 | |||
6a51f02845 | |||
e7071e1093 | |||
11b141b190 | |||
7e099b39cf | |||
b46bf0dfc9 | |||
91f64161b2 | |||
8255ef4346 | |||
254b6c6f79 | |||
1c56d27e20 | |||
4da655cc44 | |||
a746324ecf | |||
1a3b931727 | |||
bfec01e837 | |||
a7ecb7beb8 | |||
c466672626 |
23
.github/workflows/build.yml
vendored
23
.github/workflows/build.yml
vendored
@ -20,6 +20,14 @@ jobs:
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
|
||||
# - name: Setup docker
|
||||
# uses: docker-practice/actions-setup-docker@master
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
@ -33,29 +41,16 @@ jobs:
|
||||
ref: v2
|
||||
path: alist-web
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
|
||||
- name: Set up xgo
|
||||
run: |
|
||||
docker pull techknowlogick/xgo:latest
|
||||
go install src.techknowlogick.com/xgo@latest
|
||||
sudo apt install upx
|
||||
|
||||
- name: Build web
|
||||
run: |
|
||||
cd alist-web
|
||||
yarn
|
||||
yarn build
|
||||
cd ..
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
cd alist
|
||||
mv alist/build.sh .
|
||||
bash build.sh
|
||||
cd ..
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
|
48
.github/workflows/docker.yml
vendored
Normal file
48
.github/workflows/docker.yml
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
name: docker
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'v2'
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
branches:
|
||||
- 'v2'
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
name: Docker
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
images: xhofe/alist
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
- name: Build web
|
||||
run: bash build.sh web
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: xhofe
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386,linux/arm/v6,linux/ppc64le,linux/s390x
|
37
.github/workflows/release.yml
vendored
37
.github/workflows/release.yml
vendored
@ -1,4 +1,4 @@
|
||||
name: build
|
||||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
@ -19,11 +19,21 @@ jobs:
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
|
||||
# - name: Setup docker
|
||||
# uses: docker-practice/actions-setup-docker@master
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
ref: v2
|
||||
path: alist
|
||||
persist-credentials: false
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Checkout web repo
|
||||
uses: actions/checkout@v2
|
||||
@ -31,11 +41,8 @@ jobs:
|
||||
repository: Xhofe/alist-web
|
||||
ref: v2
|
||||
path: alist-web
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16'
|
||||
persist-credentials: false
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up xgo
|
||||
run: |
|
||||
@ -43,18 +50,18 @@ jobs:
|
||||
go install src.techknowlogick.com/xgo@latest
|
||||
sudo apt install upx
|
||||
|
||||
- name: Build web
|
||||
run: |
|
||||
cd alist-web
|
||||
yarn
|
||||
yarn build
|
||||
cd ..
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
cd alist
|
||||
mv alist/build.sh .
|
||||
bash build.sh release
|
||||
cd ..
|
||||
|
||||
- name: Upload asserts files
|
||||
uses: ad-m/github-push-action@master
|
||||
with:
|
||||
github_token: ${{ secrets.MY_TOKEN }}
|
||||
branch: cdn
|
||||
directory: alist-web
|
||||
repository: Xhofe/alist-web
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
|
13
Dockerfile
Normal file
13
Dockerfile
Normal file
@ -0,0 +1,13 @@
|
||||
FROM alpine:edge as builder
|
||||
LABEL stage=go-builder
|
||||
WORKDIR /app/
|
||||
COPY ./ ./
|
||||
RUN apk add --no-cache bash git go gcc musl-dev; \
|
||||
sh build.sh docker
|
||||
|
||||
FROM alpine:edge
|
||||
LABEL MAINTAINER="i@nn.ci"
|
||||
WORKDIR /opt/alist/
|
||||
COPY --from=builder /app/bin/alist ./
|
||||
EXPOSE 5244
|
||||
CMD [ "./alist" ]
|
10
alist.go
10
alist.go
@ -13,14 +13,6 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var (
|
||||
builtAt string
|
||||
goVersion string
|
||||
gitAuthor string
|
||||
gitCommit string
|
||||
gitTag string
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&conf.ConfigFile, "conf", "config.json", "config file")
|
||||
flag.BoolVar(&conf.Debug, "debug", false, "start with debug mode")
|
||||
@ -38,7 +30,7 @@ func Init() {
|
||||
|
||||
func main() {
|
||||
if conf.Version {
|
||||
fmt.Printf("Built At: %s\nGo Version: %s\nAuthor: %s\nCommit ID: %s\nVersion:%s\n", builtAt, goVersion, gitAuthor, gitCommit, gitTag)
|
||||
fmt.Printf("Built At: %s\nGo Version: %s\nAuthor: %s\nCommit ID: %s\nVersion: %s\n", conf.BuiltAt, conf.GoVersion, conf.GitAuthor, conf.GitCommit, conf.GitTag)
|
||||
return
|
||||
}
|
||||
Init()
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/drivers"
|
||||
"github.com/Xhofe/alist/model"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/driver/postgres"
|
||||
@ -106,85 +105,85 @@ func initAccounts() {
|
||||
|
||||
func initSettings() {
|
||||
log.Infof("init settings...")
|
||||
version, err := model.GetSettingByKey("version")
|
||||
if err != nil {
|
||||
log.Debugf("first run")
|
||||
version = &model.SettingItem{
|
||||
version := model.SettingItem{
|
||||
Key: "version",
|
||||
Value: "0.0.0",
|
||||
Type: "string",
|
||||
Value: conf.GitTag,
|
||||
Description: "version",
|
||||
Group: model.CONST,
|
||||
}
|
||||
}
|
||||
settingsMap := map[string][]model.SettingItem{
|
||||
"2.0.0": {
|
||||
|
||||
_ = model.SaveSetting(version)
|
||||
|
||||
settings := []model.SettingItem{
|
||||
{
|
||||
Key: "title",
|
||||
Value: "Alist",
|
||||
Description: "title",
|
||||
Type: "string",
|
||||
Group: model.PUBLIC,
|
||||
},
|
||||
{
|
||||
Key: "password",
|
||||
Value: "alist",
|
||||
Type: "string",
|
||||
Description: "password",
|
||||
Group: model.PRIVATE,
|
||||
},
|
||||
{
|
||||
Key: "version",
|
||||
Value: "2.0.0",
|
||||
Type: "string",
|
||||
Description: "version",
|
||||
Group: model.CONST,
|
||||
},
|
||||
{
|
||||
Key: "logo",
|
||||
Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png",
|
||||
Type: "string",
|
||||
Description: "logo",
|
||||
Group: model.PUBLIC,
|
||||
},
|
||||
{
|
||||
Key: "favicon",
|
||||
Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png",
|
||||
Description: "favicon",
|
||||
Group: model.PUBLIC,
|
||||
},
|
||||
{
|
||||
Key: "icon color",
|
||||
Value: "teal.300",
|
||||
Type: "string",
|
||||
Description: "icon's color",
|
||||
Group: model.PUBLIC,
|
||||
},
|
||||
{
|
||||
Key: "text types",
|
||||
Value: "txt,htm,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,yml,go,sh,c,cpp,h,hpp",
|
||||
Type: "string",
|
||||
Description: "text type extensions",
|
||||
},
|
||||
{
|
||||
Key: "readme file",
|
||||
Value: "hide",
|
||||
Type: "string",
|
||||
Description: "hide readme file? (show/hide)",
|
||||
},
|
||||
{
|
||||
Key: "music cover",
|
||||
Value: "https://store.heytapimage.com/cdo-portal/feedback/202110/30/d43c41c5d257c9bc36366e310374fb19.png",
|
||||
Type: "string",
|
||||
Description: "music cover image",
|
||||
Group: model.PUBLIC,
|
||||
},
|
||||
{
|
||||
Key: "site beian",
|
||||
Type: "string",
|
||||
Description: "chinese beian info",
|
||||
Group: model.PUBLIC,
|
||||
},
|
||||
{
|
||||
Key: "home readme url",
|
||||
Description: "when have multiple, the readme file to show",
|
||||
Group: model.PUBLIC,
|
||||
},
|
||||
{
|
||||
Key: "markdown theme",
|
||||
Value: "vuepress",
|
||||
Description: "default | github | vuepress",
|
||||
Group: model.PUBLIC,
|
||||
},
|
||||
}
|
||||
for k, v := range settingsMap {
|
||||
if utils.VersionCompare(k, version.Value) > 0 {
|
||||
log.Infof("writing [v%s] settings", k)
|
||||
err = model.SaveSettings(v)
|
||||
for _, v := range settings {
|
||||
_, err := model.GetSettingByKey(v.Key)
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
err = model.SaveSetting(v)
|
||||
if err != nil {
|
||||
log.Fatalf("save settings error")
|
||||
log.Fatalf("failed write setting: %s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
79
build.sh
79
build.sh
@ -1,35 +1,79 @@
|
||||
#!/bin/bash
|
||||
if [ "$1" == "web" ]; then
|
||||
git clone https://github.com/Xhofe/alist-web.git
|
||||
cd alist-web || exit
|
||||
yarn
|
||||
yarn build
|
||||
mv dist/* ../public
|
||||
cd ..
|
||||
exit 0
|
||||
fi
|
||||
|
||||
go env -w GOPROXY=https://goproxy.cn,https://mirrors.aliyun.com/goproxy/,https://goproxy.io,direct
|
||||
|
||||
if [ "$1" == "docker" ]; then
|
||||
appName="alist"
|
||||
builtAt="$(date +'%F %T %z')"
|
||||
goVersion=$(go version | sed 's/go version //')
|
||||
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
|
||||
gitCommit=$(git log --pretty=format:"%h" -1)
|
||||
|
||||
if [ "$1" == "release" ]; then
|
||||
gitTag=$(git describe --abbrev=0 --tags)
|
||||
else
|
||||
gitTag="beta"
|
||||
gitTag=$(git describe --long --tags --dirty --always)
|
||||
ldflags="\
|
||||
-w -s \
|
||||
-X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \
|
||||
-X 'github.com/Xhofe/alist/conf.GoVersion=$goVersion' \
|
||||
-X 'github.com/Xhofe/alist/conf.GitAuthor=$gitAuthor' \
|
||||
-X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \
|
||||
-X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \
|
||||
"
|
||||
go build -o ./bin/alist -ldflags="$ldflags" alist.go
|
||||
exit 0
|
||||
fi
|
||||
|
||||
cd alist-web || exit
|
||||
webCommit=$(git log --pretty=format:"%h" -1)
|
||||
echo "web commit id: $webCommit"
|
||||
yarn
|
||||
if [ "$1" == "release" ]; then
|
||||
yarn build --base="https://cdn.jsdelivr.net/gh/Xhofe/alist-web@cdn/v2/$webCommit"
|
||||
mv dist/assets ..
|
||||
else
|
||||
yarn build
|
||||
fi
|
||||
cd ..
|
||||
|
||||
cd alist
|
||||
appName="alist"
|
||||
builtAt="$(date +'%F %T %z')"
|
||||
goVersion=$(go version | sed 's/go version //')
|
||||
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
|
||||
gitCommit=$(git log --pretty=format:"%h" -1)
|
||||
gitTag=$(git describe --long --tags --dirty --always)
|
||||
|
||||
echo "build version: $gitTag"
|
||||
|
||||
ldflags="\
|
||||
-w -s \
|
||||
-X 'main.builtAt=$builtAt' \
|
||||
-X 'main.goVersion=$goVersion' \
|
||||
-X 'main.gitAuthor=$gitAuthor' \
|
||||
-X 'main.gitCommit=$gitCommit' \
|
||||
-X 'main.gitTag=$gitTag' \
|
||||
-X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \
|
||||
-X 'github.com/Xhofe/alist/conf.GoVersion=$goVersion' \
|
||||
-X 'github.com/Xhofe/alist/conf.GitAuthor=$gitAuthor' \
|
||||
-X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \
|
||||
-X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \
|
||||
"
|
||||
|
||||
cp -R ../alist-web/dist/* public
|
||||
|
||||
if [ "$1" == "release" ]; then
|
||||
xgo -out alist -ldflags="$ldflags" .
|
||||
else
|
||||
xgo -targets=linux/amd64,windows/amd64,darwin/amd64 -out alist -ldflags="$ldflags" .
|
||||
fi
|
||||
mkdir "build"
|
||||
mv alist-* build
|
||||
cd build || exit
|
||||
upx -9 ./*
|
||||
find . -type f -print0 | xargs -0 md5sum > md5.txt
|
||||
|
||||
cat md5.txt
|
||||
# compress file (release)
|
||||
if [ "$1" == "release" ]; then
|
||||
mkdir compress
|
||||
@ -47,3 +91,16 @@ if [ "$1" == "release" ]; then
|
||||
zip compress/$(echo $i | sed 's/\.[^.]*$//').zip "$i"
|
||||
done
|
||||
fi
|
||||
cd ../..
|
||||
|
||||
if [ "$1" == "release" ]; then
|
||||
cd alist-web
|
||||
git checkout cdn
|
||||
mkdir "v2/$webCommit"
|
||||
mv ../assets/ v2/$webCommit
|
||||
git add .
|
||||
git config --local user.email "i@nn.ci"
|
||||
git config --local user.name "Xhofe"
|
||||
git commit --allow-empty -m "upload $webCommit assets files" -a
|
||||
cd ..
|
||||
fi
|
@ -7,6 +7,14 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var (
|
||||
BuiltAt string
|
||||
GoVersion string
|
||||
GitAuthor string
|
||||
GitCommit string
|
||||
GitTag string
|
||||
)
|
||||
|
||||
var (
|
||||
ConfigFile string // config file
|
||||
Conf *Config
|
||||
|
@ -221,13 +221,16 @@ func (a AliDrive) Path(path string, account *model.Account) (*model.File, []*mod
|
||||
return a.FormatFile(&file), nil, nil
|
||||
} else {
|
||||
files, _ := cache.([]AliFile)
|
||||
if len(files) != 0 {
|
||||
res := make([]*model.File, 0)
|
||||
for _, file = range files {
|
||||
res = append(res, a.FormatFile(&file))
|
||||
}
|
||||
return nil, res, nil
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
// no cache or len(files) == 0
|
||||
fileId := account.RootFolder
|
||||
if path != "/" {
|
||||
dir, name := filepath.Split(path)
|
||||
@ -270,7 +273,6 @@ func (a AliDrive) Path(path string, account *model.Account) (*model.File, []*mod
|
||||
}
|
||||
return nil, res, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a AliDrive) Link(path string, account *model.Account) (string, error) {
|
||||
file, err := a.GetFile(utils.ParsePath(path), account)
|
||||
@ -316,10 +318,12 @@ func (a AliDrive) RefreshToken(account *model.Account) error {
|
||||
SetError(&e).
|
||||
Post(url)
|
||||
if err != nil {
|
||||
account.Status = err.Error()
|
||||
return err
|
||||
}
|
||||
log.Debugf("%+v,%+v", resp, e)
|
||||
if e.Code != "" {
|
||||
account.Status = e.Message
|
||||
return fmt.Errorf("failed to refresh token: %s", e.Message)
|
||||
}
|
||||
account.RefreshToken, account.AccessToken = resp.RefreshToken, resp.AccessToken
|
||||
@ -354,9 +358,6 @@ func (a AliDrive) Save(account *model.Account, old *model.Account) error {
|
||||
return
|
||||
}
|
||||
err = a.RefreshToken(&newAccount)
|
||||
if err != nil {
|
||||
newAccount.Status = err.Error()
|
||||
}
|
||||
_ = model.SaveAccount(newAccount)
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -115,8 +115,8 @@ func (o Onedrive) Items() []Item {
|
||||
Required: true,
|
||||
},
|
||||
{
|
||||
Name: "site_url",
|
||||
Label: "site url",
|
||||
Name: "site_id",
|
||||
Label: "site id",
|
||||
Type: "string",
|
||||
Required: false,
|
||||
},
|
||||
@ -146,9 +146,11 @@ func (o Onedrive) RefreshToken(account *model.Account) error {
|
||||
"refresh_token": account.RefreshToken,
|
||||
}).Post(url)
|
||||
if err != nil {
|
||||
account.Status = err.Error()
|
||||
return err
|
||||
}
|
||||
if e.Error != "" {
|
||||
account.Status = e.ErrorDescription
|
||||
return fmt.Errorf("%s", e.ErrorDescription)
|
||||
}
|
||||
account.RefreshToken, account.AccessToken = resp.RefreshToken, resp.AccessToken
|
||||
@ -280,9 +282,6 @@ func (o Onedrive) Save(account *model.Account, old *model.Account) error {
|
||||
return
|
||||
}
|
||||
err = o.RefreshToken(&newAccount)
|
||||
if err != nil {
|
||||
newAccount.Status = err.Error()
|
||||
}
|
||||
_ = model.SaveAccount(newAccount)
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -1,13 +1,15 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/robfig/cron/v3"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Account struct {
|
||||
Name string `json:"name" gorm:"primaryKey" validate:"required"`
|
||||
Index int `json:"index" validate:"required"`
|
||||
Index int `json:"index"`
|
||||
Type string `json:"type"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
@ -28,7 +30,7 @@ type Account struct {
|
||||
Zone string `json:"zone"`
|
||||
RedirectUri string `json:"redirect_uri"`
|
||||
SiteUrl string `json:"site_url"`
|
||||
SiteId string
|
||||
SiteId string `json:"site_id"`
|
||||
OnedriveType string `json:"onedrive_type"`
|
||||
}
|
||||
|
||||
@ -44,9 +46,11 @@ func SaveAccount(account Account) error {
|
||||
}
|
||||
|
||||
func DeleteAccount(name string) error {
|
||||
account := Account{
|
||||
Name: name,
|
||||
account, ok := GetAccount(name)
|
||||
if !ok {
|
||||
return fmt.Errorf("no [%s] account", name)
|
||||
}
|
||||
conf.Cron.Remove(cron.EntryID(account.CronId))
|
||||
if err := conf.DB.Delete(&account).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ type SettingItem struct {
|
||||
Key string `json:"key" gorm:"primaryKey" validate:"required"`
|
||||
Value string `json:"value"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type"`
|
||||
//Type string `json:"type"`
|
||||
Group int `json:"group"`
|
||||
}
|
||||
|
||||
@ -22,6 +22,10 @@ func SaveSettings(items []SettingItem) error {
|
||||
return conf.DB.Save(items).Error
|
||||
}
|
||||
|
||||
func SaveSetting(item SettingItem) error {
|
||||
return conf.DB.Save(item).Error
|
||||
}
|
||||
|
||||
func GetSettingsPublic() (*[]SettingItem, error) {
|
||||
var items []SettingItem
|
||||
if err := conf.DB.Where("`group` <> ?", 1).Find(&items).Error; err != nil {
|
||||
@ -40,7 +44,7 @@ func GetSettings() (*[]SettingItem, error) {
|
||||
|
||||
func GetSettingByKey(key string) (*SettingItem, error) {
|
||||
var items SettingItem
|
||||
if err := conf.DB.Where("key = ?", key).First(&items).Error; err != nil {
|
||||
if err := conf.DB.Where("`key` = ?", key).First(&items).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &items, nil
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func Down(ctx *fiber.Ctx) error {
|
||||
rawPath, err:= url.QueryUnescape(ctx.Params("*"))
|
||||
rawPath, err := url.PathUnescape(ctx.Params("*"))
|
||||
if err != nil {
|
||||
return ErrorResp(ctx, err, 500)
|
||||
}
|
||||
@ -34,7 +34,7 @@ func Down(ctx *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
func Proxy(ctx *fiber.Ctx) error {
|
||||
rawPath, err:= url.QueryUnescape(ctx.Params("*"))
|
||||
rawPath, err := url.PathUnescape(ctx.Params("*"))
|
||||
if err != nil {
|
||||
return ErrorResp(ctx, err, 500)
|
||||
}
|
||||
@ -55,6 +55,20 @@ func Proxy(ctx *fiber.Ctx) error {
|
||||
return ctx.SendFile(link)
|
||||
} else {
|
||||
driver.Proxy(ctx)
|
||||
//ctx.Response().ImmediateHeaderFlush = true
|
||||
//var ProxyNetHttp = fasthttpadaptor.NewFastHTTPHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// target, _ := url.Parse(link)
|
||||
// protocol := "https://"
|
||||
// if strings.HasPrefix(link, "http://") {
|
||||
// protocol = "http://"
|
||||
// }
|
||||
// targetHost, _ := url.Parse(fmt.Sprintf("%s%s", protocol, target.Host))
|
||||
// proxy := httputil.NewSingleHostReverseProxy(targetHost)
|
||||
// r.URL = target
|
||||
// r.Host = target.Host
|
||||
// proxy.ServeHTTP(w, r)
|
||||
//})
|
||||
//ProxyNetHttp(ctx.Context())
|
||||
if err := proxy.Do(ctx, link); err != nil {
|
||||
log.Errorf("proxy error: %s", err)
|
||||
return ErrorResp(ctx,err,500)
|
||||
|
@ -22,6 +22,7 @@ func SaveMeta(ctx *fiber.Ctx) error {
|
||||
if err := validate.Struct(req); err != nil {
|
||||
return ErrorResp(ctx, err, 400)
|
||||
}
|
||||
req.Path = utils.ParsePath(req.Path)
|
||||
if err := model.SaveMeta(req); err != nil {
|
||||
return ErrorResp(ctx, err, 500)
|
||||
} else {
|
||||
@ -31,7 +32,7 @@ func SaveMeta(ctx *fiber.Ctx) error {
|
||||
|
||||
func DeleteMeta(ctx *fiber.Ctx) error {
|
||||
path := ctx.Query("path")
|
||||
path = utils.ParsePath(path)
|
||||
//path = utils.ParsePath(path)
|
||||
if err := model.DeleteMeta(path); err != nil {
|
||||
return ErrorResp(ctx, err, 500)
|
||||
}
|
||||
|
Reference in New Issue
Block a user