Comp mysql 5.5. Add show alien config. Fix upload globally. Better the install process.
This commit is contained in:
@ -1,9 +1,5 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
)
|
||||
|
||||
type BaseDao struct {
|
||||
Bean
|
||||
}
|
||||
|
@ -13,11 +13,12 @@ type IBase interface {
|
||||
TableName() string
|
||||
}
|
||||
|
||||
//Mysql 5.5只支持一个CURRENT_TIMESTAMP的默认值,因此时间的默认值都使用蓝眼云盘第一个发布版本时间 2018-01-01 00:00:00
|
||||
type Base struct {
|
||||
Uuid string `json:"uuid" gorm:"type:char(36);primary_key;unique"`
|
||||
Sort int64 `json:"sort" gorm:"type:bigint(20) not null"`
|
||||
UpdateTime time.Time `json:"updateTime" gorm:"type:timestamp not null;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"`
|
||||
CreateTime time.Time `json:"createTime" gorm:"type:timestamp not null;default:CURRENT_TIMESTAMP"`
|
||||
UpdateTime time.Time `json:"updateTime" gorm:"type:timestamp not null;default:CURRENT_TIMESTAMP"`
|
||||
CreateTime time.Time `json:"createTime" gorm:"type:timestamp not null;default:'2018-01-01 00:00:00'"`
|
||||
}
|
||||
|
||||
//将 Struct 转换成map[string]interface{}类型
|
||||
|
@ -65,6 +65,9 @@ func (this *ConfigItem) validate() bool {
|
||||
if this.ServerPort == 0 {
|
||||
LOGGER.Error("ServerPort 未配置")
|
||||
return false
|
||||
} else {
|
||||
//只要配置文件中有配置端口,就使用。
|
||||
CONFIG.ServerPort = this.ServerPort
|
||||
}
|
||||
|
||||
if this.MysqlUsername == "" {
|
||||
@ -134,9 +137,10 @@ func (this *Config) ReadFromConfigFile() {
|
||||
this.Installed = false
|
||||
} else {
|
||||
this.Item = &ConfigItem{}
|
||||
LOGGER.Warn("读取配置文件:%s", filePath)
|
||||
err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(content, this.Item)
|
||||
if err != nil {
|
||||
LOGGER.Error("配置文件格式错误!")
|
||||
LOGGER.Error("配置文件格式错误! 即将进入安装过程!")
|
||||
this.Installed = false
|
||||
return
|
||||
}
|
||||
@ -144,7 +148,7 @@ func (this *Config) ReadFromConfigFile() {
|
||||
//验证项是否齐全
|
||||
itemValidate := this.Item.validate()
|
||||
if !itemValidate {
|
||||
LOGGER.Error("配置文件信息不齐全!")
|
||||
LOGGER.Error("配置文件信息不齐全! 即将进入安装过程!")
|
||||
this.Installed = false
|
||||
return
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package rest
|
||||
|
||||
import (
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
"github.com/nu7hatch/gouuid"
|
||||
"time"
|
||||
)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
|
||||
"github.com/nu7hatch/gouuid"
|
||||
"time"
|
||||
)
|
||||
|
@ -8,7 +8,7 @@ type DownloadToken struct {
|
||||
Base
|
||||
UserUuid string `json:"userUuid" gorm:"type:char(36) not null"`
|
||||
MatterUuid string `json:"matterUuid" gorm:"type:char(36) not null;index:idx_mu"`
|
||||
ExpireTime time.Time `json:"expireTime" gorm:"type:timestamp not null;default:CURRENT_TIMESTAMP"`
|
||||
ExpireTime time.Time `json:"expireTime" gorm:"type:timestamp not null;default:'2018-01-01 00:00:00'"`
|
||||
Ip string `json:"ip" gorm:"type:varchar(128) not null"`
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package rest
|
||||
|
||||
import (
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
|
||||
"github.com/nu7hatch/gouuid"
|
||||
"time"
|
||||
)
|
||||
|
@ -3,11 +3,10 @@ package rest
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
"github.com/nu7hatch/gouuid"
|
||||
"os"
|
||||
"time"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ImageCacheDao struct {
|
||||
@ -114,7 +113,6 @@ func (this *ImageCacheDao) Page(page int, pageSize int, userUuid string, matterU
|
||||
return pager
|
||||
}
|
||||
|
||||
|
||||
//创建
|
||||
func (this *ImageCacheDao) Create(imageCache *ImageCache) *ImageCache {
|
||||
|
||||
@ -150,17 +148,16 @@ func (this *ImageCacheDao) deleteFileAndDir(imageCache *ImageCache) {
|
||||
//删除文件
|
||||
err := os.Remove(filePath)
|
||||
if err != nil {
|
||||
this.logger.Error(fmt.Sprintf("删除磁盘上的文件%s出错,不做任何处理 %s", filePath, err.Error()))
|
||||
this.logger.Error(fmt.Sprintf("删除磁盘上的文件%s出错 %s", filePath, err.Error()))
|
||||
}
|
||||
|
||||
//删除这一层文件夹
|
||||
err = os.Remove(dirPath)
|
||||
if err != nil {
|
||||
this.logger.Error(fmt.Sprintf("删除磁盘上的文件夹%s出错,不做任何处理 %s", dirPath, err.Error()))
|
||||
this.logger.Error(fmt.Sprintf("删除磁盘上的文件夹%s出错 %s", dirPath, err.Error()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//删除一个文件,数据库中删除,物理磁盘上删除。
|
||||
func (this *ImageCacheDao) Delete(imageCache *ImageCache) {
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"fmt"
|
||||
"github.com/disintegration/imaging"
|
||||
"image"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"github.com/disintegration/imaging"
|
||||
"strings"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
//@Service
|
||||
|
@ -444,12 +444,12 @@ func (this *InstallController) Finish(writer http.ResponseWriter, request *http.
|
||||
MysqlPassword: mysqlPassword,
|
||||
}
|
||||
|
||||
//用json的方式输出返回值。
|
||||
jsonStr, _ := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(configItem)
|
||||
//用json的方式输出返回值。为了让格式更好看。
|
||||
jsonStr, _ := jsoniter.ConfigCompatibleWithStandardLibrary.MarshalIndent(configItem, "", " ")
|
||||
|
||||
//写入到配置文件中
|
||||
//写入到配置文件中(不能使用os.O_APPEND 否则会追加)
|
||||
filePath := GetConfPath() + "/tank.json"
|
||||
f, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0777)
|
||||
f, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE, 0777)
|
||||
this.PanicError(err)
|
||||
_, err = f.Write(jsonStr)
|
||||
this.PanicError(err)
|
||||
|
@ -169,6 +169,7 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req
|
||||
userUuid := request.FormValue("userUuid")
|
||||
name := request.FormValue("name")
|
||||
dir := request.FormValue("dir")
|
||||
alien := request.FormValue("alien")
|
||||
orderDir := request.FormValue("orderDir")
|
||||
orderSize := request.FormValue("orderSize")
|
||||
orderName := request.FormValue("orderName")
|
||||
@ -229,7 +230,7 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req
|
||||
},
|
||||
}
|
||||
|
||||
pager := this.matterDao.Page(page, pageSize, puuid, userUuid, name, dir, extensions, sortArray)
|
||||
pager := this.matterDao.Page(page, pageSize, puuid, userUuid, name, dir, alien, extensions, sortArray)
|
||||
|
||||
return this.Success(pager)
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package rest
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
|
||||
"github.com/nu7hatch/gouuid"
|
||||
"os"
|
||||
"strings"
|
||||
@ -146,7 +146,7 @@ func (this *MatterDao) List(puuid string, userUuid string, sortArray []OrderPair
|
||||
}
|
||||
|
||||
//获取某个文件夹下所有的文件和子文件
|
||||
func (this *MatterDao) Page(page int, pageSize int, puuid string, userUuid string, name string, dir string, extensions []string, sortArray []OrderPair) *Pager {
|
||||
func (this *MatterDao) Page(page int, pageSize int, puuid string, userUuid string, name string, dir string, alien string, extensions []string, sortArray []OrderPair) *Pager {
|
||||
|
||||
var wp = &WherePair{}
|
||||
|
||||
@ -168,6 +168,12 @@ func (this *MatterDao) Page(page int, pageSize int, puuid string, userUuid strin
|
||||
wp = wp.And(&WherePair{Query: "dir = ?", Args: []interface{}{0}})
|
||||
}
|
||||
|
||||
if alien == "true" {
|
||||
wp = wp.And(&WherePair{Query: "alien = ?", Args: []interface{}{1}})
|
||||
} else if alien == "false" {
|
||||
wp = wp.And(&WherePair{Query: "alien = ?", Args: []interface{}{0}})
|
||||
}
|
||||
|
||||
var conditionDB *gorm.DB
|
||||
if extensions != nil && len(extensions) > 0 {
|
||||
var orWp = &WherePair{}
|
||||
@ -282,4 +288,4 @@ func (this *MatterDao) SizeBetweenTime(startTime time.Time, endTime time.Time) i
|
||||
row := db.Row()
|
||||
row.Scan(&size)
|
||||
return size
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ func (this *PreferenceController) Edit(writer http.ResponseWriter, request *http
|
||||
faviconUrl := request.FormValue("faviconUrl")
|
||||
footerLine1 := request.FormValue("footerLine1")
|
||||
footerLine2 := request.FormValue("footerLine2")
|
||||
showAlienStr := request.FormValue("showAlien")
|
||||
|
||||
preference := this.preferenceDao.Fetch()
|
||||
preference.Name = name
|
||||
@ -67,6 +68,11 @@ func (this *PreferenceController) Edit(writer http.ResponseWriter, request *http
|
||||
preference.FaviconUrl = faviconUrl
|
||||
preference.FooterLine1 = footerLine1
|
||||
preference.FooterLine2 = footerLine2
|
||||
if showAlienStr == "true" {
|
||||
preference.ShowAlien = true
|
||||
} else if showAlienStr == "false" {
|
||||
preference.ShowAlien = false
|
||||
}
|
||||
|
||||
preference = this.preferenceDao.Save(preference)
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
"github.com/nu7hatch/gouuid"
|
||||
"time"
|
||||
)
|
||||
@ -20,7 +19,7 @@ func (this *PreferenceDao) Fetch() *Preference {
|
||||
|
||||
if db.Error.Error() == "record not found" {
|
||||
preference.Name = "蓝眼云盘"
|
||||
preference.Version = VERSION
|
||||
preference.ShowAlien = true
|
||||
this.Create(preference)
|
||||
return preference
|
||||
} else {
|
||||
|
@ -7,7 +7,7 @@ type Preference struct {
|
||||
FaviconUrl string `json:"faviconUrl" gorm:"type:varchar(255)"`
|
||||
FooterLine1 string `json:"footerLine1" gorm:"type:varchar(1024)"`
|
||||
FooterLine2 string `json:"footerLine2" gorm:"type:varchar(1024)"`
|
||||
Version string `json:"version" gorm:"type:varchar(45)"`
|
||||
ShowAlien bool `json:"showAlien" gorm:"type:tinyint(1) not null;default:1"`
|
||||
}
|
||||
|
||||
// set File's table name to be `profiles`
|
||||
|
@ -1,7 +1,7 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
|
||||
"github.com/nu7hatch/gouuid"
|
||||
"time"
|
||||
)
|
||||
|
@ -8,7 +8,7 @@ type Session struct {
|
||||
Base
|
||||
UserUuid string `json:"userUuid" gorm:"type:char(36)"`
|
||||
Ip string `json:"ip" gorm:"type:varchar(128) not null"`
|
||||
ExpireTime time.Time `json:"expireTime" gorm:"type:timestamp not null;default:CURRENT_TIMESTAMP"`
|
||||
ExpireTime time.Time `json:"expireTime" gorm:"type:timestamp not null;default:'2018-01-01 00:00:00'"`
|
||||
}
|
||||
|
||||
// set User's table name to be `profiles`
|
||||
|
@ -1,7 +1,7 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
|
||||
"github.com/nu7hatch/gouuid"
|
||||
"time"
|
||||
)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
|
||||
"github.com/nu7hatch/gouuid"
|
||||
"time"
|
||||
)
|
||||
|
@ -37,7 +37,7 @@ type User struct {
|
||||
City string `json:"city" gorm:"type:varchar(45)"`
|
||||
AvatarUrl string `json:"avatarUrl" gorm:"type:varchar(255)"`
|
||||
LastIp string `json:"lastIp" gorm:"type:varchar(128)"`
|
||||
LastTime time.Time `json:"lastTime" gorm:"type:timestamp not null;default:CURRENT_TIMESTAMP"`
|
||||
LastTime time.Time `json:"lastTime" gorm:"type:timestamp not null;default:'2018-01-01 00:00:00'"`
|
||||
SizeLimit int64 `json:"sizeLimit" gorm:"type:bigint(20) not null;default:-1"`
|
||||
Status string `json:"status" gorm:"type:varchar(45)"`
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"fmt"
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
//给密码字符串加密
|
||||
|
Reference in New Issue
Block a user