下面是我处理下的代码,但是还是启动不起来。
[C] 纯文本查看 复制代码 package bootstrap
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"fmt"
"github.com/cloudreve/Cloudreve/v3/bootstrap/constant"
"github.com/cloudreve/Cloudreve/v3/pkg/conf"
"github.com/cloudreve/Cloudreve/v3/pkg/vol"
"github.com/gin-gonic/gin"
"io/ioutil"
"log"
"strconv"
)
var matrix []byte
var APPID string
// InitApplication 初始化应用常量
func InitApplication() {
fmt.Print(`
Cloudreve Application Information
Version: ` + conf.BackendVersion + ` Commit: #` + conf.LastCommit + ` Pro: ` + conf.IsPro + `
================================================
`)
pic, err := ioutil.ReadFile("bg.png")
if err != nil {
log.Fatalf("Failed to read bg.png: %v", err)
}
// Your data
table := map[string]interface{}{
"id": "2018110303550773058",
"pic": pic,
"secret": "C3E8E7FDB44F866A29309FAF91242343",
"version": "3.3.1",
"date": "1111111111111111111",
"domains": "dd.cc",
"table": make([]int, 15),
}
// 使用解密和解码后的数据初始化全局变量
constant.HashIDTable = table["table"].([]int)
APPID = table["id"].(string)
matrix = table["pic"].([]byte)
vol.ClientSecret = table["secret"].(string)
}
// InitCustomRoute 初始化自定义路由
func InitCustomRoute(group *gin.RouterGroup) {
// 定义一个返回 PNG 图片的路由
group.GET("bg", func(c *gin.Context) {
c.Header("content-type", "image/png")
c.Writer.Write(matrix)
})
// 定义一个返回 APPID 的路由
group.GET("id", func(c *gin.Context) {
c.String(200, APPID)
})
}
func seed() []byte {
res := []int{8}
s := "20210323"
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)]
}
func encode(orig []byte, key []byte) []byte {
block, _ := aes.NewCipher(key[:32])
blockSize := block.BlockSize()
orig = pKCS7Padding(orig, blockSize)
blockMode := cipher.NewCBCEncrypter(block, key[:blockSize])
crypted := make([]byte, len(orig))
blockMode.CryptBlocks(crypted, orig)
return crypted
}
func pKCS7Padding(origData []byte, blockSize int) []byte {
padding := blockSize - len(origData)%blockSize
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
return append(origData, padtext...)
}
|