Compatible with revel 0.18
This commit is contained in:
@ -46,14 +46,17 @@ func (c Attach) uploadAttach(noteId string) (re info.Re) {
|
||||
return re
|
||||
}
|
||||
|
||||
file, handel, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
return re
|
||||
}
|
||||
defer file.Close()
|
||||
var data []byte
|
||||
c.Params.Bind(&data, "file")
|
||||
|
||||
data, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
// file, handel, err := c.Request.FormFile("file")
|
||||
// if err != nil {
|
||||
// return re
|
||||
// }
|
||||
// defer file.Close()
|
||||
|
||||
// data, err := ioutil.ReadAll(file)
|
||||
if data == nil || len(data) == 0 {
|
||||
return re
|
||||
}
|
||||
// > 5M?
|
||||
@ -71,10 +74,13 @@ func (c Attach) uploadAttach(noteId string) (re info.Re) {
|
||||
newGuid := NewGuid()
|
||||
filePath := "files/" + GetRandomFilePath(c.GetUserId(), newGuid) + "/attachs"
|
||||
dir := revel.BasePath + "/" + filePath
|
||||
err = os.MkdirAll(dir, 0755)
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
if err != nil {
|
||||
return re
|
||||
}
|
||||
|
||||
handel := c.Params.Files["file"][0]
|
||||
|
||||
// 生成新的文件名
|
||||
filename := handel.Filename
|
||||
_, ext := SplitFilename(filename) // .doc
|
||||
|
@ -77,7 +77,7 @@ func (c Blog) e404(themePath string) revel.Result {
|
||||
// life.leanote.com
|
||||
// lealife.com
|
||||
func (c Blog) domain() (ok bool, userBlog info.UserBlog) {
|
||||
host := c.Request.Request.Host // a.cc.com:9000
|
||||
host := c.Request.Host // a.cc.com:9000
|
||||
hostArr := strings.Split(host, ".")
|
||||
if strings.Contains(host, configService.GetDefaultDomain()) {
|
||||
// 有二级域名 a.leanoe.com 3个
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
// "path"
|
||||
// "strconv"
|
||||
"net/http"
|
||||
"io"
|
||||
)
|
||||
|
||||
// 验证码服务
|
||||
@ -30,7 +31,8 @@ func (r Ca) Apply(req *revel.Request, resp *revel.Response) {
|
||||
func (c Captcha) Get() revel.Result {
|
||||
c.Response.ContentType = "image/png"
|
||||
image, str := captcha.Fetch()
|
||||
image.WriteTo(c.Response.Out)
|
||||
out := io.Writer(c.Response.GetWriter())
|
||||
image.WriteTo(out)
|
||||
|
||||
sessionId := c.Session["_ID"]
|
||||
// LogJ(c.Session)
|
||||
|
@ -97,11 +97,27 @@ func (c File) uploadImage(from, albumId string) (re info.Re) {
|
||||
re.Ok = Ok
|
||||
}()
|
||||
|
||||
file, handel, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
// file, handel, err := c.Request.FormFile("file")
|
||||
// if err != nil {
|
||||
// return re
|
||||
// }
|
||||
// defer file.Close()
|
||||
|
||||
var data []byte
|
||||
c.Params.Bind(&data, "file")
|
||||
handel := c.Params.Files["file"][0]
|
||||
if data == nil || len(data) == 0 {
|
||||
return re
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// file, handel, err := c.Request.FormFile("file")
|
||||
// if err != nil {
|
||||
// return re
|
||||
// }
|
||||
// defer file.Close()
|
||||
|
||||
// data, err := ioutil.ReadAll(file)
|
||||
|
||||
|
||||
// 生成上传路径
|
||||
newGuid := NewGuid()
|
||||
@ -116,7 +132,7 @@ func (c File) uploadImage(from, albumId string) (re info.Re) {
|
||||
}
|
||||
|
||||
dir := revel.BasePath + "/" + fileUrlPath
|
||||
err = os.MkdirAll(dir, 0755)
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
if err != nil {
|
||||
return re
|
||||
}
|
||||
@ -136,11 +152,11 @@ func (c File) uploadImage(from, albumId string) (re info.Re) {
|
||||
}
|
||||
|
||||
filename = newGuid + ext
|
||||
data, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
LogJ(err)
|
||||
return re
|
||||
}
|
||||
// data, err := ioutil.ReadAll(file)
|
||||
// if err != nil {
|
||||
// LogJ(err)
|
||||
// return re
|
||||
// }
|
||||
|
||||
var maxFileSize float64
|
||||
if from == "logo" {
|
||||
|
@ -53,16 +53,23 @@ func (c ApiBaseContrller) uploadAttach(name string, noteId string) (ok bool, msg
|
||||
}
|
||||
*/
|
||||
|
||||
file, handel, err := c.Request.FormFile(name)
|
||||
if err != nil {
|
||||
var data []byte
|
||||
c.Params.Bind(&data, name)
|
||||
handel := c.Params.Files[name][0]
|
||||
if data == nil || len(data) == 0 {
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
data, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// file, handel, err := c.Request.FormFile(name)
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// defer file.Close()
|
||||
|
||||
// data, err := ioutil.ReadAll(file)
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// > 5M?
|
||||
maxFileSize := configService.GetUploadSize("uploadAttachSize")
|
||||
if maxFileSize <= 0 {
|
||||
@ -79,7 +86,7 @@ func (c ApiBaseContrller) uploadAttach(name string, noteId string) (ok bool, msg
|
||||
filePath := "files/" + GetRandomFilePath(userId, newGuid) + "/attachs"
|
||||
|
||||
dir := revel.BasePath + "/" + filePath
|
||||
err = os.MkdirAll(dir, 0755)
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -122,11 +129,18 @@ func (c ApiBaseContrller) upload(name string, noteId string, isAttach bool) (ok
|
||||
if isAttach {
|
||||
return c.uploadAttach(name, noteId)
|
||||
}
|
||||
file, handel, err := c.Request.FormFile(name)
|
||||
if err != nil {
|
||||
// file, handel, err := c.Request.FormFile(name)
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// defer file.Close()
|
||||
|
||||
var data []byte
|
||||
c.Params.Bind(&data, name)
|
||||
handel := c.Params.Files[name][0]
|
||||
if data == nil || len(data) == 0 {
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
newGuid := NewGuid()
|
||||
// 生成上传路径
|
||||
@ -135,7 +149,7 @@ func (c ApiBaseContrller) upload(name string, noteId string, isAttach bool) (ok
|
||||
fileUrlPath := "files/" + GetRandomFilePath(userId, newGuid) + "/images"
|
||||
|
||||
dir := revel.BasePath + "/" + fileUrlPath
|
||||
err = os.MkdirAll(dir, 0755)
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -148,10 +162,10 @@ func (c ApiBaseContrller) upload(name string, noteId string, isAttach bool) (ok
|
||||
// }
|
||||
|
||||
filename = newGuid + ext
|
||||
data, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// data, err := ioutil.ReadAll(file)
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
|
||||
maxFileSize := configService.GetUploadSize("uploadImageSize")
|
||||
if maxFileSize <= 0 {
|
||||
|
@ -104,16 +104,23 @@ func (c ApiUser) uploadImage() (ok bool, msg, url string) {
|
||||
var fileUrlPath = ""
|
||||
ok = false
|
||||
|
||||
file, handel, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
var data []byte
|
||||
c.Params.Bind(&data, "file")
|
||||
handel := c.Params.Files["file"][0]
|
||||
if data == nil || len(data) == 0 {
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// file, handel, err := c.Request.FormFile("file")
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// defer file.Close()
|
||||
// 生成上传路径
|
||||
fileUrlPath = "public/upload/" + c.getUserId() + "/images/logo"
|
||||
|
||||
dir := revel.BasePath + "/" + fileUrlPath
|
||||
err = os.MkdirAll(dir, 0755)
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -129,11 +136,11 @@ func (c ApiUser) uploadImage() (ok bool, msg, url string) {
|
||||
}
|
||||
|
||||
filename = NewGuid() + ext
|
||||
data, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
LogJ(err)
|
||||
return
|
||||
}
|
||||
// data, err := ioutil.ReadAll(file)
|
||||
// if err != nil {
|
||||
// LogJ(err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// > 5M?
|
||||
if len(data) > 5*1024*1024 {
|
||||
|
@ -351,14 +351,21 @@ func (c MemberBlog) uploadImage(themeId string) (re info.Re) {
|
||||
re.Ok = Ok
|
||||
}()
|
||||
|
||||
file, handel, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
var data []byte
|
||||
c.Params.Bind(&data, "file")
|
||||
handel := c.Params.Files["file"][0]
|
||||
if data == nil || len(data) == 0 {
|
||||
return re
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// file, handel, err := c.Request.FormFile("file")
|
||||
// if err != nil {
|
||||
// return re
|
||||
// }
|
||||
// defer file.Close()
|
||||
// 生成上传路径
|
||||
dir := themeService.GetThemeAbsolutePath(c.GetUserId(), themeId) + "/images"
|
||||
err = os.MkdirAll(dir, 0755)
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
if err != nil {
|
||||
return re
|
||||
}
|
||||
@ -374,11 +381,11 @@ func (c MemberBlog) uploadImage(themeId string) (re info.Re) {
|
||||
}
|
||||
|
||||
filename = filename
|
||||
data, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
LogJ(err)
|
||||
return re
|
||||
}
|
||||
// data, err := ioutil.ReadAll(file)
|
||||
// if err != nil {
|
||||
// LogJ(err)
|
||||
// return re
|
||||
// }
|
||||
|
||||
// > 2M?
|
||||
if len(data) > 5*1024*1024 {
|
||||
@ -441,17 +448,24 @@ func (c MemberBlog) ExportTheme(themeId string) revel.Result {
|
||||
func (c MemberBlog) ImportTheme() revel.Result {
|
||||
re := info.NewRe()
|
||||
|
||||
file, handel, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
re.Msg = fmt.Sprintf("%v", err)
|
||||
var data []byte
|
||||
c.Params.Bind(&data, "file")
|
||||
handel := c.Params.Files["file"][0]
|
||||
if data == nil || len(data) == 0 {
|
||||
return c.RenderJSON(re)
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
// file, handel, err := c.Request.FormFile("file")
|
||||
// if err != nil {
|
||||
// re.Msg = fmt.Sprintf("%v", err)
|
||||
// return c.RenderJSON(re)
|
||||
// }
|
||||
|
||||
// defer file.Close()
|
||||
// 生成上传路径
|
||||
userId := c.GetUserId()
|
||||
dir := revel.BasePath + "/public/upload/" + userId + "/tmp"
|
||||
err = os.MkdirAll(dir, 0755)
|
||||
err := os.MkdirAll(dir, 0755)
|
||||
if err != nil {
|
||||
re.Msg = fmt.Sprintf("%v", err)
|
||||
return c.RenderJSON(re)
|
||||
@ -467,10 +481,10 @@ func (c MemberBlog) ImportTheme() revel.Result {
|
||||
}
|
||||
|
||||
filename = filename
|
||||
data, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
return c.RenderJSON(re)
|
||||
}
|
||||
// data, err := ioutil.ReadAll(file)
|
||||
// if err != nil {
|
||||
// return c.RenderJSON(re)
|
||||
// }
|
||||
|
||||
// > 10M?
|
||||
if len(data) > 10*1024*1024 {
|
||||
|
@ -104,7 +104,7 @@ func (r *RenderTemplateResult) Apply(req *revel.Request, resp *revel.Response) {
|
||||
chunked := revel.Config.BoolDefault("results.chunked", false)
|
||||
|
||||
// If it's a HEAD request, throw away the bytes.
|
||||
out := io.Writer(resp.Out)
|
||||
out := io.Writer(resp.GetWriter())
|
||||
if req.Method == "HEAD" {
|
||||
out = ioutil.Discard
|
||||
}
|
||||
@ -289,7 +289,7 @@ func (r ErrorResult) Apply(req *revel.Request, resp *revel.Response) {
|
||||
// 不是preview就不要显示错误了
|
||||
if r.IsPreview {
|
||||
var b bytes.Buffer
|
||||
out := io.Writer(resp.Out)
|
||||
out := io.Writer(resp.GetWriter())
|
||||
// out = ioutil.Discard
|
||||
err = tmpl.Execute(&b, r.ViewArgs)
|
||||
resp.WriteHeader(http.StatusOK, "text/html; charset=utf-8")
|
||||
|
@ -210,10 +210,10 @@ func hasAcceptLanguageHeader(request *revel.Request) (bool, string) {
|
||||
|
||||
// Determine whether the given request has a valid language cookie value.
|
||||
func hasLocaleCookie(request *revel.Request) (bool, string) {
|
||||
if request != nil && request.Cookies() != nil {
|
||||
if request != nil {
|
||||
name := revel.Config.StringDefault(localeCookieConfigKey, revel.CookiePrefix+"_LANG")
|
||||
if cookie, error := request.Cookie(name); error == nil {
|
||||
return true, cookie.Value
|
||||
return true, cookie.GetValue()
|
||||
} else {
|
||||
revel.TRACE.Printf("Unable to read locale cookie with name '%s': %s", name, error.Error())
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package route
|
||||
import (
|
||||
"github.com/leanote/leanote/app/db"
|
||||
"github.com/revel/revel"
|
||||
// . "github.com/leanote/leanote/app/lea"
|
||||
. "github.com/leanote/leanote/app/lea"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
@ -14,15 +14,19 @@ var staticPrefix = []string{"/public", "/favicon.ico", "/css", "/js", "/images",
|
||||
|
||||
func RouterFilter(c *revel.Controller, fc []revel.Filter) {
|
||||
// 补全controller部分
|
||||
path := c.Request.Request.URL.Path
|
||||
path := c.Request.URL.Path
|
||||
|
||||
// Figure out the Controller/Action
|
||||
var route *revel.RouteMatch = revel.MainRouter.Route(c.Request.Request)
|
||||
// var route *revel.RouteMatch = revel.MainRouter.Route(c.Request.Request)
|
||||
route := revel.MainRouter.Route(c.Request)
|
||||
|
||||
if route == nil {
|
||||
c.Result = c.NotFound("No matching route found: " + c.Request.RequestURI)
|
||||
c.Result = c.NotFound("No matching route found: " + c.Request.GetRequestURI())
|
||||
return
|
||||
}
|
||||
|
||||
Log("---------" + route.Action + " " + path)
|
||||
|
||||
// The route may want to explicitly return a 404.
|
||||
if route.Action == "404" {
|
||||
c.Result = c.NotFound("(intentionally)")
|
||||
@ -47,14 +51,23 @@ func RouterFilter(c *revel.Controller, fc []revel.Filter) {
|
||||
// 检查mongodb 是否lost
|
||||
db.CheckMongoSessionLost()
|
||||
|
||||
// /api/file/getImage -> App\file (/api/file/getImage)
|
||||
// App\auth
|
||||
// App\note
|
||||
// static\static
|
||||
//
|
||||
// Log("---------" + route.ControllerName + " " + path)
|
||||
|
||||
// api设置
|
||||
// leanote.com/api/user/get => ApiUser::Get
|
||||
//* /api/login ApiAuth.Login, 这里的设置, 其实已经转成了ApiAuth了
|
||||
if strings.HasPrefix(path, "/api") && !strings.HasPrefix(route.ControllerName, "Api") {
|
||||
route.ControllerName = "Api" + route.ControllerName
|
||||
} else if strings.HasPrefix(path, "/member") && !strings.HasPrefix(route.ControllerName, "Member") {
|
||||
if strings.HasPrefix(path, "/api") && !strings.HasPrefix(route.ControllerName, "App\\api") {
|
||||
route.ControllerName = "App\\api" + strings.Split(route.ControllerName, "\\")[1]
|
||||
// route.ControllerName = "App\\apifile"
|
||||
} else if strings.HasPrefix(path, "/member") && !strings.HasPrefix(route.ControllerName, "App\\member") {
|
||||
// member设置
|
||||
route.ControllerName = "Member" + route.ControllerName
|
||||
// route.ControllerName = "App\\Member" + route.ControllerName
|
||||
route.ControllerName = "App\\member" + strings.Split(route.ControllerName, "\\")[1]
|
||||
}
|
||||
// end
|
||||
}
|
||||
|
@ -128,6 +128,12 @@ GET /upload/*filepath Static.Serve("public/upload")
|
||||
# the prefix of member's controllername is "Member"
|
||||
* /member MemberIndex.Index
|
||||
* /member/index MemberIndex.Index
|
||||
* /member/group/index MemberGroup.Index
|
||||
* /member/group/addGroup MemberGroup.AddGroup
|
||||
* /member/group/updateGroupTitle MemberGroup.UpdateGroupTitle
|
||||
* /member/group/deleteGroup MemberGroup.DeleteGroup
|
||||
* /member/group/addUser MemberGroup.AddUser
|
||||
* /member/group/deleteUser MemberGroup.DeleteUser
|
||||
|
||||
# common
|
||||
* /:controller/:action :controller.:action
|
||||
|
Reference in New Issue
Block a user