实现分享开关

pull/244/head
Minho 2018-03-13 19:20:50 +08:00
parent c278b72f15
commit 08e86e0f41
15 changed files with 162 additions and 134 deletions

View File

@ -168,11 +168,11 @@ func RegisterFunction() {
return cdn + p return cdn + p
}) })
beego.AddFuncMap("cdnjs",utils.URLForWithCdnJs) beego.AddFuncMap("cdnjs",conf.URLForWithCdnJs)
beego.AddFuncMap("cdncss",utils.URLForWithCdnCss) beego.AddFuncMap("cdncss",conf.URLForWithCdnCss)
beego.AddFuncMap("cdnimg", utils.URLForWithCdnImage) beego.AddFuncMap("cdnimg", conf.URLForWithCdnImage)
//重写url生成支持配置域名以及域名前缀 //重写url生成支持配置域名以及域名前缀
beego.AddFuncMap("urlfor", utils.URLFor) beego.AddFuncMap("urlfor", conf.URLFor)
} }
//解析命令 //解析命令

View File

@ -151,3 +151,107 @@ func IsAllowUploadFileExt(ext string) bool {
} }
return false return false
} }
//重写生成URL的方法加上完整的域名
func URLFor(endpoint string, values ...interface{}) string {
baseUrl := beego.AppConfig.DefaultString("baseurl","")
pathUrl := beego.URLFor(endpoint, values ...)
if baseUrl == "" {
baseUrl = BaseUrl
}
if strings.HasPrefix(pathUrl,"http://") {
return pathUrl
}
if strings.HasPrefix(pathUrl,"/") && strings.HasSuffix(baseUrl,"/") {
return baseUrl + pathUrl[1:]
}
if !strings.HasPrefix(pathUrl,"/") && !strings.HasSuffix(baseUrl,"/") {
return baseUrl + "/" + pathUrl
}
return baseUrl + beego.URLFor(endpoint, values ...)
}
func URLForWithCdnImage(p string) string {
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
return p
}
cdn := beego.AppConfig.DefaultString("cdnimg", "")
//如果没有设置cdn则使用baseURL拼接
if cdn == "" {
baseUrl := beego.AppConfig.DefaultString("baseurl","")
if baseUrl == "" {
baseUrl = BaseUrl
}
if strings.HasPrefix(p,"/") && strings.HasSuffix(baseUrl,"/") {
return baseUrl + p[1:]
}
if !strings.HasPrefix(p,"/") && !strings.HasSuffix(baseUrl,"/") {
return baseUrl + "/" + p
}
return baseUrl + p
}
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
return cdn + string(p[1:])
}
if !strings.HasPrefix(p, "/") && !strings.HasSuffix(cdn, "/") {
return cdn + "/" + p
}
return cdn + p
}
func URLForWithCdnCss (p string) string {
cdn := beego.AppConfig.DefaultString("cdncss", "")
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
return p
}
//如果没有设置cdn则使用baseURL拼接
if cdn == "" {
baseUrl := beego.AppConfig.DefaultString("baseurl","")
if baseUrl == "" {
baseUrl = BaseUrl
}
if strings.HasPrefix(p,"/") && strings.HasSuffix(baseUrl,"/") {
return baseUrl + p[1:]
}
if !strings.HasPrefix(p,"/") && !strings.HasSuffix(baseUrl,"/") {
return baseUrl + "/" + p
}
return baseUrl + p
}
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
return cdn + string(p[1:])
}
if !strings.HasPrefix(p, "/") && !strings.HasSuffix(cdn, "/") {
return cdn + "/" + p
}
return cdn + p
}
func URLForWithCdnJs(p string) string {
cdn := beego.AppConfig.DefaultString("cdnjs", "")
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
return p
}
//如果没有设置cdn则使用baseURL拼接
if cdn == "" {
baseUrl := beego.AppConfig.DefaultString("baseurl","")
if baseUrl == "" {
baseUrl = BaseUrl
}
if strings.HasPrefix(p,"/") && strings.HasSuffix(baseUrl,"/") {
return baseUrl + p[1:]
}
if !strings.HasPrefix(p,"/") && !strings.HasSuffix(baseUrl,"/") {
return baseUrl + "/" + p
}
return baseUrl + p
}
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
return cdn + string(p[1:])
}
if !strings.HasPrefix(p, "/") && !strings.HasSuffix(cdn, "/") {
return cdn + "/" + p
}
return cdn + p
}

View File

@ -32,7 +32,7 @@ func (c *AccountController) Login() {
u = c.Ctx.Request.Header.Get("Referer") u = c.Ctx.Request.Header.Get("Referer")
} }
if u == "" { if u == "" {
u = utils.URLFor("HomeController.Index") u = conf.URLFor("HomeController.Index")
} }
c.Redirect(u,302) c.Redirect(u,302)
} }
@ -83,7 +83,7 @@ func (c *AccountController) Login() {
u = c.Ctx.Request.Header.Get("Referer") u = c.Ctx.Request.Header.Get("Referer")
} }
if u == "" { if u == "" {
u = utils.URLFor("HomeController.Index") u = conf.URLFor("HomeController.Index")
} }
c.JsonResult(0, "ok", u) c.JsonResult(0, "ok", u)
@ -97,7 +97,7 @@ func (c *AccountController) Login() {
u = c.Ctx.Request.Header.Get("Referer") u = c.Ctx.Request.Header.Get("Referer")
} }
if u == "" { if u == "" {
u = utils.URLFor("HomeController.Index") u = conf.URLFor("HomeController.Index")
} }
c.Data["url"] = url.PathEscape(u) c.Data["url"] = url.PathEscape(u)
} }
@ -111,7 +111,7 @@ func (c *AccountController) LoggedIn(isPost bool) interface{} {
if !isPost { if !isPost {
// 检查是否存在 turl 参数,如果有则重定向至 turl 处,否则进入 Home 页面 // 检查是否存在 turl 参数,如果有则重定向至 turl 处,否则进入 Home 页面
if turl == "" { if turl == "" {
turl = utils.URLFor("HomeController.Index") turl = conf.URLFor("HomeController.Index")
} }
c.Redirect(turl, 302) c.Redirect(turl, 302)
return nil return nil
@ -130,7 +130,7 @@ func (c *AccountController) Register() {
//如果用户登录了,则跳转到网站首页 //如果用户登录了,则跳转到网站首页
if member, ok := c.GetSession(conf.LoginSessionName).(models.Member); ok && member.MemberId > 0 { if member, ok := c.GetSession(conf.LoginSessionName).(models.Member); ok && member.MemberId > 0 {
c.Redirect(utils.URLFor("HomeController.Index"),302) c.Redirect(conf.URLFor("HomeController.Index"),302)
} }
// 如果没有开启用户注册 // 如果没有开启用户注册
if v, ok := c.Option["ENABLED_REGISTER"]; ok && !strings.EqualFold(v, "true") { if v, ok := c.Option["ENABLED_REGISTER"]; ok && !strings.EqualFold(v, "true") {
@ -244,7 +244,7 @@ func (c *AccountController) FindPassword() {
data := map[string]interface{}{ data := map[string]interface{}{
"SITE_NAME": c.Option["SITE_NAME"], "SITE_NAME": c.Option["SITE_NAME"],
"url": utils.URLFor("AccountController.FindPassword", "token", member_token.Token, "mail", email), "url": conf.URLFor("AccountController.FindPassword", "token", member_token.Token, "mail", email),
"BaseUrl": c.BaseUrl(), "BaseUrl": c.BaseUrl(),
} }
@ -302,7 +302,7 @@ func (c *AccountController) FindPassword() {
//} //}
}(mail_conf, email, body) }(mail_conf, email, body)
c.JsonResult(0, "ok", utils.URLFor("AccountController.Login")) c.JsonResult(0, "ok", conf.URLFor("AccountController.Login"))
} }
token := c.GetString("token") token := c.GetString("token")
@ -396,7 +396,7 @@ func (c *AccountController) ValidEmail() {
beego.Error(err) beego.Error(err)
c.JsonResult(6006, "保存密码失败") c.JsonResult(6006, "保存密码失败")
} }
c.JsonResult(0, "ok", utils.URLFor("AccountController.Login")) c.JsonResult(0, "ok", conf.URLFor("AccountController.Login"))
} }
// Logout 退出登录 // Logout 退出登录
@ -407,7 +407,7 @@ func (c *AccountController) Logout() {
u := c.Ctx.Request.Header.Get("Referer") u := c.Ctx.Request.Header.Get("Referer")
c.Redirect(utils.URLFor("AccountController.Login","url",u), 302) c.Redirect(conf.URLFor("AccountController.Login","url",u), 302)
} }
// 验证码 // 验证码

View File

@ -111,7 +111,7 @@ func (c *BookController) Setting() {
c.Abort("403") c.Abort("403")
} }
if book.PrivateToken != "" { if book.PrivateToken != "" {
book.PrivateToken = utils.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken) book.PrivateToken = conf.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken)
} }
c.Data["Model"] = book c.Data["Model"] = book
@ -140,6 +140,7 @@ func (c *BookController) SaveBook() {
publisher := strings.TrimSpace(c.GetString("publisher")) publisher := strings.TrimSpace(c.GetString("publisher"))
historyCount,_ := c.GetInt("history_count",0) historyCount,_ := c.GetInt("history_count",0)
isDownload := strings.TrimSpace(c.GetString("is_download")) == "on" isDownload := strings.TrimSpace(c.GetString("is_download")) == "on"
enableShare := strings.TrimSpace(c.GetString("enable_share")) == "on"
if strings.Count(description, "") > 500 { if strings.Count(description, "") > 500 {
c.JsonResult(6004, "项目描述不能大于500字") c.JsonResult(6004, "项目描述不能大于500字")
@ -176,6 +177,11 @@ func (c *BookController) SaveBook() {
}else{ }else{
book.IsDownload = 1 book.IsDownload = 1
} }
if enableShare {
book.IsEnableShare = 0
}else{
book.IsEnableShare = 1
}
if err := book.Update(); err != nil { if err := book.Update(); err != nil {
c.JsonResult(6006, "保存失败") c.JsonResult(6006, "保存失败")
} }
@ -345,7 +351,7 @@ func (c *BookController) UploadCover() {
oldCover := book.Cover oldCover := book.Cover
book.Cover = utils.URLForWithCdnImage(url) book.Cover = conf.URLForWithCdnImage(url)
if err := book.Update(); err != nil { if err := book.Update(); err != nil {
c.JsonResult(6001, "保存图片失败") c.JsonResult(6001, "保存图片失败")
@ -554,7 +560,7 @@ func (c *BookController) CreateToken() {
logs.Error("生成阅读令牌失败 => ", err) logs.Error("生成阅读令牌失败 => ", err)
c.JsonResult(6003, "生成阅读令牌失败") c.JsonResult(6003, "生成阅读令牌失败")
} }
c.JsonResult(0, "ok", utils.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken)) c.JsonResult(0, "ok", conf.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken))
} else { } else {
book.PrivateToken = "" book.PrivateToken = ""
if err := book.Update(); err != nil { if err := book.Update(); err != nil {

View File

@ -105,7 +105,7 @@ func promptUserToLogIn(c *DocumentController) {
if c.IsAjax() { if c.IsAjax() {
c.JsonResult(6000, "请重新登录。") c.JsonResult(6000, "请重新登录。")
} else { } else {
c.Redirect(utils.URLFor("AccountController.Login")+ "?url=" + url.PathEscape(conf.BaseUrl+ c.Ctx.Request.URL.RequestURI()), 302) c.Redirect(conf.URLFor("AccountController.Login")+ "?url=" + url.PathEscape(conf.BaseUrl+ c.Ctx.Request.URL.RequestURI()), 302)
} }
} }
@ -522,7 +522,7 @@ func (c *DocumentController) Upload() {
if strings.EqualFold(ext, ".jpg") || strings.EqualFold(ext, ".jpeg") || strings.EqualFold(ext, ".png") || strings.EqualFold(ext, ".gif") { if strings.EqualFold(ext, ".jpg") || strings.EqualFold(ext, ".jpeg") || strings.EqualFold(ext, ".png") || strings.EqualFold(ext, ".gif") {
attachment.HttpPath = "/" + strings.Replace(strings.TrimPrefix(filePath, conf.WorkingDirectory), "\\", "/", -1) attachment.HttpPath = "/" + strings.Replace(strings.TrimPrefix(filePath, conf.WorkingDirectory), "\\", "/", -1)
if strings.HasPrefix(attachment.HttpPath, "//") { if strings.HasPrefix(attachment.HttpPath, "//") {
attachment.HttpPath = utils.URLForWithCdnImage(string(attachment.HttpPath[1:])) attachment.HttpPath = conf.URLForWithCdnImage(string(attachment.HttpPath[1:]))
} }
is_attach = false is_attach = false
@ -537,7 +537,7 @@ func (c *DocumentController) Upload() {
} }
if attachment.HttpPath == "" { if attachment.HttpPath == "" {
attachment.HttpPath = utils.URLFor("DocumentController.DownloadAttachment", ":key", identify, ":attach_id", attachment.AttachmentId) attachment.HttpPath = conf.URLFor("DocumentController.DownloadAttachment", ":key", identify, ":attach_id", attachment.AttachmentId)
if err := attachment.Update(); err != nil { if err := attachment.Update(); err != nil {
beego.Error("SaveToFile => ", err) beego.Error("SaveToFile => ", err)
@ -892,7 +892,7 @@ func (c *DocumentController) Export() {
} }
if !strings.HasPrefix(bookResult.Cover, "http:://") && !strings.HasPrefix(bookResult.Cover, "https:://") { if !strings.HasPrefix(bookResult.Cover, "http:://") && !strings.HasPrefix(bookResult.Cover, "https:://") {
bookResult.Cover = utils.URLForWithCdnImage(bookResult.Cover) bookResult.Cover = conf.URLForWithCdnImage(bookResult.Cover)
} }
if output == "markdown" { if output == "markdown" {
@ -951,7 +951,7 @@ func (c *DocumentController) QrCode() {
c.Abort("404") c.Abort("404")
} }
uri := utils.URLFor("DocumentController.Index", ":key", identify) uri := conf.URLFor("DocumentController.Index", ":key", identify)
code, err := qr.Encode(uri, qr.L, qr.Unicode) code, err := qr.Encode(uri, qr.L, qr.Unicode)
if err != nil { if err != nil {
beego.Error(err) beego.Error(err)

View File

@ -7,7 +7,6 @@ import (
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/lifei6671/mindoc/conf" "github.com/lifei6671/mindoc/conf"
"github.com/lifei6671/mindoc/models" "github.com/lifei6671/mindoc/models"
"github.com/lifei6671/mindoc/utils"
"github.com/lifei6671/mindoc/utils/pagination" "github.com/lifei6671/mindoc/utils/pagination"
) )
@ -20,7 +19,7 @@ func (c *HomeController) Index() {
c.TplName = "home/index.tpl" c.TplName = "home/index.tpl"
//如果没有开启匿名访问,则跳转到登录页面 //如果没有开启匿名访问,则跳转到登录页面
if !c.EnableAnonymous && c.Member == nil { if !c.EnableAnonymous && c.Member == nil {
c.Redirect(utils.URLFor("AccountController.Login")+"?url="+url.PathEscape(conf.BaseUrl+c.Ctx.Request.URL.RequestURI()), 302) c.Redirect(conf.URLFor("AccountController.Login")+"?url="+url.PathEscape(conf.BaseUrl+c.Ctx.Request.URL.RequestURI()), 302)
} }
pageIndex, _ := c.GetInt("page", 1) pageIndex, _ := c.GetInt("page", 1)
pageSize := 18 pageSize := 18

View File

@ -7,7 +7,6 @@ import (
"github.com/astaxie/beego/orm" "github.com/astaxie/beego/orm"
"github.com/lifei6671/mindoc/conf" "github.com/lifei6671/mindoc/conf"
"github.com/lifei6671/mindoc/models" "github.com/lifei6671/mindoc/models"
"github.com/lifei6671/mindoc/utils"
"github.com/lifei6671/mindoc/utils/pagination" "github.com/lifei6671/mindoc/utils/pagination"
) )
@ -20,7 +19,7 @@ func (c *LabelController) Prepare() {
//如果没有开启你们访问则跳转到登录 //如果没有开启你们访问则跳转到登录
if !c.EnableAnonymous && c.Member == nil { if !c.EnableAnonymous && c.Member == nil {
c.Redirect(utils.URLFor("AccountController.Login"), 302) c.Redirect(conf.URLFor("AccountController.Login"), 302)
return return
} }
} }

View File

@ -352,7 +352,7 @@ func (c *ManagerController) EditBook() {
c.JsonResult(0, "ok") c.JsonResult(0, "ok")
} }
if book.PrivateToken != "" { if book.PrivateToken != "" {
book.PrivateToken = utils.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken) book.PrivateToken = conf.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken)
} }
c.Data["Model"] = book c.Data["Model"] = book
} }
@ -403,7 +403,7 @@ func (c *ManagerController) CreateToken() {
logs.Error("生成阅读令牌失败 => ", err) logs.Error("生成阅读令牌失败 => ", err)
c.JsonResult(6003, "生成阅读令牌失败") c.JsonResult(6003, "生成阅读令牌失败")
} }
c.JsonResult(0, "ok", utils.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken)) c.JsonResult(0, "ok", conf.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken))
} else { } else {
book.PrivateToken = "" book.PrivateToken = ""
if err := book.Update(); err != nil { if err := book.Update(); err != nil {
@ -610,7 +610,7 @@ func (c *ManagerController) AttachDetailed() {
} }
attach.FilePath = filepath.Join(conf.WorkingDirectory, attach.FilePath) attach.FilePath = filepath.Join(conf.WorkingDirectory, attach.FilePath)
attach.HttpPath = utils.URLForWithCdnImage(attach.HttpPath) attach.HttpPath = conf.URLForWithCdnImage(attach.HttpPath)
attach.IsExist = utils.FileExists(attach.FilePath) attach.IsExist = utils.FileExists(attach.FilePath)

View File

@ -21,7 +21,7 @@ func (c *SearchController) Index() {
//如果没有开启你们访问则跳转到登录 //如果没有开启你们访问则跳转到登录
if !c.EnableAnonymous && c.Member == nil { if !c.EnableAnonymous && c.Member == nil {
c.Redirect(utils.URLFor("AccountController.Login"), 302) c.Redirect(conf.URLFor("AccountController.Login"), 302)
return return
} }

View File

@ -51,6 +51,8 @@ type Book struct {
CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add" json:"create_time"` CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add" json:"create_time"`
//每个文档保存的历史记录数量0 为不限制 //每个文档保存的历史记录数量0 为不限制
HistoryCount int `orm:"column(history_count);type(int);default(0)" json:"history_count"` HistoryCount int `orm:"column(history_count);type(int);default(0)" json:"history_count"`
//是否启用分享0启用/1不启用
IsEnableShare int `orm:"column(is_enable_share);type(int);default(0)" json:"is_enable_share"`
MemberId int `orm:"column(member_id);size(100)" json:"member_id"` MemberId int `orm:"column(member_id);size(100)" json:"member_id"`
ModifyTime time.Time `orm:"type(datetime);column(modify_time);null;auto_now" json:"modify_time"` ModifyTime time.Time `orm:"type(datetime);column(modify_time);null;auto_now" json:"modify_time"`
Version int64 `orm:"type(bigint);column(version)" json:"version"` Version int64 `orm:"type(bigint);column(version)" json:"version"`

View File

@ -48,7 +48,8 @@ type BookResult struct {
RelationshipId int `json:"relationship_id"` RelationshipId int `json:"relationship_id"`
RoleId int `json:"role_id"` RoleId int `json:"role_id"`
RoleName string `json:"role_name"` RoleName string `json:"role_name"`
Status int Status int `json:"status"`
IsEnableShare bool `json:"is_enable_share"`
LastModifyText string `json:"last_modify_text"` LastModifyText string `json:"last_modify_text"`
IsDisplayComment bool `json:"is_display_comment"` IsDisplayComment bool `json:"is_display_comment"`
@ -174,6 +175,7 @@ func (m *BookResult) ToBookResult(book Book) *BookResult {
m.Editor = book.Editor m.Editor = book.Editor
m.Theme = book.Theme m.Theme = book.Theme
m.AutoRelease = book.AutoRelease == 1 m.AutoRelease = book.AutoRelease == 1
m.IsEnableShare = book.IsEnableShare == 0
m.Publisher = book.Publisher m.Publisher = book.Publisher
m.HistoryCount = book.HistoryCount m.HistoryCount = book.HistoryCount
m.IsDownload = book.IsDownload == 0 m.IsDownload = book.IsDownload == 0

View File

@ -2,11 +2,12 @@ package models
import ( import (
"bytes" "bytes"
"github.com/astaxie/beego/orm"
"html/template" "html/template"
"math" "math"
"strconv" "strconv"
"github.com/lifei6671/mindoc/utils"
"github.com/astaxie/beego/orm"
"github.com/lifei6671/mindoc/conf"
) )
type DocumentTree struct { type DocumentTree struct {
@ -116,10 +117,10 @@ func getDocumentTree(array []*DocumentTree, parent_id int, selected_id int, sele
buf.WriteString(selected_li) buf.WriteString(selected_li)
buf.WriteString("><a href=\"") buf.WriteString("><a href=\"")
if item.Identify != "" { if item.Identify != "" {
uri := utils.URLFor("DocumentController.Read", ":key", item.BookIdentify, ":id", item.Identify) uri := conf.URLFor("DocumentController.Read", ":key", item.BookIdentify, ":id", item.Identify)
buf.WriteString(uri) buf.WriteString(uri)
} else { } else {
uri := utils.URLFor("DocumentController.Read", ":key", item.BookIdentify, ":id", item.DocumentId) uri := conf.URLFor("DocumentController.Read", ":key", item.BookIdentify, ":id", item.DocumentId)
buf.WriteString(uri) buf.WriteString(uri)
} }
buf.WriteString("\" title=\"") buf.WriteString("\" title=\"")

View File

@ -2,7 +2,6 @@ package utils
import ( import (
"strings" "strings"
"github.com/astaxie/beego"
) )
func JoinURI(elem ...string) string { func JoinURI(elem ...string) string {
@ -29,98 +28,3 @@ func JoinURI(elem ...string) string {
} }
return uri return uri
} }
//重写生成URL的方法加上完整的域名
func URLFor(endpoint string, values ...interface{}) string {
baseUrl := beego.AppConfig.DefaultString("baseurl","")
pathUrl := beego.URLFor(endpoint, values ...)
if strings.HasPrefix(pathUrl,"http://") {
return pathUrl
}
if strings.HasPrefix(pathUrl,"/") && strings.HasSuffix(baseUrl,"/") {
return baseUrl + pathUrl[1:]
}
if !strings.HasPrefix(pathUrl,"/") && !strings.HasSuffix(baseUrl,"/") {
return baseUrl + "/" + pathUrl
}
return baseUrl + beego.URLFor(endpoint, values ...)
}
func URLForWithCdnImage(p string) string {
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
return p
}
cdn := beego.AppConfig.DefaultString("cdnimg", "")
//如果没有设置cdn则使用baseURL拼接
if cdn == "" {
baseUrl := beego.AppConfig.DefaultString("baseurl","")
if strings.HasPrefix(p,"/") && strings.HasSuffix(baseUrl,"/") {
return baseUrl + p[1:]
}
if !strings.HasPrefix(p,"/") && !strings.HasSuffix(baseUrl,"/") {
return baseUrl + "/" + p
}
return baseUrl + p
}
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
return cdn + string(p[1:])
}
if !strings.HasPrefix(p, "/") && !strings.HasSuffix(cdn, "/") {
return cdn + "/" + p
}
return cdn + p
}
func URLForWithCdnCss (p string) string {
cdn := beego.AppConfig.DefaultString("cdncss", "")
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
return p
}
//如果没有设置cdn则使用baseURL拼接
if cdn == "" {
baseUrl := beego.AppConfig.DefaultString("baseurl","")
if strings.HasPrefix(p,"/") && strings.HasSuffix(baseUrl,"/") {
return baseUrl + p[1:]
}
if !strings.HasPrefix(p,"/") && !strings.HasSuffix(baseUrl,"/") {
return baseUrl + "/" + p
}
return baseUrl + p
}
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
return cdn + string(p[1:])
}
if !strings.HasPrefix(p, "/") && !strings.HasSuffix(cdn, "/") {
return cdn + "/" + p
}
return cdn + p
}
func URLForWithCdnJs(p string) string {
cdn := beego.AppConfig.DefaultString("cdnjs", "")
if strings.HasPrefix(p, "http://") || strings.HasPrefix(p, "https://") {
return p
}
//如果没有设置cdn则使用baseURL拼接
if cdn == "" {
baseUrl := beego.AppConfig.DefaultString("baseurl","")
if strings.HasPrefix(p,"/") && strings.HasSuffix(baseUrl,"/") {
return baseUrl + p[1:]
}
if !strings.HasPrefix(p,"/") && !strings.HasSuffix(baseUrl,"/") {
return baseUrl + "/" + p
}
return baseUrl + p
}
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
return cdn + string(p[1:])
}
if !strings.HasPrefix(p, "/") && !strings.HasSuffix(cdn, "/") {
return cdn + "/" + p
}
return cdn + p
}

View File

@ -129,6 +129,7 @@
</div> </div>
</div> </div>
{{end}} {{end}}
<div class="form-group"> <div class="form-group">
<label for="autoRelease">自动发布</label> <label for="autoRelease">自动发布</label>
<div class="controls"> <div class="controls">
@ -145,6 +146,14 @@
</div> </div>
</div> </div>
</div> </div>
<div class="form-group">
<label for="autoRelease">开启分享</label>
<div class="controls">
<div class="switch switch-small" data-on="primary" data-off="info">
<input type="checkbox" id="enableShare" name="enable_share"{{if .Model.IsEnableShare }} checked{{end}} data-size="small">
</div>
</div>
</div>
<div class="form-group"> <div class="form-group">
<button type="submit" id="btnSaveBookInfo" class="btn btn-success" data-loading-text="保存中...">保存修改</button> <button type="submit" id="btnSaveBookInfo" class="btn btn-success" data-loading-text="保存中...">保存修改</button>
<span id="form-error-message" class="error-message"></span> <span id="form-error-message" class="error-message"></span>
@ -308,8 +317,7 @@
}).on("show.bs.modal",function () { }).on("show.bs.modal",function () {
window.modalHtml = $("#upload-logo-panel").find(".modal-body").html(); window.modalHtml = $("#upload-logo-panel").find(".modal-body").html();
}); });
$("#autoRelease").bootstrapSwitch(); $("#autoRelease,#enableShare,#isDownload").bootstrapSwitch();
$("#isDownload").bootstrapSwitch();
$('input[name="label"]').tagsinput({ $('input[name="label"]').tagsinput({
confirmKeys: [13,44], confirmKeys: [13,44],

View File

@ -61,8 +61,10 @@
</div> </div>
<div class="dropdown pull-right" style="margin-right: 10px;"> <div class="dropdown pull-right" style="margin-right: 10px;">
{{if eq .Model.PrivatelyOwned 0}} {{if eq .Model.PrivatelyOwned 0}}
{{if .Model.IsEnableShare}}
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#shareProject"><i class="fa fa-share-alt" aria-hidden="true"></i> 分享</button> <button type="button" class="btn btn-success" data-toggle="modal" data-target="#shareProject"><i class="fa fa-share-alt" aria-hidden="true"></i> 分享</button>
{{end}} {{end}}
{{end}}
</div> </div>
{{if .Model.IsDownload}} {{if .Model.IsDownload}}
<div class="dropdown pull-right" style="margin-right: 10px;"> <div class="dropdown pull-right" style="margin-right: 10px;">
@ -211,7 +213,7 @@
</article> </article>
<div class="manual-mask"></div> <div class="manual-mask"></div>
</div> </div>
{{if .Model.IsEnableShare}}
<!-- 分享项目 --> <!-- 分享项目 -->
<div class="modal fade" id="shareProject" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal fade" id="shareProject" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog"> <div class="modal-dialog">
@ -240,6 +242,7 @@
</div> </div>
</div> </div>
</div> </div>
{{end}}
<!-- 下载项目 --> <!-- 下载项目 -->
<div class="modal fade" id="downloadBookModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal fade" id="downloadBookModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog"> <div class="modal-dialog">
@ -257,7 +260,7 @@
<div class="form-group"> <div class="form-group">
<label for="password" class="col-sm-2 control-label">项目地址</label> <label for="password" class="col-sm-2 control-label">项目地址</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" value="{{.BaseUrl}}{{urlfor "DocumentController.Index" ":key" .Model.Identify}}" class="form-control" onmouseover="this.select()" id="projectUrl" title="项目地址"> <input type="text" value="{{urlfor "DocumentController.Index" ":key" .Model.Identify}}" class="form-control" onmouseover="this.select()" id="projectUrl" title="项目地址">
</div> </div>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>