修复文章发布报错
This commit is contained in:
@@ -307,6 +307,15 @@ func (c *BackendArticleController) List() {
|
||||
qs = qs.Filter("cate_id", cid)
|
||||
}
|
||||
}
|
||||
// 创建时间区间筛选(前端日期控件传 yyyy-MM-dd)
|
||||
startDate := strings.TrimSpace(c.GetString("startDate"))
|
||||
endDate := strings.TrimSpace(c.GetString("endDate"))
|
||||
if startDate != "" {
|
||||
qs = qs.Filter("create_time__gte", startDate+" 00:00:00")
|
||||
}
|
||||
if endDate != "" {
|
||||
qs = qs.Filter("create_time__lte", endDate+" 23:59:59")
|
||||
}
|
||||
|
||||
total, _ := qs.Count()
|
||||
var rows []models.CmsArticle
|
||||
|
||||
@@ -119,7 +119,32 @@ func (c *TenantSiteController) resolveTemplateCode(tid uint64) string {
|
||||
func (c *TenantSiteController) writeHTML(status int, html string) {
|
||||
c.Ctx.Output.SetStatus(status)
|
||||
c.Ctx.Output.Header("Content-Type", "text/html; charset=utf-8")
|
||||
c.Ctx.WriteString(html)
|
||||
c.Ctx.WriteString(c.forceHTTPSStorageURLs(html))
|
||||
}
|
||||
|
||||
// forceHTTPSStorageURLs 访客以 HTTPS 访问站点时,把页面中存储(CDN)域名的
|
||||
// http:// 资源升级为 https://,避免混合内容(Mixed Content)被浏览器拦截。
|
||||
// 仅替换存储配置里那个域名,不动正文里的其他外部链接。
|
||||
func (c *TenantSiteController) forceHTTPSStorageURLs(html string) string {
|
||||
proto := c.Ctx.Input.Header("X-Forwarded-Proto")
|
||||
if proto == "" && c.Ctx.Input.IsSecure() {
|
||||
proto = "https"
|
||||
}
|
||||
if proto != "https" {
|
||||
return html
|
||||
}
|
||||
cfg, err := models.GetStorageConfig()
|
||||
if err != nil || strings.TrimSpace(cfg.QiniuDomain) == "" {
|
||||
return html
|
||||
}
|
||||
host := strings.TrimSpace(cfg.QiniuDomain)
|
||||
host = strings.TrimPrefix(host, "http://")
|
||||
host = strings.TrimPrefix(host, "https://")
|
||||
host = strings.TrimRight(host, "/")
|
||||
if host == "" {
|
||||
return html
|
||||
}
|
||||
return strings.ReplaceAll(html, "http://"+host, "https://"+host)
|
||||
}
|
||||
|
||||
// render 解析并输出模板文件
|
||||
|
||||
Reference in New Issue
Block a user