fmt all go file

This commit is contained in:
lealife
2015-11-13 17:58:41 +08:00
parent cba69444a8
commit 7809d00787
100 changed files with 3375 additions and 3331 deletions

View File

@ -2,15 +2,15 @@ package controllers
import (
"github.com/revel/revel"
// "encoding/json"
"gopkg.in/mgo.v2/bson"
// "encoding/json"
"fmt"
"github.com/leanote/leanote/app/info"
. "github.com/leanote/leanote/app/lea"
"github.com/leanote/leanote/app/lea/netutil"
"github.com/leanote/leanote/app/info"
"gopkg.in/mgo.v2/bson"
"io/ioutil"
"os"
"fmt"
// "strconv"
// "strconv"
"strings"
)
@ -22,8 +22,8 @@ type File struct {
// 上传的是博客logo
// TODO logo不要设置权限, 另外的目录
func (c File) UploadBlogLogo() revel.Result {
re := c.uploadImage("blogLogo", "");
re := c.uploadImage("blogLogo", "")
c.RenderArgs["fileUrlPath"] = re.Id
c.RenderArgs["resultCode"] = re.Code
c.RenderArgs["resultMsg"] = re.Msg
@ -34,8 +34,8 @@ func (c File) UploadBlogLogo() revel.Result {
// 拖拉上传, pasteImage
// noteId 是为了判断是否是协作的note, 如果是则需要复制一份到note owner中
func (c File) PasteImage(noteId string) revel.Result {
re := c.uploadImage("pasteImage", "");
re := c.uploadImage("pasteImage", "")
userId := c.GetUserId()
note := noteService.GetNoteById(noteId)
if note.UserId != "" {
@ -44,29 +44,29 @@ func (c File) PasteImage(noteId string) revel.Result {
// 是否是有权限协作的
if shareService.HasUpdatePerm(noteUserId, userId, noteId) {
// 复制图片之, 图片复制给noteUserId
_, re.Id = fileService.CopyImage(userId, re.Id, noteUserId)
_, re.Id = fileService.CopyImage(userId, re.Id, noteUserId)
} else {
// 怎么可能在这个笔记下paste图片呢?
// 正常情况下不会
}
}
}
return c.RenderJson(re)
}
// 头像设置
func (c File) UploadAvatar() revel.Result {
re := c.uploadImage("logo", "");
re := c.uploadImage("logo", "")
c.RenderArgs["fileUrlPath"] = re.Id
c.RenderArgs["resultCode"] = re.Code
c.RenderArgs["resultMsg"] = re.Msg
if re.Ok {
re.Ok = userService.UpdateAvatar(c.GetUserId(), re.Id)
if re.Ok {
c.UpdateSession("Logo", re.Id);
c.UpdateSession("Logo", re.Id)
}
}
@ -100,13 +100,13 @@ func (c File) uploadImage(from, albumId string) (re info.Re) {
return re
}
defer file.Close()
// 生成上传路径
newGuid := NewGuid()
userId := c.GetUserId()
if(from == "logo" || from == "blogLogo") {
if from == "logo" || from == "blogLogo" {
fileUrlPath = "public/upload/" + Digest3(userId) + "/" + userId + "/images/logo"
} else {
fileUrlPath = "files/" + Digest3(userId) + "/" + userId + "/" + Digest2(newGuid) + "/images"
@ -180,8 +180,8 @@ func (c File) uploadImage(from, albumId string) (re info.Re) {
id := bson.NewObjectId()
fileInfo.FileId = id
fileId = id.Hex()
if(from == "logo" || from == "blogLogo") {
if from == "logo" || from == "blogLogo" {
fileId = fileUrlPath
}
@ -217,13 +217,13 @@ func (c File) DeleteImage(fileId string) revel.Result {
// 输出image
// 权限判断
func (c File) OutputImage(noteId, fileId string) revel.Result {
path := fileService.GetFile(c.GetUserId(), fileId); // 得到路径
path := fileService.GetFile(c.GetUserId(), fileId) // 得到路径
if path == "" {
return c.RenderText("")
}
fn := revel.BasePath + "/" + strings.TrimLeft(path, "/")
file, _ := os.Open(fn)
return c.RenderFile(file, revel.Inline) // revel.Attachment
fn := revel.BasePath + "/" + strings.TrimLeft(path, "/")
file, _ := os.Open(fn)
return c.RenderFile(file, revel.Inline) // revel.Attachment
}
// 协作时复制图片到owner
@ -265,7 +265,7 @@ func (c File) CopyHttpImage(src string) revel.Result {
fileInfo.FileId = id
re.Id = id.Hex()
// re.Item = fileInfo.Path
// re.Item = fileInfo.Path
re.Ok, re.Msg = fileService.AddImage(fileInfo, "", c.GetUserId(), true)
return c.RenderJson(re)