Simple the result2 to result.

This commit is contained in:
zicla 2019-04-26 03:19:47 +08:00
parent d030a60721
commit c55e8699b4
20 changed files with 204 additions and 204 deletions

View File

@ -5,7 +5,7 @@ import (
"net/http" "net/http"
"regexp" "regexp"
"strconv" "strconv"
result2 "tank/code/tool/result" "tank/code/tool/result"
"tank/code/tool/util" "tank/code/tool/util"
"time" "time"
@ -139,7 +139,7 @@ func (this *AlienController) CheckRequestUser(writer http.ResponseWriter, reques
} }
//系统中的用户x要获取一个UploadToken用于提供给x信任的用户上传文件。 //系统中的用户x要获取一个UploadToken用于提供给x信任的用户上传文件。
func (this *AlienController) FetchUploadToken(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *AlienController) FetchUploadToken(writer http.ResponseWriter, request *http.Request) *result.WebResult {
//文件名。 //文件名。
filename := request.FormValue("filename") filename := request.FormValue("filename")
@ -221,7 +221,7 @@ func (this *AlienController) FetchUploadToken(writer http.ResponseWriter, reques
} }
//系统中的用户x 拿着某个文件的uuid来确认是否其信任的用户已经上传好了。 //系统中的用户x 拿着某个文件的uuid来确认是否其信任的用户已经上传好了。
func (this *AlienController) Confirm(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *AlienController) Confirm(writer http.ResponseWriter, request *http.Request) *result.WebResult {
matterUuid := request.FormValue("matterUuid") matterUuid := request.FormValue("matterUuid")
if matterUuid == "" { if matterUuid == "" {
@ -239,7 +239,7 @@ func (this *AlienController) Confirm(writer http.ResponseWriter, request *http.R
} }
//系统中的用户x 信任的用户上传文件。这个接口需要支持跨域。 //系统中的用户x 信任的用户上传文件。这个接口需要支持跨域。
func (this *AlienController) Upload(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *AlienController) Upload(writer http.ResponseWriter, request *http.Request) *result.WebResult {
//允许跨域请求。 //允许跨域请求。
this.allowCORS(writer) this.allowCORS(writer)
if request.Method == "OPTIONS" { if request.Method == "OPTIONS" {
@ -292,7 +292,7 @@ func (this *AlienController) Upload(writer http.ResponseWriter, request *http.Re
} }
//给一个指定的url从该url中去拉取文件回来。此处采用uploadToken的模式。 //给一个指定的url从该url中去拉取文件回来。此处采用uploadToken的模式。
func (this *AlienController) CrawlToken(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *AlienController) CrawlToken(writer http.ResponseWriter, request *http.Request) *result.WebResult {
//允许跨域请求。 //允许跨域请求。
this.allowCORS(writer) this.allowCORS(writer)
if request.Method == "OPTIONS" { if request.Method == "OPTIONS" {
@ -329,7 +329,7 @@ func (this *AlienController) CrawlToken(writer http.ResponseWriter, request *htt
} }
//通过一个url直接上传无需借助uploadToken. //通过一个url直接上传无需借助uploadToken.
func (this *AlienController) CrawlDirect(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *AlienController) CrawlDirect(writer http.ResponseWriter, request *http.Request) *result.WebResult {
//文件名。 //文件名。
filename := request.FormValue("filename") filename := request.FormValue("filename")
@ -367,7 +367,7 @@ func (this *AlienController) CrawlDirect(writer http.ResponseWriter, request *ht
} }
//系统中的用户x要获取一个DownloadToken用于提供给x信任的用户下载文件。 //系统中的用户x要获取一个DownloadToken用于提供给x信任的用户下载文件。
func (this *AlienController) FetchDownloadToken(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *AlienController) FetchDownloadToken(writer http.ResponseWriter, request *http.Request) *result.WebResult {
matterUuid := request.FormValue("matterUuid") matterUuid := request.FormValue("matterUuid")
if matterUuid == "" { if matterUuid == "" {

View File

@ -3,7 +3,7 @@ package code
import ( import (
"fmt" "fmt"
"net/http" "net/http"
result2 "tank/code/tool/result" "tank/code/tool/result"
"tank/code/tool/util" "tank/code/tool/util"
"time" "time"
) )
@ -98,7 +98,7 @@ func (this *AlienService) PreviewOrDownload(
tokenUser := this.userDao.CheckByUuid(downloadToken.UserUuid) tokenUser := this.userDao.CheckByUuid(downloadToken.UserUuid)
if matter.UserUuid != tokenUser.Uuid { if matter.UserUuid != tokenUser.Uuid {
panic(result2.CODE_WRAPPER_UNAUTHORIZED) panic(result.CODE_WRAPPER_UNAUTHORIZED)
} }
//下载之后立即过期掉。如果是分块下载的,必须以最终获取到完整的数据为准。 //下载之后立即过期掉。如果是分块下载的,必须以最终获取到完整的数据为准。
@ -110,7 +110,7 @@ func (this *AlienService) PreviewOrDownload(
//判断文件的所属人是否正确 //判断文件的所属人是否正确
operator := this.findUser(writer, request) operator := this.findUser(writer, request)
if operator == nil || (operator.Role != USER_ROLE_ADMINISTRATOR && matter.UserUuid != operator.Uuid) { if operator == nil || (operator.Role != USER_ROLE_ADMINISTRATOR && matter.UserUuid != operator.Uuid) {
panic(result2.CODE_WRAPPER_UNAUTHORIZED) panic(result.CODE_WRAPPER_UNAUTHORIZED)
} }
} }

View File

@ -5,7 +5,7 @@ import (
"github.com/json-iterator/go" "github.com/json-iterator/go"
"go/types" "go/types"
"net/http" "net/http"
result2 "tank/code/tool/result" "tank/code/tool/result"
) )
type IController interface { type IController interface {
@ -50,13 +50,13 @@ func (this *BaseController) HandleRoutes(writer http.ResponseWriter, request *ht
} }
//需要进行登录验证的wrap包装 //需要进行登录验证的wrap包装
func (this *BaseController) Wrap(f func(writer http.ResponseWriter, request *http.Request) *result2.WebResult, qualifiedRole string) func(w http.ResponseWriter, r *http.Request) { func (this *BaseController) Wrap(f func(writer http.ResponseWriter, request *http.Request) *result.WebResult, qualifiedRole string) func(w http.ResponseWriter, r *http.Request) {
return func(writer http.ResponseWriter, request *http.Request) { return func(writer http.ResponseWriter, request *http.Request) {
//writer和request赋值给自己。 //writer和request赋值给自己。
var webResult *result2.WebResult = nil var webResult *result.WebResult = nil
//只有游客接口不需要登录 //只有游客接口不需要登录
if qualifiedRole != USER_ROLE_GUEST { if qualifiedRole != USER_ROLE_GUEST {
@ -64,10 +64,10 @@ func (this *BaseController) Wrap(f func(writer http.ResponseWriter, request *htt
if user.Status == USER_STATUS_DISABLED { if user.Status == USER_STATUS_DISABLED {
//判断用户是否被禁用。 //判断用户是否被禁用。
webResult = result2.ConstWebResult(result2.CODE_WRAPPER_USER_DISABLED) webResult = result.ConstWebResult(result.CODE_WRAPPER_USER_DISABLED)
} else { } else {
if qualifiedRole == USER_ROLE_ADMINISTRATOR && user.Role != USER_ROLE_ADMINISTRATOR { if qualifiedRole == USER_ROLE_ADMINISTRATOR && user.Role != USER_ROLE_ADMINISTRATOR {
webResult = result2.ConstWebResult(result2.CODE_WRAPPER_UNAUTHORIZED) webResult = result.ConstWebResult(result.CODE_WRAPPER_UNAUTHORIZED)
} else { } else {
webResult = f(writer, request) webResult = f(writer, request)
} }
@ -87,7 +87,7 @@ func (this *BaseController) Wrap(f func(writer http.ResponseWriter, request *htt
this.PanicError(err) this.PanicError(err)
writer.WriteHeader(result2.FetchHttpStatus(webResult.Code)) writer.WriteHeader(result.FetchHttpStatus(webResult.Code))
_, err = fmt.Fprintf(writer, string(b)) _, err = fmt.Fprintf(writer, string(b))
this.PanicError(err) this.PanicError(err)
@ -100,20 +100,20 @@ func (this *BaseController) Wrap(f func(writer http.ResponseWriter, request *htt
} }
//返回成功的结果。支持放置三种类型 1.字符串 2. WebResult对象 3.空指针 4.任意类型 //返回成功的结果。支持放置三种类型 1.字符串 2. WebResult对象 3.空指针 4.任意类型
func (this *BaseController) Success(data interface{}) *result2.WebResult { func (this *BaseController) Success(data interface{}) *result.WebResult {
var webResult *result2.WebResult = nil var webResult *result.WebResult = nil
if value, ok := data.(string); ok { if value, ok := data.(string); ok {
//返回一句普通的消息 //返回一句普通的消息
webResult = &result2.WebResult{Code: result2.CODE_WRAPPER_OK.Code, Msg: value} webResult = &result.WebResult{Code: result.CODE_WRAPPER_OK.Code, Msg: value}
} else if value, ok := data.(*result2.WebResult); ok { } else if value, ok := data.(*result.WebResult); ok {
//返回一个webResult对象 //返回一个webResult对象
webResult = value webResult = value
} else if _, ok := data.(types.Nil); ok { } else if _, ok := data.(types.Nil); ok {
//返回一个空指针 //返回一个空指针
webResult = result2.ConstWebResult(result2.CODE_WRAPPER_OK) webResult = result.ConstWebResult(result.CODE_WRAPPER_OK)
} else { } else {
//返回的类型不明确。 //返回的类型不明确。
webResult = &result2.WebResult{Code: result2.CODE_WRAPPER_OK.Code, Data: data} webResult = &result.WebResult{Code: result.CODE_WRAPPER_OK.Code, Data: data}
} }
return webResult return webResult
} }

View File

@ -4,7 +4,7 @@ import (
"net/http" "net/http"
"tank/code/config" "tank/code/config"
"tank/code/logger" "tank/code/logger"
result2 "tank/code/tool/result" "tank/code/tool/result"
"tank/code/tool/util" "tank/code/tool/util"
) )
@ -78,7 +78,7 @@ func (this *Bean) findUser(writer http.ResponseWriter, request *http.Request) *U
//获取当前登录的用户,找不到就返回登录错误 //获取当前登录的用户,找不到就返回登录错误
func (this *Bean) checkUser(writer http.ResponseWriter, request *http.Request) *User { func (this *Bean) checkUser(writer http.ResponseWriter, request *http.Request) *User {
if this.findUser(writer, request) == nil { if this.findUser(writer, request) == nil {
panic(result2.ConstWebResult(result2.CODE_WRAPPER_LOGIN)) panic(result.ConstWebResult(result.CODE_WRAPPER_LOGIN))
} else { } else {
return this.findUser(writer, request) return this.findUser(writer, request)
} }

View File

@ -3,7 +3,7 @@ package code
import ( import (
"net/http" "net/http"
"strconv" "strconv"
result2 "tank/code/tool/result" "tank/code/tool/result"
) )
type DashboardController struct { type DashboardController struct {
@ -42,14 +42,14 @@ func (this *DashboardController) RegisterRoutes() map[string]func(writer http.Re
} }
//过去七天分时调用量 //过去七天分时调用量
func (this *DashboardController) InvokeList(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *DashboardController) InvokeList(writer http.ResponseWriter, request *http.Request) *result.WebResult {
return this.Success("") return this.Success("")
} }
//按照分页的方式获取某个图片缓存夹下图片缓存和子图片缓存夹的列表,通常情况下只有一页。 //按照分页的方式获取某个图片缓存夹下图片缓存和子图片缓存夹的列表,通常情况下只有一页。
func (this *DashboardController) Page(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *DashboardController) Page(writer http.ResponseWriter, request *http.Request) *result.WebResult {
//如果是根目录那么就传入root. //如果是根目录那么就传入root.
pageStr := request.FormValue("page") pageStr := request.FormValue("page")
@ -97,7 +97,7 @@ func (this *DashboardController) Page(writer http.ResponseWriter, request *http.
} }
func (this *DashboardController) ActiveIpTop10(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *DashboardController) ActiveIpTop10(writer http.ResponseWriter, request *http.Request) *result.WebResult {
list := this.dashboardDao.ActiveIpTop10() list := this.dashboardDao.ActiveIpTop10()
return this.Success(list) return this.Success(list)
} }

View File

@ -7,7 +7,7 @@ import (
"net/http" "net/http"
"regexp" "regexp"
"strings" "strings"
result2 "tank/code/tool/result" "tank/code/tool/result"
"tank/code/tool/util" "tank/code/tool/util"
) )
@ -79,16 +79,16 @@ func (this *DavController) CheckCurrentUser(writer http.ResponseWriter, request
//要求前端使用Basic的形式授权 //要求前端使用Basic的形式授权
writer.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`) writer.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
panic(result2.ConstWebResult(result2.CODE_WRAPPER_LOGIN)) panic(result.ConstWebResult(result.CODE_WRAPPER_LOGIN))
} }
user := this.userDao.FindByUsername(username) user := this.userDao.FindByUsername(username)
if user == nil { if user == nil {
panic(result2.BadRequest("邮箱或密码错误")) panic(result.BadRequest("邮箱或密码错误"))
} else { } else {
if !util.MatchBcrypt(password, user.Password) { if !util.MatchBcrypt(password, user.Password) {
panic(result2.BadRequest("邮箱或密码错误")) panic(result.BadRequest("邮箱或密码错误"))
} }
} }

View File

@ -9,7 +9,7 @@ import (
"strings" "strings"
dav2 "tank/code/tool/dav" dav2 "tank/code/tool/dav"
xml2 "tank/code/tool/dav/xml" xml2 "tank/code/tool/dav/xml"
result2 "tank/code/tool/result" "tank/code/tool/result"
"tank/code/tool/util" "tank/code/tool/util"
) )
@ -58,7 +58,7 @@ func (this *DavService) ParseDepth(request *http.Request) int {
return 1 return 1
} }
} else { } else {
panic(result2.BadRequest("必须指定Header Depth")) panic(result.BadRequest("必须指定Header Depth"))
} }
return depth return depth
} }
@ -107,7 +107,7 @@ func (this *DavService) PropstatsFromXmlNames(user *User, matter *Matter, xmlNam
} }
if len(properties) == 0 { if len(properties) == 0 {
panic(result2.BadRequest("请求的属性项无法解析!")) panic(result.BadRequest("请求的属性项无法解析!"))
} }
okPropstat := dav2.Propstat{Status: http.StatusOK, Props: properties} okPropstat := dav2.Propstat{Status: http.StatusOK, Props: properties}
@ -136,7 +136,7 @@ func (this *DavService) Propstats(user *User, matter *Matter, propfind *dav2.Pro
propstats := make([]dav2.Propstat, 0) propstats := make([]dav2.Propstat, 0)
if propfind.Propname != nil { if propfind.Propname != nil {
panic(result2.BadRequest("propfind.Propname != nil 尚未处理")) panic(result.BadRequest("propfind.Propname != nil 尚未处理"))
} else if propfind.Allprop != nil { } else if propfind.Allprop != nil {
//TODO: 如果include中还有内容那么包含进去。 //TODO: 如果include中还有内容那么包含进去。
@ -313,7 +313,7 @@ func (this *DavService) prepareMoveCopy(
var destinationPath string var destinationPath string
if destinationStr == "" { if destinationStr == "" {
panic(result2.BadRequest("Header Destination必填")) panic(result.BadRequest("Header Destination必填"))
} }
//如果是重命名那么就不是http开头了。 //如果是重命名那么就不是http开头了。
@ -323,7 +323,7 @@ func (this *DavService) prepareMoveCopy(
destinationUrl, err := url.Parse(destinationStr) destinationUrl, err := url.Parse(destinationStr)
this.PanicError(err) this.PanicError(err)
if destinationUrl.Host != request.Host { if destinationUrl.Host != request.Host {
panic(result2.BadRequest("Destination Host不一致. %s %s != %s", destinationStr, destinationUrl.Host, request.Host)) panic(result.BadRequest("Destination Host不一致. %s %s != %s", destinationStr, destinationUrl.Host, request.Host))
} }
fullDestinationPath = destinationUrl.Path fullDestinationPath = destinationUrl.Path
} }
@ -338,7 +338,7 @@ func (this *DavService) prepareMoveCopy(
if len(strs) == 2 { if len(strs) == 2 {
destinationPath = strs[1] destinationPath = strs[1]
} else { } else {
panic(result2.BadRequest("目标前缀必须为:%s", WEBDAV_PREFFIX)) panic(result.BadRequest("目标前缀必须为:%s", WEBDAV_PREFFIX))
} }
destinationName = util.GetFilenameOfPath(destinationPath) destinationName = util.GetFilenameOfPath(destinationPath)
@ -361,7 +361,7 @@ func (this *DavService) prepareMoveCopy(
//如果是空或者/就是请求根目录 //如果是空或者/就是请求根目录
if srcMatter.Uuid == MATTER_ROOT { if srcMatter.Uuid == MATTER_ROOT {
panic(result2.BadRequest("你不能移动根目录!")) panic(result.BadRequest("你不能移动根目录!"))
} }
//寻找目标文件夹matter //寻找目标文件夹matter
@ -405,19 +405,19 @@ func (this *DavService) HandleCopy(writer http.ResponseWriter, request *http.Req
//加锁 //加锁
func (this *DavService) HandleLock(writer http.ResponseWriter, request *http.Request, user *User, subPath string) { func (this *DavService) HandleLock(writer http.ResponseWriter, request *http.Request, user *User, subPath string) {
panic(result2.BadRequest("不支持LOCK方法")) panic(result.BadRequest("不支持LOCK方法"))
} }
//解锁 //解锁
func (this *DavService) HandleUnlock(writer http.ResponseWriter, request *http.Request, user *User, subPath string) { func (this *DavService) HandleUnlock(writer http.ResponseWriter, request *http.Request, user *User, subPath string) {
panic(result2.BadRequest("不支持UNLOCK方法")) panic(result.BadRequest("不支持UNLOCK方法"))
} }
//修改文件属性 //修改文件属性
func (this *DavService) HandleProppatch(writer http.ResponseWriter, request *http.Request, user *User, subPath string) { func (this *DavService) HandleProppatch(writer http.ResponseWriter, request *http.Request, user *User, subPath string) {
panic(result2.BadRequest("不支持PROPPATCH方法")) panic(result.BadRequest("不支持PROPPATCH方法"))
} }
//处理所有的请求 //处理所有的请求
@ -481,7 +481,7 @@ func (this *DavService) HandleDav(writer http.ResponseWriter, request *http.Requ
} else { } else {
panic(result2.BadRequest("该方法还不支持。%s", method)) panic(result.BadRequest("该方法还不支持。%s", method))
} }

View File

@ -3,7 +3,7 @@ package code
import ( import (
"net/http" "net/http"
"strconv" "strconv"
result2 "tank/code/tool/result" "tank/code/tool/result"
) )
type FootprintController struct { type FootprintController struct {
@ -43,11 +43,11 @@ func (this *FootprintController) RegisterRoutes() map[string]func(writer http.Re
} }
//查看详情。 //查看详情。
func (this *FootprintController) Detail(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *FootprintController) Detail(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid") uuid := request.FormValue("uuid")
if uuid == "" { if uuid == "" {
panic(result2.BadRequest("图片缓存的uuid必填")) panic(result.BadRequest("图片缓存的uuid必填"))
} }
footprint := this.footprintService.Detail(uuid) footprint := this.footprintService.Detail(uuid)
@ -65,7 +65,7 @@ func (this *FootprintController) Detail(writer http.ResponseWriter, request *htt
} }
//按照分页的方式查询 //按照分页的方式查询
func (this *FootprintController) Page(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *FootprintController) Page(writer http.ResponseWriter, request *http.Request) *result.WebResult {
//如果是根目录那么就传入root. //如果是根目录那么就传入root.
pageStr := request.FormValue("page") pageStr := request.FormValue("page")
@ -109,11 +109,11 @@ func (this *FootprintController) Page(writer http.ResponseWriter, request *http.
} }
//删除一条记录 //删除一条记录
func (this *FootprintController) Delete(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *FootprintController) Delete(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid") uuid := request.FormValue("uuid")
if uuid == "" { if uuid == "" {
panic(result2.BadRequest("uuid必填")) panic(result.BadRequest("uuid必填"))
} }
footprint := this.footprintDao.FindByUuid(uuid) footprint := this.footprintDao.FindByUuid(uuid)

View File

@ -4,7 +4,7 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
result2 "tank/code/tool/result" "tank/code/tool/result"
) )
type ImageCacheController struct { type ImageCacheController struct {
@ -45,11 +45,11 @@ func (this *ImageCacheController) RegisterRoutes() map[string]func(writer http.R
} }
//查看某个图片缓存的详情。 //查看某个图片缓存的详情。
func (this *ImageCacheController) Detail(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *ImageCacheController) Detail(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid") uuid := request.FormValue("uuid")
if uuid == "" { if uuid == "" {
panic(result2.BadRequest("图片缓存的uuid必填")) panic(result.BadRequest("图片缓存的uuid必填"))
} }
imageCache := this.imageCacheService.Detail(uuid) imageCache := this.imageCacheService.Detail(uuid)
@ -67,7 +67,7 @@ func (this *ImageCacheController) Detail(writer http.ResponseWriter, request *ht
} }
//按照分页的方式获取某个图片缓存夹下图片缓存和子图片缓存夹的列表,通常情况下只有一页。 //按照分页的方式获取某个图片缓存夹下图片缓存和子图片缓存夹的列表,通常情况下只有一页。
func (this *ImageCacheController) Page(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *ImageCacheController) Page(writer http.ResponseWriter, request *http.Request) *result.WebResult {
//如果是根目录那么就传入root. //如果是根目录那么就传入root.
pageStr := request.FormValue("page") pageStr := request.FormValue("page")
pageSizeStr := request.FormValue("pageSize") pageSizeStr := request.FormValue("pageSize")
@ -123,11 +123,11 @@ func (this *ImageCacheController) Page(writer http.ResponseWriter, request *http
} }
//删除一个图片缓存 //删除一个图片缓存
func (this *ImageCacheController) Delete(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *ImageCacheController) Delete(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid") uuid := request.FormValue("uuid")
if uuid == "" { if uuid == "" {
panic(result2.BadRequest("图片缓存的uuid必填")) panic(result.BadRequest("图片缓存的uuid必填"))
} }
imageCache := this.imageCacheDao.FindByUuid(uuid) imageCache := this.imageCacheDao.FindByUuid(uuid)
@ -136,7 +136,7 @@ func (this *ImageCacheController) Delete(writer http.ResponseWriter, request *ht
user := this.checkUser(writer, request) user := this.checkUser(writer, request)
if user.Role != USER_ROLE_ADMINISTRATOR && imageCache.UserUuid != user.Uuid { if user.Role != USER_ROLE_ADMINISTRATOR && imageCache.UserUuid != user.Uuid {
panic(result2.Unauthorized("没有权限")) panic(result.Unauthorized("没有权限"))
} }
this.imageCacheDao.Delete(imageCache) this.imageCacheDao.Delete(imageCache)
@ -145,11 +145,11 @@ func (this *ImageCacheController) Delete(writer http.ResponseWriter, request *ht
} }
//删除一系列图片缓存。 //删除一系列图片缓存。
func (this *ImageCacheController) DeleteBatch(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *ImageCacheController) DeleteBatch(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuids := request.FormValue("uuids") uuids := request.FormValue("uuids")
if uuids == "" { if uuids == "" {
panic(result2.BadRequest("图片缓存的uuids必填")) panic(result.BadRequest("图片缓存的uuids必填"))
} }
uuidArray := strings.Split(uuids, ",") uuidArray := strings.Split(uuids, ",")
@ -161,7 +161,7 @@ func (this *ImageCacheController) DeleteBatch(writer http.ResponseWriter, reques
//判断图片缓存的所属人是否正确 //判断图片缓存的所属人是否正确
user := this.checkUser(writer, request) user := this.checkUser(writer, request)
if user.Role != USER_ROLE_ADMINISTRATOR && imageCache.UserUuid != user.Uuid { if user.Role != USER_ROLE_ADMINISTRATOR && imageCache.UserUuid != user.Uuid {
panic(result2.Unauthorized("没有权限")) panic(result.Unauthorized("没有权限"))
} }
this.imageCacheDao.Delete(imageCache) this.imageCacheDao.Delete(imageCache)

View File

@ -12,7 +12,7 @@ import (
"regexp" "regexp"
"strconv" "strconv"
"tank/code/config" "tank/code/config"
result2 "tank/code/tool/result" "tank/code/tool/result"
"tank/code/tool/util" "tank/code/tool/util"
"time" "time"
) )
@ -130,7 +130,7 @@ func (this *InstallController) getCreateSQLFromFile(tableName string) string {
filePath := homePath + "/db/" + tableName + ".sql" filePath := homePath + "/db/" + tableName + ".sql"
exists, err := util.PathExists(filePath) exists, err := util.PathExists(filePath)
if err != nil { if err != nil {
panic(result2.Server("从安装目录判断建表语句文件是否存在时出错!")) panic(result.Server("从安装目录判断建表语句文件是否存在时出错!"))
} }
//2. 从GOPATH下面去找因为可能是开发环境 //2. 从GOPATH下面去找因为可能是开发环境
@ -142,11 +142,11 @@ func (this *InstallController) getCreateSQLFromFile(tableName string) string {
filePath = build.Default.GOPATH + "/src/tank/build/db/" + tableName + ".sql" filePath = build.Default.GOPATH + "/src/tank/build/db/" + tableName + ".sql"
exists, err = util.PathExists(filePath) exists, err = util.PathExists(filePath)
if err != nil { if err != nil {
panic(result2.Server("从GOPATH判断建表语句文件是否存在时出错")) panic(result.Server("从GOPATH判断建表语句文件是否存在时出错"))
} }
if !exists { if !exists {
panic(result2.Server("%s 或 %s 均不存在,请检查你的安装情况。", filePath1, filePath)) panic(result.Server("%s 或 %s 均不存在,请检查你的安装情况。", filePath1, filePath))
} }
} }
@ -219,17 +219,17 @@ func (this *InstallController) validateTableMetaList(tableInfoList []*InstallTab
strs = append(strs, v.DBName) strs = append(strs, v.DBName)
} }
panic(result2.BadRequest(fmt.Sprintf("%s 表的以下字段缺失:%v", tableInfo.Name, strs))) panic(result.BadRequest(fmt.Sprintf("%s 表的以下字段缺失:%v", tableInfo.Name, strs)))
} }
} else { } else {
panic(result2.BadRequest(tableInfo.Name + "表不存在")) panic(result.BadRequest(tableInfo.Name + "表不存在"))
} }
} }
} }
//验证数据库连接 //验证数据库连接
func (this *InstallController) Verify(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *InstallController) Verify(writer http.ResponseWriter, request *http.Request) *result.WebResult {
db := this.openDbConnection(writer, request) db := this.openDbConnection(writer, request)
defer this.closeDbConnection(db) defer this.closeDbConnection(db)
@ -242,7 +242,7 @@ func (this *InstallController) Verify(writer http.ResponseWriter, request *http.
} }
//获取需要安装的数据库表 //获取需要安装的数据库表
func (this *InstallController) TableInfoList(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *InstallController) TableInfoList(writer http.ResponseWriter, request *http.Request) *result.WebResult {
db := this.openDbConnection(writer, request) db := this.openDbConnection(writer, request)
defer this.closeDbConnection(db) defer this.closeDbConnection(db)
@ -251,7 +251,7 @@ func (this *InstallController) TableInfoList(writer http.ResponseWriter, request
} }
//创建缺失数据库和表 //创建缺失数据库和表
func (this *InstallController) CreateTable(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *InstallController) CreateTable(writer http.ResponseWriter, request *http.Request) *result.WebResult {
var tableNames = []IBase{&Dashboard{}, &DownloadToken{}, &Footprint{}, &ImageCache{}, &Matter{}, &Preference{}, &Session{}, &UploadToken{}, &User{}} var tableNames = []IBase{&Dashboard{}, &DownloadToken{}, &Footprint{}, &ImageCache{}, &Matter{}, &Preference{}, &Session{}, &UploadToken{}, &User{}}
var installTableInfos []*InstallTableInfo var installTableInfos []*InstallTableInfo
@ -280,7 +280,7 @@ func (this *InstallController) CreateTable(writer http.ResponseWriter, request *
} }
//获取管理员列表(10条记录) //获取管理员列表(10条记录)
func (this *InstallController) AdminList(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *InstallController) AdminList(writer http.ResponseWriter, request *http.Request) *result.WebResult {
db := this.openDbConnection(writer, request) db := this.openDbConnection(writer, request)
defer this.closeDbConnection(db) defer this.closeDbConnection(db)
@ -298,7 +298,7 @@ func (this *InstallController) AdminList(writer http.ResponseWriter, request *ht
} }
//创建管理员 //创建管理员
func (this *InstallController) CreateAdmin(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *InstallController) CreateAdmin(writer http.ResponseWriter, request *http.Request) *result.WebResult {
db := this.openDbConnection(writer, request) db := this.openDbConnection(writer, request)
defer this.closeDbConnection(db) defer this.closeDbConnection(db)
@ -309,15 +309,15 @@ func (this *InstallController) CreateAdmin(writer http.ResponseWriter, request *
//验证超级管理员的信息 //验证超级管理员的信息
if m, _ := regexp.MatchString(`^[0-9a-zA-Z_]+$`, adminUsername); !m { if m, _ := regexp.MatchString(`^[0-9a-zA-Z_]+$`, adminUsername); !m {
panic(result2.BadRequest(`超级管理员用户名必填,且只能包含字母,数字和'_''`)) panic(result.BadRequest(`超级管理员用户名必填,且只能包含字母,数字和'_''`))
} }
if len(adminPassword) < 6 { if len(adminPassword) < 6 {
panic(result2.BadRequest(`超级管理员密码长度至少为6位`)) panic(result.BadRequest(`超级管理员密码长度至少为6位`))
} }
if adminEmail == "" { if adminEmail == "" {
panic(result2.BadRequest(`超级管理员邮箱必填`)) panic(result.BadRequest(`超级管理员邮箱必填`))
} }
//检查是否有重复。 //检查是否有重复。
@ -325,14 +325,14 @@ func (this *InstallController) CreateAdmin(writer http.ResponseWriter, request *
db1 := db.Model(&User{}).Where("email = ?", adminEmail).Count(&count1) db1 := db.Model(&User{}).Where("email = ?", adminEmail).Count(&count1)
this.PanicError(db1.Error) this.PanicError(db1.Error)
if count1 > 0 { if count1 > 0 {
panic(result2.BadRequest(`该邮箱已存在`)) panic(result.BadRequest(`该邮箱已存在`))
} }
var count2 int64 var count2 int64
db2 := db.Model(&User{}).Where("username = ?", adminUsername).Count(&count2) db2 := db.Model(&User{}).Where("username = ?", adminUsername).Count(&count2)
this.PanicError(db2.Error) this.PanicError(db2.Error)
if count2 > 0 { if count2 > 0 {
panic(result2.BadRequest(`该用户名已存在`)) panic(result.BadRequest(`该用户名已存在`))
} }
user := &User{} user := &User{}
@ -359,7 +359,7 @@ func (this *InstallController) CreateAdmin(writer http.ResponseWriter, request *
} }
//(如果数据库中本身存在管理员了)验证管理员 //(如果数据库中本身存在管理员了)验证管理员
func (this *InstallController) ValidateAdmin(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *InstallController) ValidateAdmin(writer http.ResponseWriter, request *http.Request) *result.WebResult {
db := this.openDbConnection(writer, request) db := this.openDbConnection(writer, request)
defer this.closeDbConnection(db) defer this.closeDbConnection(db)
@ -369,24 +369,24 @@ func (this *InstallController) ValidateAdmin(writer http.ResponseWriter, request
//验证超级管理员的信息 //验证超级管理员的信息
if adminEmail == "" { if adminEmail == "" {
panic(result2.BadRequest(`超级管理员邮箱必填`)) panic(result.BadRequest(`超级管理员邮箱必填`))
} }
if len(adminPassword) < 6 { if len(adminPassword) < 6 {
panic(result2.BadRequest(`超级管理员密码长度至少为6位`)) panic(result.BadRequest(`超级管理员密码长度至少为6位`))
} }
var existEmailUser = &User{} var existEmailUser = &User{}
db = db.Where(&User{Email: adminEmail}).First(existEmailUser) db = db.Where(&User{Email: adminEmail}).First(existEmailUser)
if db.Error != nil { if db.Error != nil {
panic(result2.BadRequest(fmt.Sprintf("%s对应的用户不存在", adminEmail))) panic(result.BadRequest(fmt.Sprintf("%s对应的用户不存在", adminEmail)))
} }
if !util.MatchBcrypt(adminPassword, existEmailUser.Password) { if !util.MatchBcrypt(adminPassword, existEmailUser.Password) {
panic(result2.BadRequest("邮箱或密码错误")) panic(result.BadRequest("邮箱或密码错误"))
} }
if existEmailUser.Role != USER_ROLE_ADMINISTRATOR { if existEmailUser.Role != USER_ROLE_ADMINISTRATOR {
panic(result2.BadRequest("该账号不是管理员")) panic(result.BadRequest("该账号不是管理员"))
} }
return this.Success("OK") return this.Success("OK")
@ -394,7 +394,7 @@ func (this *InstallController) ValidateAdmin(writer http.ResponseWriter, request
} }
//完成系统安装 //完成系统安装
func (this *InstallController) Finish(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *InstallController) Finish(writer http.ResponseWriter, request *http.Request) *result.WebResult {
mysqlPortStr := request.FormValue("mysqlPort") mysqlPortStr := request.FormValue("mysqlPort")
mysqlHost := request.FormValue("mysqlHost") mysqlHost := request.FormValue("mysqlHost")
@ -422,7 +422,7 @@ func (this *InstallController) Finish(writer http.ResponseWriter, request *http.
db1 := db.Model(&User{}).Where("role = ?", USER_ROLE_ADMINISTRATOR).Count(&count1) db1 := db.Model(&User{}).Where("role = ?", USER_ROLE_ADMINISTRATOR).Count(&count1)
this.PanicError(db1.Error) this.PanicError(db1.Error)
if count1 == 0 { if count1 == 0 {
panic(result2.BadRequest(`请至少配置一名管理员`)) panic(result.BadRequest(`请至少配置一名管理员`))
} }
var configItem = &config.ConfigItem{ var configItem = &config.ConfigItem{

View File

@ -4,7 +4,7 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
result2 "tank/code/tool/result" "tank/code/tool/result"
) )
type MatterController struct { type MatterController struct {
@ -68,11 +68,11 @@ func (this *MatterController) RegisterRoutes() map[string]func(writer http.Respo
} }
//查看某个文件的详情。 //查看某个文件的详情。
func (this *MatterController) Detail(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *MatterController) Detail(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid") uuid := request.FormValue("uuid")
if uuid == "" { if uuid == "" {
panic(result2.BadRequest("文件的uuid必填")) panic(result.BadRequest("文件的uuid必填"))
} }
matter := this.matterService.Detail(uuid) matter := this.matterService.Detail(uuid)
@ -90,7 +90,7 @@ func (this *MatterController) Detail(writer http.ResponseWriter, request *http.R
} }
//按照分页的方式获取某个文件夹下文件和子文件夹的列表,通常情况下只有一页。 //按照分页的方式获取某个文件夹下文件和子文件夹的列表,通常情况下只有一页。
func (this *MatterController) Page(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *MatterController) Page(writer http.ResponseWriter, request *http.Request) *result.WebResult {
//如果是根目录那么就传入root. //如果是根目录那么就传入root.
pageStr := request.FormValue("page") pageStr := request.FormValue("page")
@ -171,7 +171,7 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req
} }
//创建一个文件夹。 //创建一个文件夹。
func (this *MatterController) CreateDirectory(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *MatterController) CreateDirectory(writer http.ResponseWriter, request *http.Request) *result.WebResult {
puuid := request.FormValue("puuid") puuid := request.FormValue("puuid")
name := request.FormValue("name") name := request.FormValue("name")
@ -197,7 +197,7 @@ func (this *MatterController) CreateDirectory(writer http.ResponseWriter, reques
} }
//上传文件 //上传文件
func (this *MatterController) Upload(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *MatterController) Upload(writer http.ResponseWriter, request *http.Request) *result.WebResult {
userUuid := request.FormValue("userUuid") userUuid := request.FormValue("userUuid")
puuid := request.FormValue("puuid") puuid := request.FormValue("puuid")
@ -240,7 +240,7 @@ func (this *MatterController) Upload(writer http.ResponseWriter, request *http.R
} }
//从一个Url中去爬取资源 //从一个Url中去爬取资源
func (this *MatterController) Crawl(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *MatterController) Crawl(writer http.ResponseWriter, request *http.Request) *result.WebResult {
userUuid := request.FormValue("userUuid") userUuid := request.FormValue("userUuid")
puuid := request.FormValue("puuid") puuid := request.FormValue("puuid")
@ -280,11 +280,11 @@ func (this *MatterController) Crawl(writer http.ResponseWriter, request *http.Re
} }
//删除一个文件 //删除一个文件
func (this *MatterController) Delete(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *MatterController) Delete(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid") uuid := request.FormValue("uuid")
if uuid == "" { if uuid == "" {
panic(result2.BadRequest("文件的uuid必填")) panic(result.BadRequest("文件的uuid必填"))
} }
matter := this.matterDao.CheckByUuid(uuid) matter := this.matterDao.CheckByUuid(uuid)
@ -292,7 +292,7 @@ func (this *MatterController) Delete(writer http.ResponseWriter, request *http.R
//判断文件的所属人是否正确 //判断文件的所属人是否正确
user := this.checkUser(writer, request) user := this.checkUser(writer, request)
if user.Role != USER_ROLE_ADMINISTRATOR && matter.UserUuid != user.Uuid { if user.Role != USER_ROLE_ADMINISTRATOR && matter.UserUuid != user.Uuid {
panic(result2.Unauthorized("没有权限")) panic(result.Unauthorized("没有权限"))
} }
this.matterService.AtomicDelete(matter) this.matterService.AtomicDelete(matter)
@ -301,11 +301,11 @@ func (this *MatterController) Delete(writer http.ResponseWriter, request *http.R
} }
//删除一系列文件。 //删除一系列文件。
func (this *MatterController) DeleteBatch(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *MatterController) DeleteBatch(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuids := request.FormValue("uuids") uuids := request.FormValue("uuids")
if uuids == "" { if uuids == "" {
panic(result2.BadRequest("文件的uuids必填")) panic(result.BadRequest("文件的uuids必填"))
} }
uuidArray := strings.Split(uuids, ",") uuidArray := strings.Split(uuids, ",")
@ -323,7 +323,7 @@ func (this *MatterController) DeleteBatch(writer http.ResponseWriter, request *h
//判断文件的所属人是否正确 //判断文件的所属人是否正确
user := this.checkUser(writer, request) user := this.checkUser(writer, request)
if user.Role != USER_ROLE_ADMINISTRATOR && matter.UserUuid != user.Uuid { if user.Role != USER_ROLE_ADMINISTRATOR && matter.UserUuid != user.Uuid {
panic(result2.Unauthorized("没有权限")) panic(result.Unauthorized("没有权限"))
} }
this.matterService.AtomicDelete(matter) this.matterService.AtomicDelete(matter)
@ -334,7 +334,7 @@ func (this *MatterController) DeleteBatch(writer http.ResponseWriter, request *h
} }
//重命名一个文件或一个文件夹 //重命名一个文件或一个文件夹
func (this *MatterController) Rename(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *MatterController) Rename(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid") uuid := request.FormValue("uuid")
name := request.FormValue("name") name := request.FormValue("name")
@ -345,7 +345,7 @@ func (this *MatterController) Rename(writer http.ResponseWriter, request *http.R
matter := this.matterDao.CheckByUuid(uuid) matter := this.matterDao.CheckByUuid(uuid)
if user.Role != USER_ROLE_ADMINISTRATOR && matter.UserUuid != user.Uuid { if user.Role != USER_ROLE_ADMINISTRATOR && matter.UserUuid != user.Uuid {
panic(result2.Unauthorized("没有权限")) panic(result.Unauthorized("没有权限"))
} }
this.matterService.AtomicRename(matter, name, user) this.matterService.AtomicRename(matter, name, user)
@ -354,7 +354,7 @@ func (this *MatterController) Rename(writer http.ResponseWriter, request *http.R
} }
//改变一个文件的公私有属性 //改变一个文件的公私有属性
func (this *MatterController) ChangePrivacy(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *MatterController) ChangePrivacy(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid") uuid := request.FormValue("uuid")
privacyStr := request.FormValue("privacy") privacyStr := request.FormValue("privacy")
privacy := false privacy := false
@ -371,7 +371,7 @@ func (this *MatterController) ChangePrivacy(writer http.ResponseWriter, request
//权限验证 //权限验证
user := this.checkUser(writer, request) user := this.checkUser(writer, request)
if user.Role != USER_ROLE_ADMINISTRATOR && matter.UserUuid != user.Uuid { if user.Role != USER_ROLE_ADMINISTRATOR && matter.UserUuid != user.Uuid {
panic(result2.Unauthorized("没有权限")) panic(result.Unauthorized("没有权限"))
} }
matter.Privacy = privacy matter.Privacy = privacy
@ -381,7 +381,7 @@ func (this *MatterController) ChangePrivacy(writer http.ResponseWriter, request
} }
//将一个文件夹或者文件移入到另一个文件夹下。 //将一个文件夹或者文件移入到另一个文件夹下。
func (this *MatterController) Move(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *MatterController) Move(writer http.ResponseWriter, request *http.Request) *result.WebResult {
srcUuidsStr := request.FormValue("srcUuids") srcUuidsStr := request.FormValue("srcUuids")
destUuid := request.FormValue("destUuid") destUuid := request.FormValue("destUuid")
@ -390,7 +390,7 @@ func (this *MatterController) Move(writer http.ResponseWriter, request *http.Req
var srcUuids []string var srcUuids []string
//验证参数。 //验证参数。
if srcUuidsStr == "" { if srcUuidsStr == "" {
panic(result2.BadRequest("srcUuids参数必填")) panic(result.BadRequest("srcUuids参数必填"))
} else { } else {
srcUuids = strings.Split(srcUuidsStr, ",") srcUuids = strings.Split(srcUuidsStr, ",")
} }
@ -405,11 +405,11 @@ func (this *MatterController) Move(writer http.ResponseWriter, request *http.Req
//验证dest是否有问题 //验证dest是否有问题
var destMatter = this.matterDao.CheckWithRootByUuid(destUuid, user) var destMatter = this.matterDao.CheckWithRootByUuid(destUuid, user)
if !destMatter.Dir { if !destMatter.Dir {
panic(result2.BadRequest("目标不是文件夹")) panic(result.BadRequest("目标不是文件夹"))
} }
if user.Role != USER_ROLE_ADMINISTRATOR && destMatter.UserUuid != user.Uuid { if user.Role != USER_ROLE_ADMINISTRATOR && destMatter.UserUuid != user.Uuid {
panic(result2.Unauthorized("没有权限")) panic(result.Unauthorized("没有权限"))
} }
var srcMatters []*Matter var srcMatters []*Matter
@ -419,14 +419,14 @@ func (this *MatterController) Move(writer http.ResponseWriter, request *http.Req
srcMatter := this.matterDao.CheckByUuid(uuid) srcMatter := this.matterDao.CheckByUuid(uuid)
if srcMatter.Puuid == destMatter.Uuid { if srcMatter.Puuid == destMatter.Uuid {
panic(result2.BadRequest("没有进行移动,操作无效!")) panic(result.BadRequest("没有进行移动,操作无效!"))
} }
//判断同级文件夹中是否有同名的文件 //判断同级文件夹中是否有同名的文件
count := this.matterDao.CountByUserUuidAndPuuidAndDirAndName(user.Uuid, destMatter.Uuid, srcMatter.Dir, srcMatter.Name) count := this.matterDao.CountByUserUuidAndPuuidAndDirAndName(user.Uuid, destMatter.Uuid, srcMatter.Dir, srcMatter.Name)
if count > 0 { if count > 0 {
panic(result2.BadRequest("【" + srcMatter.Name + "】在目标文件夹已经存在了,操作失败。")) panic(result.BadRequest("【" + srcMatter.Name + "】在目标文件夹已经存在了,操作失败。"))
} }
//判断和目标文件夹是否是同一个主人。 //判断和目标文件夹是否是同一个主人。

View File

@ -5,7 +5,7 @@ import (
"github.com/nu7hatch/gouuid" "github.com/nu7hatch/gouuid"
"os" "os"
"tank/code/config" "tank/code/config"
result2 "tank/code/tool/result" "tank/code/tool/result"
"tank/code/tool/util" "tank/code/tool/util"
"time" "time"
) )
@ -33,7 +33,7 @@ func (this *MatterDao) FindByUuid(uuid string) *Matter {
var matter Matter var matter Matter
db := CONTEXT.DB.Where(&Matter{Base: Base{Uuid: uuid}}).First(&matter) db := CONTEXT.DB.Where(&Matter{Base: Base{Uuid: uuid}}).First(&matter)
if db.Error != nil { if db.Error != nil {
if db.Error.Error() == result2.DB_ERROR_NOT_FOUND { if db.Error.Error() == result.DB_ERROR_NOT_FOUND {
return nil return nil
} else { } else {
this.PanicError(db.Error) this.PanicError(db.Error)
@ -46,7 +46,7 @@ func (this *MatterDao) FindByUuid(uuid string) *Matter {
func (this *MatterDao) CheckByUuid(uuid string) *Matter { func (this *MatterDao) CheckByUuid(uuid string) *Matter {
matter := this.FindByUuid(uuid) matter := this.FindByUuid(uuid)
if matter == nil { if matter == nil {
panic(result2.NotFound("%s 对应的matter不存在", uuid)) panic(result.NotFound("%s 对应的matter不存在", uuid))
} }
return matter return matter
} }
@ -55,13 +55,13 @@ func (this *MatterDao) CheckByUuid(uuid string) *Matter {
func (this *MatterDao) CheckWithRootByUuid(uuid string, user *User) *Matter { func (this *MatterDao) CheckWithRootByUuid(uuid string, user *User) *Matter {
if uuid == "" { if uuid == "" {
panic(result2.BadRequest("uuid cannot be nil.")) panic(result.BadRequest("uuid cannot be nil."))
} }
var matter *Matter var matter *Matter
if uuid == MATTER_ROOT { if uuid == MATTER_ROOT {
if user == nil { if user == nil {
panic(result2.BadRequest("user cannot be nil.")) panic(result.BadRequest("user cannot be nil."))
} }
matter = NewRootMatter(user) matter = NewRootMatter(user)
} else { } else {
@ -77,7 +77,7 @@ func (this *MatterDao) CheckWithRootByPath(path string, user *User) *Matter {
var matter *Matter var matter *Matter
if user == nil { if user == nil {
panic(result2.BadRequest("user cannot be nil.")) panic(result.BadRequest("user cannot be nil."))
} }
//目标文件夹matter //目标文件夹matter
@ -335,7 +335,7 @@ func (this *MatterDao) findByUserUuidAndPath(userUuid string, path string) *Matt
db := CONTEXT.DB.Model(&Matter{}).Where(wp.Query, wp.Args...).First(matter) db := CONTEXT.DB.Model(&Matter{}).Where(wp.Query, wp.Args...).First(matter)
if db.Error != nil { if db.Error != nil {
if db.Error.Error() == result2.DB_ERROR_NOT_FOUND { if db.Error.Error() == result.DB_ERROR_NOT_FOUND {
return nil return nil
} else { } else {
this.PanicError(db.Error) this.PanicError(db.Error)
@ -349,11 +349,11 @@ func (this *MatterDao) findByUserUuidAndPath(userUuid string, path string) *Matt
func (this *MatterDao) checkByUserUuidAndPath(userUuid string, path string) *Matter { func (this *MatterDao) checkByUserUuidAndPath(userUuid string, path string) *Matter {
if path == "" { if path == "" {
panic(result2.BadRequest("path 不能为空")) panic(result.BadRequest("path 不能为空"))
} }
matter := this.findByUserUuidAndPath(userUuid, path) matter := this.findByUserUuidAndPath(userUuid, path)
if matter == nil { if matter == nil {
panic(result2.NotFound("path = %s 不存在", path)) panic(result.NotFound("path = %s 不存在", path))
} }
return matter return matter

View File

@ -7,7 +7,7 @@ import (
"regexp" "regexp"
"strings" "strings"
download2 "tank/code/tool/download" download2 "tank/code/tool/download"
result2 "tank/code/tool/result" "tank/code/tool/result"
"tank/code/tool/util" "tank/code/tool/util"
) )
@ -72,7 +72,7 @@ func (this *MatterService) DownloadFile(
func (this *MatterService) AtomicDelete(matter *Matter) { func (this *MatterService) AtomicDelete(matter *Matter) {
if matter == nil { if matter == nil {
panic(result2.BadRequest("matter不能为nil")) panic(result.BadRequest("matter不能为nil"))
} }
//操作锁 //操作锁
@ -86,17 +86,17 @@ func (this *MatterService) AtomicDelete(matter *Matter) {
func (this *MatterService) Upload(file io.Reader, user *User, dirMatter *Matter, filename string, privacy bool) *Matter { func (this *MatterService) Upload(file io.Reader, user *User, dirMatter *Matter, filename string, privacy bool) *Matter {
if user == nil { if user == nil {
panic(result2.BadRequest("user cannot be nil.")) panic(result.BadRequest("user cannot be nil."))
} }
//验证dirMatter //验证dirMatter
if dirMatter == nil { if dirMatter == nil {
panic(result2.BadRequest("dirMatter cannot be nil.")) panic(result.BadRequest("dirMatter cannot be nil."))
} }
//文件名不能太长。 //文件名不能太长。
if len(filename) > MATTER_NAME_MAX_LENGTH { if len(filename) > MATTER_NAME_MAX_LENGTH {
panic(result2.BadRequest("文件名不能超过%s", MATTER_NAME_MAX_LENGTH)) panic(result.BadRequest("文件名不能超过%s", MATTER_NAME_MAX_LENGTH))
} }
//文件夹路径 //文件夹路径
@ -105,7 +105,7 @@ func (this *MatterService) Upload(file io.Reader, user *User, dirMatter *Matter,
count := this.matterDao.CountByUserUuidAndPuuidAndDirAndName(user.Uuid, dirMatter.Uuid, false, filename) count := this.matterDao.CountByUserUuidAndPuuidAndDirAndName(user.Uuid, dirMatter.Uuid, false, filename)
if count > 0 { if count > 0 {
panic(result2.BadRequest("该目录下%s已经存在了", filename)) panic(result.BadRequest("该目录下%s已经存在了", filename))
} }
//获取文件应该存放在的物理路径的绝对路径和相对路径。 //获取文件应该存放在的物理路径的绝对路径和相对路径。
@ -144,7 +144,7 @@ func (this *MatterService) Upload(file io.Reader, user *User, dirMatter *Matter,
err = os.Remove(fileAbsolutePath) err = os.Remove(fileAbsolutePath)
this.PanicError(err) this.PanicError(err)
panic(result2.BadRequest("文件大小超出限制 %s > %s ", util.HumanFileSize(user.SizeLimit), util.HumanFileSize(fileSize))) panic(result.BadRequest("文件大小超出限制 %s > %s ", util.HumanFileSize(user.SizeLimit), util.HumanFileSize(fileSize)))
} }
} }
@ -169,7 +169,7 @@ func (this *MatterService) Upload(file io.Reader, user *User, dirMatter *Matter,
func (this *MatterService) AtomicUpload(file io.Reader, user *User, dirMatter *Matter, filename string, privacy bool) *Matter { func (this *MatterService) AtomicUpload(file io.Reader, user *User, dirMatter *Matter, filename string, privacy bool) *Matter {
if user == nil { if user == nil {
panic(result2.BadRequest("user cannot be nil.")) panic(result.BadRequest("user cannot be nil."))
} }
//操作锁 //操作锁
@ -184,33 +184,33 @@ func (this *MatterService) createDirectory(dirMatter *Matter, name string, user
//父级matter必须存在 //父级matter必须存在
if dirMatter == nil { if dirMatter == nil {
panic(result2.BadRequest("dirMatter必须指定")) panic(result.BadRequest("dirMatter必须指定"))
} }
//必须是文件夹 //必须是文件夹
if !dirMatter.Dir { if !dirMatter.Dir {
panic(result2.BadRequest("dirMatter必须是文件夹")) panic(result.BadRequest("dirMatter必须是文件夹"))
} }
if dirMatter.UserUuid != user.Uuid { if dirMatter.UserUuid != user.Uuid {
panic(result2.BadRequest("dirMatter的userUuid和user不一致")) panic(result.BadRequest("dirMatter的userUuid和user不一致"))
} }
name = strings.TrimSpace(name) name = strings.TrimSpace(name)
//验证参数。 //验证参数。
if name == "" { if name == "" {
panic(result2.BadRequest("name参数必填并且不能全是空格")) panic(result.BadRequest("name参数必填并且不能全是空格"))
} }
if len(name) > MATTER_NAME_MAX_LENGTH { if len(name) > MATTER_NAME_MAX_LENGTH {
panic(result2.BadRequest("name长度不能超过%d", MATTER_NAME_MAX_LENGTH)) panic(result.BadRequest("name长度不能超过%d", MATTER_NAME_MAX_LENGTH))
} }
if m, _ := regexp.MatchString(`[<>|*?/\\]`, name); m { if m, _ := regexp.MatchString(`[<>|*?/\\]`, name); m {
panic(result2.BadRequest(`名称中不能包含以下特殊符号:< > | * ? / \`)) panic(result.BadRequest(`名称中不能包含以下特殊符号:< > | * ? / \`))
} }
//判断同级文件夹中是否有同名的文件夹 //判断同级文件夹中是否有同名的文件夹
@ -218,14 +218,14 @@ func (this *MatterService) createDirectory(dirMatter *Matter, name string, user
if count > 0 { if count > 0 {
panic(result2.BadRequest("%s 已经存在了,请使用其他名称。", name)) panic(result.BadRequest("%s 已经存在了,请使用其他名称。", name))
} }
parts := strings.Split(dirMatter.Path, "/") parts := strings.Split(dirMatter.Path, "/")
this.logger.Info("%s的层数%d", dirMatter.Name, len(parts)) this.logger.Info("%s的层数%d", dirMatter.Name, len(parts))
if len(parts) > 32 { if len(parts) > 32 {
panic(result2.BadRequest("文件夹最多%d层", MATTER_NAME_MAX_DEPTH)) panic(result.BadRequest("文件夹最多%d层", MATTER_NAME_MAX_DEPTH))
} }
//绝对路径 //绝对路径
@ -277,7 +277,7 @@ func (this *MatterService) handleOverwrite(userUuid string, destinationPath stri
//要求覆盖。那么删除。 //要求覆盖。那么删除。
this.matterDao.Delete(destMatter) this.matterDao.Delete(destMatter)
} else { } else {
panic(result2.BadRequest("%s已经存在操作失败", destMatter.Path)) panic(result.BadRequest("%s已经存在操作失败", destMatter.Path))
} }
} }
@ -287,11 +287,11 @@ func (this *MatterService) handleOverwrite(userUuid string, destinationPath stri
func (this *MatterService) move(srcMatter *Matter, destDirMatter *Matter) { func (this *MatterService) move(srcMatter *Matter, destDirMatter *Matter) {
if srcMatter == nil { if srcMatter == nil {
panic(result2.BadRequest("srcMatter cannot be nil.")) panic(result.BadRequest("srcMatter cannot be nil."))
} }
if !destDirMatter.Dir { if !destDirMatter.Dir {
panic(result2.BadRequest("目标必须为文件夹")) panic(result.BadRequest("目标必须为文件夹"))
} }
if srcMatter.Dir { if srcMatter.Dir {
@ -341,7 +341,7 @@ func (this *MatterService) move(srcMatter *Matter, destDirMatter *Matter) {
func (this *MatterService) AtomicMove(srcMatter *Matter, destDirMatter *Matter, overwrite bool) { func (this *MatterService) AtomicMove(srcMatter *Matter, destDirMatter *Matter, overwrite bool) {
if srcMatter == nil { if srcMatter == nil {
panic(result2.BadRequest("srcMatter cannot be nil.")) panic(result.BadRequest("srcMatter cannot be nil."))
} }
//操作锁 //操作锁
@ -349,10 +349,10 @@ func (this *MatterService) AtomicMove(srcMatter *Matter, destDirMatter *Matter,
defer this.userService.MatterUnlock(srcMatter.UserUuid) defer this.userService.MatterUnlock(srcMatter.UserUuid)
if destDirMatter == nil { if destDirMatter == nil {
panic(result2.BadRequest("destDirMatter cannot be nil.")) panic(result.BadRequest("destDirMatter cannot be nil."))
} }
if !destDirMatter.Dir { if !destDirMatter.Dir {
panic(result2.BadRequest("目标必须为文件夹")) panic(result.BadRequest("目标必须为文件夹"))
} }
//文件夹不能把自己移入到自己中,也不可以移入到自己的子文件夹下。 //文件夹不能把自己移入到自己中,也不可以移入到自己的子文件夹下。
@ -377,7 +377,7 @@ func (this *MatterService) AtomicMove(srcMatter *Matter, destDirMatter *Matter,
func (this *MatterService) AtomicMoveBatch(srcMatters []*Matter, destDirMatter *Matter) { func (this *MatterService) AtomicMoveBatch(srcMatters []*Matter, destDirMatter *Matter) {
if destDirMatter == nil { if destDirMatter == nil {
panic(result2.BadRequest("destDirMatter cannot be nil.")) panic(result.BadRequest("destDirMatter cannot be nil."))
} }
//操作锁 //操作锁
@ -385,11 +385,11 @@ func (this *MatterService) AtomicMoveBatch(srcMatters []*Matter, destDirMatter *
defer this.userService.MatterUnlock(destDirMatter.UserUuid) defer this.userService.MatterUnlock(destDirMatter.UserUuid)
if srcMatters == nil { if srcMatters == nil {
panic(result2.BadRequest("srcMatters cannot be nil.")) panic(result.BadRequest("srcMatters cannot be nil."))
} }
if !destDirMatter.Dir { if !destDirMatter.Dir {
panic(result2.BadRequest("目标必须为文件夹")) panic(result.BadRequest("目标必须为文件夹"))
} }
//文件夹不能把自己移入到自己中,也不可以移入到自己的子文件夹下。 //文件夹不能把自己移入到自己中,也不可以移入到自己的子文件夹下。
@ -469,7 +469,7 @@ func (this *MatterService) copy(srcMatter *Matter, destDirMatter *Matter, name s
func (this *MatterService) AtomicCopy(srcMatter *Matter, destDirMatter *Matter, name string, overwrite bool) { func (this *MatterService) AtomicCopy(srcMatter *Matter, destDirMatter *Matter, name string, overwrite bool) {
if srcMatter == nil { if srcMatter == nil {
panic(result2.BadRequest("srcMatter cannot be nil.")) panic(result.BadRequest("srcMatter cannot be nil."))
} }
//操作锁 //操作锁
@ -477,7 +477,7 @@ func (this *MatterService) AtomicCopy(srcMatter *Matter, destDirMatter *Matter,
defer this.userService.MatterUnlock(srcMatter.UserUuid) defer this.userService.MatterUnlock(srcMatter.UserUuid)
if !destDirMatter.Dir { if !destDirMatter.Dir {
panic(result2.BadRequest("目标必须为文件夹")) panic(result.BadRequest("目标必须为文件夹"))
} }
destinationPath := destDirMatter.Path + "/" + name destinationPath := destDirMatter.Path + "/" + name
@ -490,7 +490,7 @@ func (this *MatterService) AtomicCopy(srcMatter *Matter, destDirMatter *Matter,
func (this *MatterService) AtomicRename(matter *Matter, name string, user *User) { func (this *MatterService) AtomicRename(matter *Matter, name string, user *User) {
if user == nil { if user == nil {
panic(result2.BadRequest("user cannot be nil")) panic(result.BadRequest("user cannot be nil"))
} }
//操作锁 //操作锁
@ -499,10 +499,10 @@ func (this *MatterService) AtomicRename(matter *Matter, name string, user *User)
//验证参数。 //验证参数。
if name == "" { if name == "" {
panic(result2.BadRequest("name参数必填")) panic(result.BadRequest("name参数必填"))
} }
if m, _ := regexp.MatchString(`[<>|*?/\\]`, name); m { if m, _ := regexp.MatchString(`[<>|*?/\\]`, name); m {
panic(result2.BadRequest(`名称中不能包含以下特殊符号:< > | * ? / \`)) panic(result.BadRequest(`名称中不能包含以下特殊符号:< > | * ? / \`))
} }
if len(name) > 200 { if len(name) > 200 {
@ -510,14 +510,14 @@ func (this *MatterService) AtomicRename(matter *Matter, name string, user *User)
} }
if name == matter.Name { if name == matter.Name {
panic(result2.BadRequest("新名称和旧名称一样,操作失败!")) panic(result.BadRequest("新名称和旧名称一样,操作失败!"))
} }
//判断同级文件夹中是否有同名的文件 //判断同级文件夹中是否有同名的文件
count := this.matterDao.CountByUserUuidAndPuuidAndDirAndName(user.Uuid, matter.Puuid, matter.Dir, name) count := this.matterDao.CountByUserUuidAndPuuidAndDirAndName(user.Uuid, matter.Puuid, matter.Dir, name)
if count > 0 { if count > 0 {
panic(result2.BadRequest("【" + name + "】已经存在了,请使用其他名称。")) panic(result.BadRequest("【" + name + "】已经存在了,请使用其他名称。"))
} }
if matter.Dir { if matter.Dir {
@ -594,7 +594,7 @@ func (this *MatterService) CreateDirectories(user *User, dirPath string) *Matter
folders := strings.Split(dirPath, "/") folders := strings.Split(dirPath, "/")
if len(folders) > MATTER_NAME_MAX_DEPTH { if len(folders) > MATTER_NAME_MAX_DEPTH {
panic(result2.BadRequest("文件夹最多%d层。", MATTER_NAME_MAX_DEPTH)) panic(result.BadRequest("文件夹最多%d层。", MATTER_NAME_MAX_DEPTH))
} }
var dirMatter *Matter var dirMatter *Matter
@ -616,7 +616,7 @@ func (this *MatterService) CreateDirectories(user *User, dirPath string) *Matter
func (this *MatterService) WrapDetail(matter *Matter) *Matter { func (this *MatterService) WrapDetail(matter *Matter) *Matter {
if matter == nil { if matter == nil {
panic(result2.BadRequest("matter cannot be nil.")) panic(result.BadRequest("matter cannot be nil."))
} }
//组装file的内容展示其父组件。 //组装file的内容展示其父组件。
@ -642,7 +642,7 @@ func (this *MatterService) Detail(uuid string) *Matter {
func (this *MatterService) AtomicCrawl(url string, filename string, user *User, dirMatter *Matter, privacy bool) *Matter { func (this *MatterService) AtomicCrawl(url string, filename string, user *User, dirMatter *Matter, privacy bool) *Matter {
if user == nil { if user == nil {
panic(result2.BadRequest("user cannot be nil.")) panic(result.BadRequest("user cannot be nil."))
} }
//操作锁 //操作锁

View File

@ -2,7 +2,7 @@ package code
import ( import (
"net/http" "net/http"
result2 "tank/code/tool/result" "tank/code/tool/result"
"tank/code/tool/util" "tank/code/tool/util"
) )
@ -43,7 +43,7 @@ func (this *PreferenceController) RegisterRoutes() map[string]func(writer http.R
} }
//查看某个偏好设置的详情。 //查看某个偏好设置的详情。
func (this *PreferenceController) Fetch(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *PreferenceController) Fetch(writer http.ResponseWriter, request *http.Request) *result.WebResult {
preference := this.preferenceService.Fetch() preference := this.preferenceService.Fetch()
@ -51,7 +51,7 @@ func (this *PreferenceController) Fetch(writer http.ResponseWriter, request *htt
} }
//修改 //修改
func (this *PreferenceController) Edit(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *PreferenceController) Edit(writer http.ResponseWriter, request *http.Request) *result.WebResult {
//验证参数。 //验证参数。
name := request.FormValue("name") name := request.FormValue("name")
@ -86,13 +86,13 @@ func (this *PreferenceController) Edit(writer http.ResponseWriter, request *http
} }
//清扫系统,所有数据全部丢失。一定要非常慎点,非常慎点!只在系统初始化的时候点击! //清扫系统,所有数据全部丢失。一定要非常慎点,非常慎点!只在系统初始化的时候点击!
func (this *PreferenceController) SystemCleanup(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *PreferenceController) SystemCleanup(writer http.ResponseWriter, request *http.Request) *result.WebResult {
user := this.checkUser(writer, request) user := this.checkUser(writer, request)
password := request.FormValue("password") password := request.FormValue("password")
if !util.MatchBcrypt(password, user.Password) { if !util.MatchBcrypt(password, user.Password) {
panic(result2.BadRequest("密码错误,不能执行!")) panic(result.BadRequest("密码错误,不能执行!"))
} }
for _, bean := range CONTEXT.BeanMap { for _, bean := range CONTEXT.BeanMap {

View File

@ -2,7 +2,7 @@ package code
import ( import (
"github.com/nu7hatch/gouuid" "github.com/nu7hatch/gouuid"
result2 "tank/code/tool/result" "tank/code/tool/result"
"time" "time"
) )
@ -18,7 +18,7 @@ func (this *PreferenceDao) Fetch() *Preference {
db := CONTEXT.DB.First(preference) db := CONTEXT.DB.First(preference)
if db.Error != nil { if db.Error != nil {
if db.Error.Error() == result2.DB_ERROR_NOT_FOUND { if db.Error.Error() == result.DB_ERROR_NOT_FOUND {
preference.Name = "蓝眼云盘" preference.Name = "蓝眼云盘"
preference.ShowAlien = true preference.ShowAlien = true
this.Create(preference) this.Create(preference)

View File

@ -9,7 +9,7 @@ import (
"strings" "strings"
"tank/code/config" "tank/code/config"
"tank/code/logger" "tank/code/logger"
result2 "tank/code/tool/result" "tank/code/tool/result"
"tank/code/tool/util" "tank/code/tool/util"
"time" "time"
) )
@ -74,26 +74,26 @@ func (this *Router) GlobalPanicHandler(writer http.ResponseWriter, request *http
logger.LOGGER.Error("错误: %v", err) logger.LOGGER.Error("错误: %v", err)
var webResult *result2.WebResult = nil var webResult *result.WebResult = nil
if value, ok := err.(string); ok { if value, ok := err.(string); ok {
//一个字符串,默认是请求错误。 //一个字符串,默认是请求错误。
webResult = result2.CustomWebResult(result2.CODE_WRAPPER_BAD_REQUEST, value) webResult = result.CustomWebResult(result.CODE_WRAPPER_BAD_REQUEST, value)
} else if value, ok := err.(*result2.WebResult); ok { } else if value, ok := err.(*result.WebResult); ok {
//一个WebResult对象 //一个WebResult对象
webResult = value webResult = value
} else if value, ok := err.(*result2.CodeWrapper); ok { } else if value, ok := err.(*result.CodeWrapper); ok {
//一个WebResult对象 //一个WebResult对象
webResult = result2.ConstWebResult(value) webResult = result.ConstWebResult(value)
} else if value, ok := err.(error); ok { } else if value, ok := err.(error); ok {
//一个普通的错误对象 //一个普通的错误对象
webResult = result2.CustomWebResult(result2.CODE_WRAPPER_UNKNOWN, value.Error()) webResult = result.CustomWebResult(result.CODE_WRAPPER_UNKNOWN, value.Error())
} else { } else {
//其他不能识别的内容 //其他不能识别的内容
webResult = result2.ConstWebResult(result2.CODE_WRAPPER_UNKNOWN) webResult = result.ConstWebResult(result.CODE_WRAPPER_UNKNOWN)
} }
//修改http code码 //修改http code码
writer.WriteHeader(result2.FetchHttpStatus(webResult.Code)) writer.WriteHeader(result.FetchHttpStatus(webResult.Code))
//输出的是json格式 返回的内容申明是jsonutf-8 //输出的是json格式 返回的内容申明是jsonutf-8
writer.Header().Set("Content-Type", "application/json;charset=UTF-8") writer.Header().Set("Content-Type", "application/json;charset=UTF-8")
@ -152,7 +152,7 @@ func (this *Router) ServeHTTP(writer http.ResponseWriter, request *http.Request)
} }
if !canHandle { if !canHandle {
panic(result2.CustomWebResult(result2.CODE_WRAPPER_NOT_FOUND, fmt.Sprintf("没有找到能够处理%s的方法", path))) panic(result.CustomWebResult(result.CODE_WRAPPER_NOT_FOUND, fmt.Sprintf("没有找到能够处理%s的方法", path)))
} }
} }
@ -166,7 +166,7 @@ func (this *Router) ServeHTTP(writer http.ResponseWriter, request *http.Request)
if handler, ok := this.installRouteMap[path]; ok { if handler, ok := this.installRouteMap[path]; ok {
handler(writer, request) handler(writer, request)
} else { } else {
panic(result2.ConstWebResult(result2.CODE_WRAPPER_NOT_INSTALLED)) panic(result.ConstWebResult(result.CODE_WRAPPER_NOT_INSTALLED))
} }
} }

View File

@ -11,7 +11,7 @@ import (
"io" "io"
"net/http" "net/http"
"tank/code/tool/dav/xml" "tank/code/tool/dav/xml"
result2 "tank/code/tool/result" "tank/code/tool/result"
) )
// Proppatch describes a property update instruction as defined in RFC 4918. // Proppatch describes a property update instruction as defined in RFC 4918.
@ -239,20 +239,20 @@ func ReadPropfind(reader io.Reader) (propfind *Propfind) {
err = errInvalidPropfind err = errInvalidPropfind
} }
panic(result2.BadRequest(err.Error())) panic(result.BadRequest(err.Error()))
} }
if propfind.Allprop == nil && propfind.Include != nil { if propfind.Allprop == nil && propfind.Include != nil {
panic(result2.BadRequest(errInvalidPropfind.Error())) panic(result.BadRequest(errInvalidPropfind.Error()))
} }
if propfind.Allprop != nil && (propfind.Prop != nil || propfind.Propname != nil) { if propfind.Allprop != nil && (propfind.Prop != nil || propfind.Propname != nil) {
panic(result2.BadRequest(errInvalidPropfind.Error())) panic(result.BadRequest(errInvalidPropfind.Error()))
} }
if propfind.Prop != nil && propfind.Propname != nil { if propfind.Prop != nil && propfind.Propname != nil {
panic(result2.BadRequest(errInvalidPropfind.Error())) panic(result.BadRequest(errInvalidPropfind.Error()))
} }
if propfind.Propname == nil && propfind.Allprop == nil && propfind.Prop == nil { if propfind.Propname == nil && propfind.Allprop == nil && propfind.Prop == nil {
panic(result2.BadRequest(errInvalidPropfind.Error())) panic(result.BadRequest(errInvalidPropfind.Error()))
} }
return propfind return propfind

View File

@ -9,7 +9,7 @@ import (
"os/user" "os/user"
"path/filepath" "path/filepath"
"strings" "strings"
result2 "tank/code/tool/result" "tank/code/tool/result"
) )
//判断文件或文件夹是否已经存在 //判断文件或文件夹是否已经存在
@ -126,13 +126,13 @@ func GetFilenameOfPath(fullPath string) string {
func DeleteEmptyDir(dirPath string) bool { func DeleteEmptyDir(dirPath string) bool {
dir, err := ioutil.ReadDir(dirPath) dir, err := ioutil.ReadDir(dirPath)
if err != nil { if err != nil {
panic(result2.BadRequest("尝试读取目录%s时出错 %s", dirPath, err.Error())) panic(result.BadRequest("尝试读取目录%s时出错 %s", dirPath, err.Error()))
} }
if len(dir) == 0 { if len(dir) == 0 {
//空文件夹 //空文件夹
err = os.Remove(dirPath) err = os.Remove(dirPath)
if err != nil { if err != nil {
panic(result2.BadRequest("删除磁盘上的文件夹%s出错 %s", dirPath, err.Error())) panic(result.BadRequest("删除磁盘上的文件夹%s出错 %s", dirPath, err.Error()))
} }
return true return true
} }

View File

@ -5,7 +5,7 @@ import (
"regexp" "regexp"
"strconv" "strconv"
"tank/code/config" "tank/code/config"
result2 "tank/code/tool/result" "tank/code/tool/result"
"tank/code/tool/util" "tank/code/tool/util"
"time" "time"
) )
@ -43,25 +43,25 @@ func (this *UserController) RegisterRoutes() map[string]func(writer http.Respons
//参数: //参数:
// @email:邮箱 // @email:邮箱
// @password:密码 // @password:密码
func (this *UserController) Login(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *UserController) Login(writer http.ResponseWriter, request *http.Request) *result.WebResult {
email := request.FormValue("email") email := request.FormValue("email")
password := request.FormValue("password") password := request.FormValue("password")
if "" == email || "" == password { if "" == email || "" == password {
panic(result2.BadRequest("请输入邮箱和密码")) panic(result.BadRequest("请输入邮箱和密码"))
} }
user := this.userDao.FindByEmail(email) user := this.userDao.FindByEmail(email)
if user == nil { if user == nil {
panic(result2.BadRequest("邮箱或密码错误")) panic(result.BadRequest("邮箱或密码错误"))
} else { } else {
if !util.MatchBcrypt(password, user.Password) { if !util.MatchBcrypt(password, user.Password) {
panic(result2.BadRequest("邮箱或密码错误")) panic(result.BadRequest("邮箱或密码错误"))
} }
} }
@ -96,7 +96,7 @@ func (this *UserController) Login(writer http.ResponseWriter, request *http.Requ
} }
//创建一个用户 //创建一个用户
func (this *UserController) Create(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *UserController) Create(writer http.ResponseWriter, request *http.Request) *result.WebResult {
username := request.FormValue("username") username := request.FormValue("username")
if m, _ := regexp.MatchString(`^[0-9a-zA-Z_]+$`, username); !m { if m, _ := regexp.MatchString(`^[0-9a-zA-Z_]+$`, username); !m {
@ -159,7 +159,7 @@ func (this *UserController) Create(writer http.ResponseWriter, request *http.Req
} }
//编辑一个用户的资料。 //编辑一个用户的资料。
func (this *UserController) Edit(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *UserController) Edit(writer http.ResponseWriter, request *http.Request) *result.WebResult {
avatarUrl := request.FormValue("avatarUrl") avatarUrl := request.FormValue("avatarUrl")
uuid := request.FormValue("uuid") uuid := request.FormValue("uuid")
@ -187,7 +187,7 @@ func (this *UserController) Edit(writer http.ResponseWriter, request *http.Reque
user.SizeLimit = sizeLimit user.SizeLimit = sizeLimit
} else { } else {
if currentUser.Uuid != uuid { if currentUser.Uuid != uuid {
panic(result2.Unauthorized("没有权限")) panic(result.Unauthorized("没有权限"))
} }
} }
@ -202,7 +202,7 @@ func (this *UserController) Edit(writer http.ResponseWriter, request *http.Reque
} }
//获取用户详情 //获取用户详情
func (this *UserController) Detail(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *UserController) Detail(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid") uuid := request.FormValue("uuid")
@ -213,7 +213,7 @@ func (this *UserController) Detail(writer http.ResponseWriter, request *http.Req
} }
//退出登录 //退出登录
func (this *UserController) Logout(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *UserController) Logout(writer http.ResponseWriter, request *http.Request) *result.WebResult {
//session置为过期 //session置为过期
sessionCookie, err := request.Cookie(config.COOKIE_AUTH_KEY) sessionCookie, err := request.Cookie(config.COOKIE_AUTH_KEY)
@ -249,7 +249,7 @@ func (this *UserController) Logout(writer http.ResponseWriter, request *http.Req
} }
//获取用户列表 管理员的权限。 //获取用户列表 管理员的权限。
func (this *UserController) Page(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *UserController) Page(writer http.ResponseWriter, request *http.Request) *result.WebResult {
pageStr := request.FormValue("page") pageStr := request.FormValue("page")
pageSizeStr := request.FormValue("pageSize") pageSizeStr := request.FormValue("pageSize")
@ -301,7 +301,7 @@ func (this *UserController) Page(writer http.ResponseWriter, request *http.Reque
} }
//禁用用户 //禁用用户
func (this *UserController) Disable(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *UserController) Disable(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid") uuid := request.FormValue("uuid")
@ -309,11 +309,11 @@ func (this *UserController) Disable(writer http.ResponseWriter, request *http.Re
loginUser := this.checkUser(writer, request) loginUser := this.checkUser(writer, request)
if uuid == loginUser.Uuid { if uuid == loginUser.Uuid {
panic(result2.BadRequest("你不能操作自己的状态。")) panic(result.BadRequest("你不能操作自己的状态。"))
} }
if user.Status == USER_STATUS_DISABLED { if user.Status == USER_STATUS_DISABLED {
panic(result2.BadRequest("用户已经被禁用,操作无效。")) panic(result.BadRequest("用户已经被禁用,操作无效。"))
} }
user.Status = USER_STATUS_DISABLED user.Status = USER_STATUS_DISABLED
@ -325,18 +325,18 @@ func (this *UserController) Disable(writer http.ResponseWriter, request *http.Re
} }
//启用用户 //启用用户
func (this *UserController) Enable(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *UserController) Enable(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid") uuid := request.FormValue("uuid")
user := this.userDao.CheckByUuid(uuid) user := this.userDao.CheckByUuid(uuid)
loginUser := this.checkUser(writer, request) loginUser := this.checkUser(writer, request)
if uuid == loginUser.Uuid { if uuid == loginUser.Uuid {
panic(result2.BadRequest("你不能操作自己的状态。")) panic(result.BadRequest("你不能操作自己的状态。"))
} }
if user.Status == USER_STATUS_OK { if user.Status == USER_STATUS_OK {
panic(result2.BadRequest("用户已经是正常状态,操作无效。")) panic(result.BadRequest("用户已经是正常状态,操作无效。"))
} }
user.Status = USER_STATUS_OK user.Status = USER_STATUS_OK
@ -348,12 +348,12 @@ func (this *UserController) Enable(writer http.ResponseWriter, request *http.Req
} }
//用户修改密码 //用户修改密码
func (this *UserController) ChangePassword(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *UserController) ChangePassword(writer http.ResponseWriter, request *http.Request) *result.WebResult {
oldPassword := request.FormValue("oldPassword") oldPassword := request.FormValue("oldPassword")
newPassword := request.FormValue("newPassword") newPassword := request.FormValue("newPassword")
if oldPassword == "" || newPassword == "" { if oldPassword == "" || newPassword == "" {
panic(result2.BadRequest("旧密码和新密码都不能为空")) panic(result.BadRequest("旧密码和新密码都不能为空"))
} }
user := this.checkUser(writer, request) user := this.checkUser(writer, request)
@ -364,7 +364,7 @@ func (this *UserController) ChangePassword(writer http.ResponseWriter, request *
} }
if !util.MatchBcrypt(oldPassword, user.Password) { if !util.MatchBcrypt(oldPassword, user.Password) {
panic(result2.BadRequest("旧密码不正确!")) panic(result.BadRequest("旧密码不正确!"))
} }
user.Password = util.GetBcrypt(newPassword) user.Password = util.GetBcrypt(newPassword)
@ -375,21 +375,21 @@ func (this *UserController) ChangePassword(writer http.ResponseWriter, request *
} }
//管理员重置用户密码 //管理员重置用户密码
func (this *UserController) ResetPassword(writer http.ResponseWriter, request *http.Request) *result2.WebResult { func (this *UserController) ResetPassword(writer http.ResponseWriter, request *http.Request) *result.WebResult {
userUuid := request.FormValue("userUuid") userUuid := request.FormValue("userUuid")
password := request.FormValue("password") password := request.FormValue("password")
if userUuid == "" { if userUuid == "" {
panic(result2.BadRequest("用户不能为空")) panic(result.BadRequest("用户不能为空"))
} }
if password == "" { if password == "" {
panic(result2.BadRequest("密码不能为空")) panic(result.BadRequest("密码不能为空"))
} }
currentUser := this.checkUser(writer, request) currentUser := this.checkUser(writer, request)
if currentUser.Role != USER_ROLE_ADMINISTRATOR { if currentUser.Role != USER_ROLE_ADMINISTRATOR {
panic(result2.Unauthorized("没有权限")) panic(result.Unauthorized("没有权限"))
} }
user := this.userDao.CheckByUuid(userUuid) user := this.userDao.CheckByUuid(userUuid)

View File

@ -4,7 +4,7 @@ import (
"net/http" "net/http"
"tank/code/config" "tank/code/config"
cache2 "tank/code/tool/cache" cache2 "tank/code/tool/cache"
result2 "tank/code/tool/result" "tank/code/tool/result"
"time" "time"
) )
@ -50,7 +50,7 @@ func (this *UserService) MatterLock(userUuid string) {
//当前被锁住了。 //当前被锁住了。
if cacheItem != nil && cacheItem.Data() != nil { if cacheItem != nil && cacheItem.Data() != nil {
panic(result2.BadRequest("当前正在进行文件操作,请稍后再试!")) panic(result.BadRequest("当前正在进行文件操作,请稍后再试!"))
} }
//添加一把新锁有效期为12小时 //添加一把新锁有效期为12小时