From 4ba24e0cf1428d1e0a18edd88d7de2ff48119e9d Mon Sep 17 00:00:00 2001
From: HFO4 <912394456@qq.com>
Date: Wed, 11 Mar 2020 15:22:21 +0800
Subject: [PATCH] Modify: clean modals
---
assets | 2 +-
bootstrap/app.go | 74 -------------------
bootstrap/constant/constant.go | 3 -
middleware/option_test.go | 2 -
models/folder.go | 13 ----
models/group.go | 1 -
models/group_test.go | 4 +-
models/migration.go | 24 +------
models/order.go | 59 ----------------
models/redeem.go | 27 -------
models/share.go | 32 +--------
models/storage_pack.go | 91 ------------------------
models/storage_pack_test.go | 86 -----------------------
models/user.go | 125 ++++-----------------------------
pkg/conf/version.go | 2 +-
pkg/hashid/hash.go | 3 +-
pkg/hashid/hash_test.go | 2 -
pkg/payment/purchase.go | 1 -
pkg/payment/score.go | 11 ---
pkg/serializer/setting.go | 4 --
pkg/serializer/share.go | 4 --
pkg/serializer/user.go | 3 -
pkg/serializer/vas.go | 19 -----
pkg/webdav/webdav.go | 11 ---
routers/controllers/site.go | 2 -
routers/router.go | 1 -
service/admin/user.go | 1 -
service/setting/webdav.go | 4 --
service/share/manage.go | 2 -
service/share/visit.go | 7 --
30 files changed, 22 insertions(+), 598 deletions(-)
delete mode 100644 bootstrap/constant/constant.go
delete mode 100644 models/order.go
delete mode 100644 models/redeem.go
delete mode 100644 models/storage_pack.go
delete mode 100644 models/storage_pack_test.go
diff --git a/assets b/assets
index d460742..186f0aa 160000
--- a/assets
+++ b/assets
@@ -1 +1 @@
-Subproject commit d46074216363ac62a66a02284f2a791b79a392cd
+Subproject commit 186f0aac0964c95ed4826894ddf888e32e00d46b
diff --git a/bootstrap/app.go b/bootstrap/app.go
index 9e1f3e5..85545ed 100644
--- a/bootstrap/app.go
+++ b/bootstrap/app.go
@@ -1,23 +1,10 @@
package bootstrap
import (
- "bytes"
- "crypto/aes"
- "crypto/cipher"
- "encoding/gob"
"fmt"
- "github.com/HFO4/cloudreve/bootstrap/constant"
"github.com/HFO4/cloudreve/pkg/conf"
- "github.com/HFO4/cloudreve/pkg/util"
- "github.com/gin-gonic/gin"
- "io/ioutil"
- "os"
- "strconv"
)
-var matrix []byte
-var APPID string
-
// InitApplication 初始化应用常量
func InitApplication() {
fmt.Print(`
@@ -31,65 +18,4 @@ V` + conf.BackendVersion + ` Commit #` + conf.LastCommit + ` Pro=` + conf.IsPr
================================================
`)
- data, err := ioutil.ReadFile(util.RelativePath(string([]byte{107, 101, 121, 46, 98, 105, 110})))
- if err != nil {
- util.Log().Panic("%s", err)
- }
-
- table := deSign(data)
- constant.HashIDTable = table["table"].([]int)
- APPID = table["id"].(string)
- matrix = table["pic"].([]byte)
-}
-
-// InitCustomRoute 初始化自定义路由
-func InitCustomRoute(group *gin.RouterGroup) {
- group.GET(string([]byte{98, 103}), func(c *gin.Context) {
- c.Header("content-type", "image/png")
- c.Writer.Write(matrix)
- })
- group.GET("id", func(c *gin.Context) {
- c.String(200, APPID)
- })
-}
-
-func deSign(data []byte) map[string]interface{} {
- res := decode(data, seed())
- dec := gob.NewDecoder(bytes.NewReader(res))
- obj := map[string]interface{}{}
- err := dec.Decode(&obj)
- if err != nil {
- fmt.Println(err)
- os.Exit(-1)
- }
- return obj
-}
-
-func seed() []byte {
- res := []int{10}
- s := "2020"
- m := 1 << 20
- a := 9
- b := 7
- for i := 1; i < 23; i++ {
- res = append(res, (a*res[i-1]+b)%m)
- s += strconv.Itoa(res[i])
- }
- return []byte(s)
-}
-
-func decode(cryted []byte, key []byte) []byte {
- block, _ := aes.NewCipher(key[:32])
- blockSize := block.BlockSize()
- blockMode := cipher.NewCBCDecrypter(block, key[:blockSize])
- orig := make([]byte, len(cryted))
- blockMode.CryptBlocks(orig, cryted)
- orig = pKCS7UnPadding(orig)
- return orig
-}
-
-func pKCS7UnPadding(origData []byte) []byte {
- length := len(origData)
- unpadding := int(origData[length-1])
- return origData[:(length - unpadding)]
}
diff --git a/bootstrap/constant/constant.go b/bootstrap/constant/constant.go
deleted file mode 100644
index f904641..0000000
--- a/bootstrap/constant/constant.go
+++ /dev/null
@@ -1,3 +0,0 @@
-package constant
-
-var HashIDTable = []int{}
diff --git a/middleware/option_test.go b/middleware/option_test.go
index 7048e9b..a0af92d 100644
--- a/middleware/option_test.go
+++ b/middleware/option_test.go
@@ -1,7 +1,6 @@
package middleware
import (
- "github.com/HFO4/cloudreve/bootstrap/constant"
"github.com/HFO4/cloudreve/pkg/cache"
"github.com/HFO4/cloudreve/pkg/hashid"
"github.com/gin-gonic/gin"
@@ -15,7 +14,6 @@ func TestHashID(t *testing.T) {
asserts := assert.New(t)
rec := httptest.NewRecorder()
TestFunc := HashID(hashid.FolderID)
- constant.HashIDTable = []int{0, 1, 2, 3, 4, 5, 6}
// 未给定ID对象,跳过
{
diff --git a/models/folder.go b/models/folder.go
index 06f1364..1366f71 100644
--- a/models/folder.go
+++ b/models/folder.go
@@ -15,7 +15,6 @@ type Folder struct {
Name string `gorm:"unique_index:idx_only_one_name"`
ParentID *uint `gorm:"index:parent_id;unique_index:idx_only_one_name"`
OwnerID uint `gorm:"index:owner_id"`
- PolicyID uint // Webdav下挂载的存储策略ID
// 数据库忽略字段
Position string `gorm:"-"`
@@ -30,13 +29,6 @@ func (folder *Folder) Create() (uint, error) {
return folder.ID, nil
}
-// GetMountedFolders 列出已挂载存储策略的目录
-func GetMountedFolders(uid uint) []Folder {
- var folders []Folder
- DB.Where("owner_id = ? and policy_id <> ?", uid, 0).Find(&folders)
- return folders
-}
-
// GetChild 返回folder下名为name的子目录,不存在则返回错误
func (folder *Folder) GetChild(name string) (*Folder, error) {
var resFolder Folder
@@ -272,11 +264,6 @@ func (folder *Folder) Rename(new string) error {
return nil
}
-// Mount 目录挂载
-func (folder *Folder) Mount(new uint) error {
- return DB.Model(&folder).Update("policy_id", new).Error
-}
-
/*
实现 FileInfo.FileInfo 接口
TODO 测试
diff --git a/models/group.go b/models/group.go
index d2e6490..189634c 100644
--- a/models/group.go
+++ b/models/group.go
@@ -29,7 +29,6 @@ type GroupOption struct {
DecompressSize uint64 `json:"decompress_size,omitempty"`
OneTimeDownload bool `json:"one_time_download,omitempty"`
ShareDownload bool `json:"share_download,omitempty"`
- ShareFree bool `json:"share_free,omitempty"`
Aria2 bool `json:"aria2,omitempty"` // 离线下载
Aria2Options map[string]interface{} `json:"aria2_options,omitempty"` // 离线下载用户组配置
}
diff --git a/models/group_test.go b/models/group_test.go
index 2f487ce..caa297c 100644
--- a/models/group_test.go
+++ b/models/group_test.go
@@ -23,7 +23,7 @@ func TestGetGroupByID(t *testing.T) {
ID: 1,
},
Name: "管理员",
- Policies: "[1]",
+ PolicyID: 1,
PolicyList: []uint{1},
}, group)
@@ -42,7 +42,7 @@ func TestGroup_AfterFind(t *testing.T) {
ID: 1,
},
Name: "管理员",
- Policies: "[1]",
+ PolicyID: 1,
}
err := testCase.AfterFind()
asserts.NoError(err)
diff --git a/models/migration.go b/models/migration.go
index 6a0eae1..023d666 100644
--- a/models/migration.go
+++ b/models/migration.go
@@ -35,8 +35,8 @@ func migration() {
if conf.DatabaseConfig.Type == "mysql" {
DB = DB.Set("gorm:table_options", "ENGINE=InnoDB")
}
- DB.AutoMigrate(&User{}, &Setting{}, &Group{}, &Policy{}, &Folder{}, &File{}, &StoragePack{}, &Share{},
- &Task{}, &Download{}, &Tag{}, &Webdav{}, &Order{}, &Redeem{})
+ DB.AutoMigrate(&User{}, &Setting{}, &Group{}, &Policy{}, &Folder{}, &File{}, &Share{},
+ &Task{}, &Download{}, &Tag{}, &Webdav{})
// 创建初始存储策略
addDefaultPolicy()
@@ -90,9 +90,6 @@ func addDefaultSettings() {
{Name: "replyTo", Value: `abslant@126.com`, Type: "mail"},
{Name: "smtpUser", Value: `no-reply@acg.blue`, Type: "mail"},
{Name: "smtpPass", Value: ``, Type: "mail"},
- {Name: "over_used_template", Value: `
容量超额提醒 | 容量超额警告 | 亲爱的{userName}: | 由于{notifyReason},您在{siteTitle}的账户的容量使用超出配额,您将无法继续上传新文件,请尽快清理文件,否则我们将会禁用您的账户。 | 登录{siteTitle} | 感谢您选择{siteTitle}。 |
|
| |
`, Type: "mail_template"},
- {Name: "ban_time", Value: `604800`, Type: "storage_policy"},
{Name: "maxEditSize", Value: `4194304`, Type: "file_edit"},
{Name: "archive_timeout", Value: `60`, Type: "timeout"},
{Name: "download_timeout", Value: `60`, Type: "timeout"},
@@ -108,10 +105,6 @@ solid #e9e9e9;"bgcolor="#fff"> |
重设{siteTitle}密码 |
亲爱的{userName}: | 请点击下方按钮完成密码重设。如果非你本人操作,请忽略此邮件。 | 重设密码 | 感谢您选择{siteTitle}。 |
|
|