mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-07 15:22:26 +08:00
add kodo
This commit is contained in:
2
back.go
2
back.go
@@ -75,7 +75,7 @@ func HandleLoginPost(c *gin.Context) {
|
||||
}
|
||||
|
||||
func GetBack() gin.H {
|
||||
return gin.H{"Author": Ei.Username}
|
||||
return gin.H{"Author": Ei.Username, "Kodo": setting.Conf.Kodo}
|
||||
}
|
||||
|
||||
// 个人配置
|
||||
|
||||
14
conf/app.yml
14
conf/app.yml
@@ -1,7 +1,5 @@
|
||||
# 运行模式 dev or prod
|
||||
runmode: prod
|
||||
# 静态文件版本
|
||||
staticversion: 2
|
||||
# 回收箱保留48小时
|
||||
trash: -48
|
||||
# 定时清理回收箱,%d小时
|
||||
@@ -14,12 +12,8 @@ pagesize: 20
|
||||
length: 400
|
||||
# 截取预览标识
|
||||
identifier: <!--more-->
|
||||
# favicon
|
||||
favicon: //st.deepzz.com/static/img/favicon.ico
|
||||
# 起始ID,预留id不时之需, 不用管
|
||||
startid: 11
|
||||
# cdn: //domain.com
|
||||
static: //st.deepzz.com
|
||||
# elasticsearch url
|
||||
searchurl: http://elasticsearch:9200
|
||||
# superfeedr shortname
|
||||
@@ -39,6 +33,14 @@ google:
|
||||
tid: UA-77251712-1
|
||||
v: "1"
|
||||
t: pageview
|
||||
# 静态文件版本
|
||||
staticversion: 2
|
||||
# 七牛CDN
|
||||
kodo:
|
||||
name: eiblog
|
||||
domain: st.deepzz.com
|
||||
accesskey:
|
||||
secretkey:
|
||||
# 运行模式
|
||||
mode:
|
||||
# you can fix certfile, keyfile, domain
|
||||
|
||||
@@ -5,5 +5,5 @@ import (
|
||||
)
|
||||
|
||||
func TestDisqus(t *testing.T) {
|
||||
CommentsCount()
|
||||
PostsCount()
|
||||
}
|
||||
|
||||
@@ -61,13 +61,6 @@ func TestIndexDocument(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexQuerySimple(t *testing.T) {
|
||||
_, err := IndexQuerySimple(INDEX, TYPE, 10, 1, "JS")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexQueryDSL(t *testing.T) {
|
||||
kw := "实现访问限制"
|
||||
dsl := map[string]interface{}{
|
||||
|
||||
2
front.go
2
front.go
@@ -63,7 +63,7 @@ func GetBase() gin.H {
|
||||
"BTitle": Ei.BTitle,
|
||||
"BeiAn": Ei.BeiAn,
|
||||
"Domain": setting.Conf.Mode.Domain,
|
||||
"Static": setting.Conf.Static,
|
||||
"Kodo": setting.Conf.Kodo,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
97
qiniu.go
Normal file
97
qiniu.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/eiblog/utils/logd"
|
||||
"qiniupkg.com/api.v7/conf"
|
||||
"qiniupkg.com/api.v7/kodo"
|
||||
"qiniupkg.com/api.v7/kodocli"
|
||||
)
|
||||
|
||||
type bucket struct {
|
||||
name string
|
||||
domain string
|
||||
accessKey string
|
||||
secretKey string
|
||||
}
|
||||
|
||||
var buckets = map[string]*bucket{
|
||||
"avatar": &bucket{name: "yooohome-avatar", domain: "o9gich2l7.bkt.clouddn.com",
|
||||
accessKey: "porNOigaMUjIcO9I5ePPGJmO1fchhqnlSI0oBrpY", secretKey: "l0EawgePDmXzMYBvC_7WALUvD69iDzMgay7rX77b"},
|
||||
"topic": &bucket{name: "yooohome-topic", domain: "o9gie1fqp.bkt.clouddn.com",
|
||||
accessKey: "porNOigaMUjIcO9I5ePPGJmO1fchhqnlSI0oBrpY", secretKey: "l0EawgePDmXzMYBvC_7WALUvD69iDzMgay7rX77b"},
|
||||
}
|
||||
|
||||
func getBucket(typ string) *bucket {
|
||||
return buckets[typ]
|
||||
}
|
||||
|
||||
type PutRet struct {
|
||||
Hash string `json:"hash"`
|
||||
Key string `json:"key"`
|
||||
}
|
||||
|
||||
func onProgress(fsize, uploaded int64) {
|
||||
d := int(float64(uploaded) / float64(fsize) * 100)
|
||||
if fsize == uploaded {
|
||||
fmt.Printf("\rUpload completed! ")
|
||||
} else {
|
||||
fmt.Printf("\r%02d%% uploaded ", int(d))
|
||||
}
|
||||
}
|
||||
|
||||
func upload(typ string, filepath string) {
|
||||
bucket := getBucket(typ)
|
||||
if bucket == nil {
|
||||
logd.Debug("invalid type:", typ)
|
||||
return
|
||||
}
|
||||
|
||||
file, err := os.Open(filepath)
|
||||
if err != nil {
|
||||
logd.Debugf("%s", err.Error())
|
||||
return
|
||||
}
|
||||
data, err := ioutil.ReadAll(file)
|
||||
file.Close()
|
||||
chksum := fmt.Sprintf("%x", md5.Sum(data))
|
||||
ext := path.Ext(filepath)
|
||||
|
||||
conf.ACCESS_KEY = bucket.accessKey
|
||||
conf.SECRET_KEY = bucket.secretKey
|
||||
// 创建一个client
|
||||
c := kodo.New(0, nil)
|
||||
|
||||
// 设置上传的策略
|
||||
policy := &kodo.PutPolicy{
|
||||
Scope: bucket.name,
|
||||
Expires: 3600,
|
||||
InsertOnly: 1,
|
||||
}
|
||||
|
||||
// 生成一个上传token
|
||||
token := c.MakeUptoken(policy)
|
||||
// 构建一个uploader
|
||||
zone := 0
|
||||
uploader := kodocli.NewUploader(zone, nil)
|
||||
|
||||
var ret PutRet
|
||||
key := fmt.Sprintf("%s-%s%s", typ, chksum, ext)
|
||||
|
||||
fmt.Printf("Uploading .....")
|
||||
var extra = kodocli.PutExtra{OnProgress: onProgress}
|
||||
res := uploader.PutFile(nil, &ret, token, key, filepath, &extra)
|
||||
// 打印返回的信息
|
||||
if res != nil {
|
||||
logd.Debugf("failed to upload patch file: %v", res)
|
||||
return
|
||||
}
|
||||
|
||||
url := kodo.MakeBaseUrl(bucket.domain, key)
|
||||
fmt.Printf("url: %s\n", url)
|
||||
}
|
||||
@@ -48,6 +48,12 @@ type Config struct {
|
||||
V string
|
||||
T string
|
||||
}
|
||||
Kodo struct { // 七牛CDN
|
||||
Name string
|
||||
Domain string
|
||||
AccessKey string
|
||||
SecretKey string
|
||||
}
|
||||
Mode RunMode // 运行模式
|
||||
Twitter string // twitter地址
|
||||
Blogger struct { // 初始化数据
|
||||
|
||||
@@ -55,6 +55,15 @@
|
||||
<input id="tags" name="tags" type="text" {{with .Edit}}value="{{join .Tags ","}}"{{end}} class="w-100 text" />
|
||||
</p>
|
||||
</section>
|
||||
<section class="typecho-post-option category-option">
|
||||
<label class="typecho-label">其它选项</label>
|
||||
<ul>
|
||||
<li>
|
||||
<input type="checkbox" id="update" value="update" name="update" />
|
||||
<label for="update">变动很大(更新时间)?</label>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
<!-- end #tab-advance -->
|
||||
<div id="tab-files" class="tab-content hidden">
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<div class="row typecho-page-main">
|
||||
<div class="col-mb-12 col-tb-3">
|
||||
<p>
|
||||
<img class="profile-avatar" src="//st.deepzz.com/static/img/deepzz.jpg" alt="{{.BlogName}}" />
|
||||
<img class="profile-avatar" src="//{{$.Kodo.Domain}}/static/img/avatar.jpg" alt="{{.BlogName}}" />
|
||||
</p>
|
||||
<h2>{{.BlogName}}</h2>
|
||||
<p>{{.SubTitle}}</p>
|
||||
@@ -163,4 +163,4 @@
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
@@ -1 +1 @@
|
||||
<!DOCTYPE html><html lang="zh-cn"><head><meta charset="utf-8"><meta content="width=device-width,minimum-scale=1.0" name="viewport"><meta name="format-detection" content="telephone=no"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="referrer" content="always"><title>{{.Title}}</title><script>!function(n,t){function e(){o("nls",1)}function c(){t.documentElement.style.display="none",u(),location.reload()}function r(n){var t="";try{t=f[n]||"",t.length<99&&c()}catch(e){u()}return t}function i(n,t){try{f[n]=t,t!==f[n]&&u()}catch(e){u()}}function o(n,e){var c=999;e||(c=-1),c=new Date(+new Date+86400000*c).toGMTString();var r=n+"="+e+";path=/;secure;expires="+c;t.cookie=r}function a(n){var e=t.getElementById(n).innerHTML;i(n,e)}function l(e,c){var i=r(e),o=t.createElement(c?"script":"style");return n.execScript&&c?n.execScript(i):(o.innerHTML=i,void t.head.appendChild(o))}function u(){o("v",0)}var f,h=function(){},d=n.L={h:h,l:h,c:h};try{f=localStorage,d.h=a,d.l=l,d.c=o}catch(p){e()}}(this,document);</script>{{if .Version}}<script>L.c('v', {{.Version}})</script>{{end}}<link rel="apple-touch-icon" href="{{.Favicon}}"><link rel="search" type="application/opensearchdescription+xml" href="//{{.Domain}}/opensearch.xml" title="{{.BTitle}}">{{if .Version}}<style id="blog_css">{{template "blog_css"}}</style><script>L.h('blog_css')</script>{{else}}<script>L.l("blog_css")</script>{{end}}<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="//{{.Domain}}/rss.html"><meta name="description" content="{{.Description}}"><style id="style-1-cropbar-clipper">.en-markup-crop-options{top:18px!important;left:50%!important;margin-left:-100px!important;width:200px!important;border:2px rgba(255,255,255,.38) solid!important;border-radius:4px!important}.en-markup-crop-options div div:first-of-type{margin-left:0!important}</style></head><body><div class="container"><div class="left-col"><div class="intrude-less"><header id="header" class="inner"><div class="profilepic"><a href="/"></a></div><h1><a href="/">{{.BlogName}}</a></h1><p class="subtitle">{{.SubTitle}}</p><nav id="main-nav"><ul><li {{if eq .Path "/"}}class="on" {{end}}><a href="/"><span>首页</span></a></li><li {{if eq .Path "/series.html"}}class="on" {{end}}><a href="/series.html"><span>专题</span></a></li><li {{if eq .Path "/archives.html"}}class="on" {{end}}><a href="/archives.html"><span>归档</span></a></li><li {{if eq .Path "/post/blogroll.html"}}class="on" {{end}}><a href="/post/blogroll.html"><span>友链</span></a></li><li {{if eq .Path "/post/about.html"}}class="on" {{end}}><a href="/post/about.html"><span>关于</span></a></li></ul></nav><nav id="sub-nav"><div class="social"><a target="_blank" class="twitter external" rel="nofollow" href="{{.Twitter}}" title="Twitter">Twitter</a><a target="_blank" class="rss" href="//{{.Domain}}/rss.html" title="RSS 订阅">RSS</a><a class="search" href="/search.html" title="站内搜索">Search</a></div></nav></header></div></div><div class="mid-col"><div class="mid-col-container">{{.LayoutContent}}</div><footer id=footer class=inner>© {{.CopyYear}} - {{.BTitle}} - <a target="_blank" rel="nofollow designer" class="external beian" href="http://www.miitbeian.gov.cn/">{{.BeiAn}}</a><br>Powered by <a target=_blank href="//github.com/eiblog/eiblog">Eiblog</a> & <a target=_blank rel="nofollow designer" class=external href="//imququ.com">JerryQu</a></footer></div></div><input type=hidden id=CURRENT_PAGE value="{{.CurrentPage}}"><input type=hidden id=CDN_DOMAIN value="{{.Static}}">{{if .Version}}<script id="ana_js">{{template "ana_js"}}</script><script>L.h('ana_js')</script>{{else}}<script>L.l('ana_js', 1)</script>{{end}}{{if .Version}}<script id="jq_js">{{template "jq_js"}}</script><script>L.h('jq_js')</script>{{else}}<script>L.l('jq_js', 1)</script>{{end}}{{if .Version}}<script id="hl_js">{{template "hl_js"}}</script><script>L.h('hl_js')</script>{{else}}<script>L.l('hl_js', 1)</script>{{end}}{{if .Version}}<script id="blog_js">{{template "blog_js"}}</script><script>L.h('blog_js')</script>{{else}}<script>L.l('blog_js', 1)</script>{{end}}</body></html>
|
||||
<!DOCTYPE html><html lang="zh-cn"><head><meta charset="utf-8"><meta content="width=device-width,minimum-scale=1.0" name="viewport"><meta name="format-detection" content="telephone=no"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="referrer" content="always"><title>{{.Title}}</title><script>!function(n,t){function e(){o("nls",1)}function c(){t.documentElement.style.display="none",u(),location.reload()}function r(n){var t="";try{t=f[n]||"",t.length<99&&c()}catch(e){u()}return t}function i(n,t){try{f[n]=t,t!==f[n]&&u()}catch(e){u()}}function o(n,e){var c=999;e||(c=-1),c=new Date(+new Date+86400000*c).toGMTString();var r=n+"="+e+";path=/;secure;expires="+c;t.cookie=r}function a(n){var e=t.getElementById(n).innerHTML;i(n,e)}function l(e,c){var i=r(e),o=t.createElement(c?"script":"style");return n.execScript&&c?n.execScript(i):(o.innerHTML=i,void t.head.appendChild(o))}function u(){o("v",0)}var f,h=function(){},d=n.L={h:h,l:h,c:h};try{f=localStorage,d.h=a,d.l=l,d.c=o}catch(p){e()}}(this,document);</script>{{if .Version}}<script>L.c('v', {{.Version}})</script>{{end}}<link rel="apple-touch-icon" href="//{{.Kodo.Domain}}/static/img/favicon.ico"><link rel="search" type="application/opensearchdescription+xml" href="//{{.Domain}}/opensearch.xml" title="{{.BTitle}}">{{if .Version}}<style id="blog_css">{{template "blog_css"}}</style><script>L.h('blog_css')</script>{{else}}<script>L.l("blog_css")</script>{{end}}<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="//{{.Domain}}/rss.html"><meta name="description" content="{{.Description}}"><style id="style-1-cropbar-clipper">.en-markup-crop-options{top:18px!important;left:50%!important;margin-left:-100px!important;width:200px!important;border:2px rgba(255,255,255,.38) solid!important;border-radius:4px!important}.en-markup-crop-options div div:first-of-type{margin-left:0!important}</style></head><body><div class="container"><div class="left-col"><div class="intrude-less"><header id="header" class="inner"><div class="profilepic"><a href="/"></a></div><h1><a href="/">{{.BlogName}}</a></h1><p class="subtitle">{{.SubTitle}}</p><nav id="main-nav"><ul><li {{if eq .Path "/"}}class="on" {{end}}><a href="/"><span>首页</span></a></li><li {{if eq .Path "/series.html"}}class="on" {{end}}><a href="/series.html"><span>专题</span></a></li><li {{if eq .Path "/archives.html"}}class="on" {{end}}><a href="/archives.html"><span>归档</span></a></li><li {{if eq .Path "/post/blogroll.html"}}class="on" {{end}}><a href="/post/blogroll.html"><span>友链</span></a></li><li {{if eq .Path "/post/about.html"}}class="on" {{end}}><a href="/post/about.html"><span>关于</span></a></li></ul></nav><nav id="sub-nav"><div class="social"><a target="_blank" class="twitter external" rel="nofollow" href="{{.Twitter}}" title="Twitter">Twitter</a><a target="_blank" class="rss" href="//{{.Domain}}/rss.html" title="RSS 订阅">RSS</a><a class="search" href="/search.html" title="站内搜索">Search</a></div></nav></header></div></div><div class="mid-col"><div class="mid-col-container">{{.LayoutContent}}</div><footer id=footer class=inner>© {{.CopyYear}} - {{.BTitle}} - <a target="_blank" rel="nofollow designer" class="external beian" href="http://www.miitbeian.gov.cn/">{{.BeiAn}}</a><br>Powered by <a target=_blank href="//github.com/eiblog/eiblog">Eiblog</a> & <a target=_blank rel="nofollow designer" class=external href="//imququ.com">JerryQu</a></footer></div></div><input type=hidden id=CURRENT_PAGE value="{{.CurrentPage}}"><input type=hidden id=CDN_DOMAIN value="//{{.Kodo.Domain}}">{{if .Version}}<script id="ana_js">{{template "ana_js"}}</script><script>L.h('ana_js')</script>{{else}}<script>L.l('ana_js', 1)</script>{{end}}{{if .Version}}<script id="jq_js">{{template "jq_js"}}</script><script>L.h('jq_js')</script>{{else}}<script>L.l('jq_js', 1)</script>{{end}}{{if .Version}}<script id="hl_js">{{template "hl_js"}}</script><script>L.h('hl_js')</script>{{else}}<script>L.l('hl_js', 1)</script>{{end}}{{if .Version}}<script id="blog_js">{{template "blog_js"}}</script><script>L.h('blog_js')</script>{{else}}<script>L.l('blog_js', 1)</script>{{end}}</body></html>
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user