Compare commits

..

29 Commits

Author SHA1 Message Date
henry.chen
433064de00 chore(release): 2.2.11 2024-01-02 19:09:40 +08:00
henry.chen
9d71ca8198 fix(disqus): fix returned posts list not have parent post 2024-01-02 19:09:37 +08:00
henry.chen
7c938bf024 chore(release): 2.2.10 2023-12-22 14:12:15 +08:00
henry.chen
65fcc69efa chore: bump all gorm & driver version 2023-12-22 14:10:36 +08:00
henry.chen
d06bab72a5 chore: bump gin swagger version to v1.6.0 2023-12-22 14:03:57 +08:00
henry.chen
95900eec1a chore: rm http header: Expect-CT 2023-12-07 09:55:30 +08:00
henry.chen
dfae78891d chore: update ad config 2023-12-01 13:46:29 +08:00
henry.chen
c515e33e2c chore(release): 2.2.9 2023-09-25 18:14:51 +08:00
henry.chen
5b12dd625b chore: update config 2023-09-25 18:14:41 +08:00
henry.chen
9b918caccd fix: google analytics not work, supported ga4 measurement protocol 2023-09-25 18:12:57 +08:00
Deepzz
2be53379e1 Update writing.md 2023-09-13 10:49:51 +08:00
Deepzz
944e27c58a Update app.yml 2023-09-13 10:45:56 +08:00
Deepzz
92baf970bc Update docker-compose.yml 2023-07-12 17:33:18 +08:00
henry.chen
64a754167a chore(release): 2.2.8 2023-07-12 17:30:37 +08:00
henry.chen
af2a20c34a chore: update 2023-07-12 17:30:34 +08:00
henry.chen
f28d0e77e0 fix(backup): restore db and tests 2023-07-12 17:26:44 +08:00
henry.chen
9a1b4db61a chore: update 2023-07-12 15:14:47 +08:00
henry.chen
c9d04aded3 chore(release): 2.2.7 2023-07-12 15:01:40 +08:00
henry.chen
ee51f678cb fix(backup): 数据恢复错误 2023-07-12 14:59:11 +08:00
Deepzz
434c1bf168 Update README.md 2023-06-19 23:19:00 +08:00
henry.chen
d2de603957 chore(release): 2.2.6 2023-06-19 23:13:56 +08:00
henry.chen
e7fdf6b1db chore(backup): backup blog with prefix: blog 2023-06-19 23:13:45 +08:00
Deepzz
305ae0ee70 Merge pull request #40 from eiblog/dependabot/go_modules/github.com/gin-gonic/gin-1.9.1
chore(deps): bump github.com/gin-gonic/gin from 1.9.0 to 1.9.1
2023-06-12 16:55:16 +08:00
dependabot[bot]
a5749fdab6 chore(deps): bump github.com/gin-gonic/gin from 1.9.0 to 1.9.1
Bumps [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin) from 1.9.0 to 1.9.1.
- [Release notes](https://github.com/gin-gonic/gin/releases)
- [Changelog](https://github.com/gin-gonic/gin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/gin-gonic/gin/compare/v1.9.0...v1.9.1)

---
updated-dependencies:
- dependency-name: github.com/gin-gonic/gin
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-01 20:35:02 +00:00
henry.chen
391f19e2a9 chore(release): 2.2.5 2023-05-26 09:57:35 +08:00
henry.chen
2c6c5bb977 fix(backup): libresolv.so.2: No such file or directory 2023-05-26 09:57:30 +08:00
henry.chen
860a85e209 chore: update go.mod 2023-05-25 16:46:26 +08:00
henry.chen
2a8d9b3bbd chore(release): 2.2.4 2023-05-25 16:44:34 +08:00
henry.chen
1509a68cda fix(ci): fix .dockerignore 2023-05-25 16:44:31 +08:00
25 changed files with 2913 additions and 273 deletions

View File

@@ -1,12 +1,12 @@
# Ignore all files and dirs
*
# Unignore files or dirs
!build
!bin
!conf
!assets
!website
!CHANGELOG.md
!LICENSE
!README.md
.github
bin
docs
.gitignore
db.sqlite
docker-compose.yml
eiblog.conf
Makefile

View File

@@ -19,13 +19,6 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Inspect builder
run: |
echo "Name: ${{ steps.buildx.outputs.name }}"
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
echo "Status: ${{ steps.buildx.outputs.status }}"
echo "Flags: ${{ steps.buildx.outputs.flags }}"
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
- name: Docker tag
id: vars
@@ -45,6 +38,7 @@ jobs:
push: true
tags: |
deepzz0/eiblog:${{ steps.vars.outputs.tag }}
deepzz0/eiblog:latest
- name: Build and push backup
uses: docker/build-push-action@v3
@@ -55,6 +49,7 @@ jobs:
push: true
tags: |
deepzz0/backup:${{ steps.vars.outputs.tag }}
deepzz0/backup:latest
- name: Package tar
env:

View File

@@ -2,6 +2,52 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [2.2.11](https://github.com/eiblog/eiblog/compare/v2.2.10...v2.2.11) (2024-01-02)
### Bug Fixes
* **disqus:** fix returned posts list not have parent post ([9d71ca8](https://github.com/eiblog/eiblog/commit/9d71ca81988bfc614d13fcb02079f0dba9ef43cc))
### [2.2.10](https://github.com/eiblog/eiblog/compare/v2.2.9...v2.2.10) (2023-12-22)
### [2.2.9](https://github.com/eiblog/eiblog/compare/v2.2.8...v2.2.9) (2023-09-25)
### Bug Fixes
* google analytics not work, supported ga4 measurement protocol ([9b918ca](https://github.com/eiblog/eiblog/commit/9b918caccd9fd7faff7d253693e075ccd0150c17))
### [2.2.8](https://github.com/eiblog/eiblog/compare/v2.2.7...v2.2.8) (2023-07-12)
### Bug Fixes
* **backup:** restore db and tests ([f28d0e7](https://github.com/eiblog/eiblog/commit/f28d0e77e06dd435dc13a1867f18a011e34b8f53))
### [2.2.7](https://github.com/eiblog/eiblog/compare/v2.2.6...v2.2.7) (2023-07-12)
### Bug Fixes
* **backup:** 数据恢复错误 ([ee51f67](https://github.com/eiblog/eiblog/commit/ee51f678cbf93332fedccf927704e78a6063289c))
### [2.2.6](https://github.com/eiblog/eiblog/compare/v2.2.5...v2.2.6) (2023-06-19)
### [2.2.5](https://github.com/eiblog/eiblog/compare/v2.2.4...v2.2.5) (2023-05-26)
### Bug Fixes
* **backup:** libresolv.so.2: No such file or directory ([2c6c5bb](https://github.com/eiblog/eiblog/commit/2c6c5bb97708683bed8c889a7a1076f1f88ee5a8))
### [2.2.4](https://github.com/eiblog/eiblog/compare/v2.2.3...v2.2.4) (2023-05-25)
### Bug Fixes
* **ci:** fix .dockerignore ([1509a68](https://github.com/eiblog/eiblog/commit/1509a68cda74ace6b4060b5015f20143303ca36f))
### [2.2.3](https://github.com/eiblog/eiblog/compare/v2.2.2...v2.2.3) (2023-05-25)

View File

@@ -1,4 +1,4 @@
# EiBlog [![Build Status](https://travis-ci.org/eiblog/eiblog.svg?branch=v1.3.0)](https://travis-ci.org/eiblog/eiblog) [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.md) [![Versuib](https://img.shields.io/github/tag/eiblog/eiblog.svg)](https://github.com/eiblog/eiblog/releases)
# EiBlog [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.md) [![Versuib](https://img.shields.io/github/tag/eiblog/eiblog.svg)](https://github.com/eiblog/eiblog/releases)
> 博客项目结构参考模版https://github.com/deepzz0/appdemo

View File

@@ -2,14 +2,14 @@ FROM golang:1.20 AS builder
WORKDIR /eiblog
COPY . .
RUN pwd
RUN ./scripts/run_build.sh backup
FROM alpine:latest
LABEL maintainer="deepzz.qi@gmail.com"
RUN apk add --update --no-cache tzdata ca-certificates mongodb-tools libc6-compat
RUN apk add --update --no-cache tzdata ca-certificates \
mongodb-tools libc6-compat gcompat
COPY README.md /app/README.md
COPY CHANGELOG.md /app/CHANGELOG.md
COPY LICENSE /app/LICENSE

View File

@@ -2,7 +2,6 @@ FROM golang:1.20 AS builder
WORKDIR /eiblog
COPY . .
RUN pwd
RUN ./scripts/run_build.sh eiblog

View File

@@ -2,7 +2,7 @@ appname: eiblog
database:
driver: sqlite
source: ./db.sqlite
eshost:
eshost: # http://elasticsearch:9200
eiblogapp:
mode:
name: cmd-eiblog
@@ -28,11 +28,10 @@ eiblogapp:
publickey: wdSgxRm9rdGAlLKFcFdToBe3GT4SibmV7Y8EjJQ0r4GWXeKtxpopMAeIeoI2dTEg
accesstoken: 50023908f39f4607957e909b495326af
google: # 谷歌分析
url: https://www.google-analytics.com/collect
tid: UA-xxxxxx-1
v: "1"
t: pageview
adsense: <script data-ad-client="ca-pub-5384494508691406" async src=""></script>
url: https://www.google-analytics.com/g/collect
tid: G-xxxxxxxxxx
v: "2"
adsense: <script async src="https://pagead2.googlesyndication.com/xxx" crossorigin="anonymous"></script>
qiniu: # 七牛OSS
bucket: eiblog
domain: st.deepzz.com

View File

@@ -27,6 +27,7 @@ services:
restart: always
backup:
image: deepzz0/backup:latest
#command: ./backend --restore true
volumes:
- ${PWD}/conf:/app/conf
links:

View File

@@ -34,7 +34,7 @@
![article-description](./img/article-description.png)
### 图片懒加载
博客系统提供图片懒加载功能浏览到某个位置图片才会加载以此来提高页面加载速度。我们可根据需要是否使用。当然由此带来的坏处就是rss不能够正确加载图片。后续看是否解决这个问题或朋友提PR。
博客系统提供图片懒加载功能(浏览到某个位置,图片才会加载),以此来提高页面加载速度。我们可根据需要是否使用。~~当然由此带来的坏处就是rss不能够正确加载图片。后续看是否解决这个问题或朋友提PR。~~,已解决。
首先看下图片的`markdown`标准写法:
```

View File

@@ -78,9 +78,6 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location ^~ /admin/ {
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
# https://imququ.com/post/web-security-and-response-header.html#toc-1
# 期望CT: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect-CT
add_header Expect-CT "max-age=180";
add_header Cache-Control no-cache;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
@@ -93,9 +90,6 @@ server {
location / {
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
# https://imququ.com/post/web-security-and-response-header.html#toc-1
# 期望CT: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect-CT
add_header Expect-CT "max-age=180";
add_header Cache-Control no-cache;
# 内容安全策略: https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
add_header Content-Security-Policy "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' blob: https:; img-src data: https:; media-src https:; style-src 'unsafe-inline' https:; child-src https:; connect-src 'self'; frame-src https://disqus.com";

26
go.mod
View File

@@ -4,23 +4,21 @@ go 1.15
require (
github.com/eiblog/blackfriday v0.0.0-20161010144836-c0ec111761ae
github.com/gin-contrib/sessions v0.0.3
github.com/gin-gonic/gin v1.9.0
github.com/golang/protobuf v1.5.0
github.com/lib/pq v1.10.1
github.com/gin-contrib/sessions v0.0.5
github.com/gin-gonic/gin v1.9.1
github.com/lib/pq v1.10.9
github.com/qiniu/go-sdk/v7 v7.11.0
github.com/satori/go.uuid v1.2.0
github.com/sirupsen/logrus v1.4.2
github.com/sirupsen/logrus v1.9.3
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14
github.com/swaggo/gin-swagger v1.3.3
github.com/swaggo/swag v1.7.4
go.mongodb.org/mongo-driver v1.5.1
google.golang.org/grpc v1.35.0
google.golang.org/protobuf v1.28.1
go.mongodb.org/mongo-driver v1.11.4
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/clickhouse v0.1.0
gorm.io/driver/mysql v1.0.6
gorm.io/driver/postgres v1.0.8
gorm.io/driver/sqlite v1.1.4
gorm.io/driver/sqlserver v1.0.7
gorm.io/gorm v1.21.9
gorm.io/driver/clickhouse v0.6.0
gorm.io/driver/mysql v1.5.2
gorm.io/driver/postgres v1.5.4
gorm.io/driver/sqlite v1.5.4
gorm.io/driver/sqlserver v1.5.2
gorm.io/gorm v1.25.5
)

2884
go.sum

File diff suppressed because it is too large Load Diff

View File

@@ -326,6 +326,11 @@ func (db *mongodb) LoadArticleList(ctx context.Context, search SearchArticles) (
return articles, int(count), nil
}
// DropDatabase drop eiblog database
func (db *mongodb) DropDatabase(ctx context.Context) error {
return db.Database(mongoDBName).Drop(ctx)
}
// counter counter
type counter struct {
Name string

View File

@@ -13,7 +13,7 @@ var (
store Store
acct *model.Account
blogger *model.Blogger
series *model.Series
series *model.Serie
article *model.Article
)
@@ -25,12 +25,12 @@ func init() {
}
// account
acct = &model.Account{
Username: "deepzz",
Password: "deepzz",
Email: "deepzz@example.com",
PhoneN: "12345678900",
Address: "address",
CreateTime: time.Now(),
Username: "deepzz",
Password: "deepzz",
Email: "deepzz@example.com",
PhoneN: "12345678900",
Address: "address",
CreatedAt: time.Now(),
}
// blogger
blogger = &model.Blogger{
@@ -41,11 +41,11 @@ func init() {
Copyright: "Copyright",
}
// series
series = &model.Series{
Slug: "slug",
Name: "series name",
Desc: "series desc",
CreateTime: time.Now(),
series = &model.Serie{
Slug: "slug",
Name: "series name",
Desc: "series desc",
CreatedAt: time.Now(),
}
// article
article = &model.Article{
@@ -55,21 +55,20 @@ func init() {
Count: 0,
Content: "### count",
SerieID: 0,
Tags: "",
Tags: nil,
IsDraft: false,
UpdateTime: time.Now(),
CreateTime: time.Now(),
UpdatedAt: time.Now(),
CreatedAt: time.Now(),
}
}
func TestLoadInsertAccount(t *testing.T) {
acct2, err := store.LoadInsertAccount(context.Background(), acct)
ok, err := store.LoadInsertAccount(context.Background(), acct)
if err != nil {
t.Fatal(err)
}
t.Log(acct2)
t.Log(acct == acct2)
t.Log(ok)
}
func TestUpdateAccount(t *testing.T) {
@@ -86,12 +85,11 @@ func TestUpdateAccount(t *testing.T) {
}
func TestLoadInsertBlogger(t *testing.T) {
blogger2, err := store.LoadInsertBlogger(context.Background(), blogger)
ok, err := store.LoadInsertBlogger(context.Background(), blogger)
if err != nil {
t.Fatal(err)
}
t.Log(blogger2)
t.Log(blogger == blogger2)
t.Log(ok)
}
func TestUpdateBlogger(t *testing.T) {
@@ -104,21 +102,21 @@ func TestUpdateBlogger(t *testing.T) {
}
func TestInsertSeries(t *testing.T) {
err := store.InsertSeries(context.Background(), series)
err := store.InsertSerie(context.Background(), series)
if err != nil {
t.Fatal(err)
}
}
func TestRemoveSeries(t *testing.T) {
err := store.RemoveSeries(context.Background(), 1)
err := store.RemoveSerie(context.Background(), 1)
if err != nil {
t.Fatal(err)
}
}
func TestUpdateSeries(t *testing.T) {
err := store.UpdateSeries(context.Background(), 2, map[string]interface{}{
err := store.UpdateSerie(context.Background(), 2, map[string]interface{}{
"desc": "update desc",
})
if err != nil {
@@ -127,7 +125,7 @@ func TestUpdateSeries(t *testing.T) {
}
func TestLoadAllSeries(t *testing.T) {
series, err := store.LoadAllSeries(context.Background())
series, err := store.LoadAllSerie(context.Background())
if err != nil {
t.Fatal(err)
}
@@ -136,7 +134,7 @@ func TestLoadAllSeries(t *testing.T) {
func TestInsertArticle(t *testing.T) {
article.ID = 12
err := store.InsertArticle(context.Background(), article)
err := store.InsertArticle(context.Background(), article, 10)
if err != nil {
t.Fatal(err)
}
@@ -150,14 +148,14 @@ func TestRemoveArticle(t *testing.T) {
}
func TestDeleteArticle(t *testing.T) {
err := store.DeleteArticle(context.Background(), 12)
err := store.RemoveArticle(context.Background(), 12)
if err != nil {
t.Fatal(err)
}
}
func TestCleanArticles(t *testing.T) {
err := store.CleanArticles(context.Background())
err := store.CleanArticles(context.Background(), time.Now())
if err != nil {
t.Fatal(err)
}
@@ -173,33 +171,13 @@ func TestUpdateArticle(t *testing.T) {
}
}
func TestRecoverArticle(t *testing.T) {
err := store.RecoverArticle(context.Background(), 12)
if err != nil {
t.Fatal(err)
}
}
func TestLoadAllArticle(t *testing.T) {
articles, err := store.LoadAllArticle(context.Background())
_, total, err := store.LoadArticleList(context.Background(), SearchArticles{
Page: 1,
Limit: 1000,
})
if err != nil {
t.Fatal(err)
}
t.Logf("load all articles: %d", len(articles))
}
func TestLoadTrashArticles(t *testing.T) {
articles, err := store.LoadTrashArticles(context.Background())
if err != nil {
t.Fatal(err)
}
t.Logf("load trash articles: %d", len(articles))
}
func TestLoadDraftArticles(t *testing.T) {
articles, err := store.LoadDraftArticles(context.Background())
if err != nil {
t.Fatal(err)
}
t.Logf("load draft articles: %d", len(articles))
t.Logf("load all articles: %d", total)
}

View File

@@ -3,6 +3,7 @@ package store
import (
"context"
"errors"
"time"
"github.com/eiblog/eiblog/pkg/model"
@@ -129,7 +130,7 @@ func (db *rdbms) InsertArticle(ctx context.Context, article *model.Article, star
if id < startID {
id = startID
} else {
id += 1
id++
}
article.ID = id
}
@@ -190,6 +191,11 @@ func (db *rdbms) LoadArticleList(ctx context.Context, search SearchArticles) (mo
return articles, int(count), err
}
// DropDatabase drop eiblog database
func (db *rdbms) DropDatabase(ctx context.Context) error {
return errors.New("can not drop eiblog database in rdbms")
}
// register store
func init() {
Register("mysql", &rdbms{})

View File

@@ -64,6 +64,9 @@ type Store interface {
LoadArticle(ctx context.Context, id int) (*model.Article, error)
// LoadArticleList 查找文章列表
LoadArticleList(ctx context.Context, search SearchArticles) (model.SortedArticles, int, error)
// 危险操作
DropDatabase(ctx context.Context) error
}
// Driver 存储驱动

View File

@@ -69,7 +69,6 @@ type Google struct {
URL string `yaml:"url"`
Tid string `yaml:"tid"`
V string `yaml:"v"`
T string `yaml:"t"`
AdSense string `yaml:"adsense"`
}

View File

@@ -5,8 +5,8 @@ import (
_ "github.com/eiblog/eiblog/pkg/core/backup/docs" // docs
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"github.com/swaggo/gin-swagger/swaggerFiles"
)
// RegisterRoutes register routes

View File

@@ -8,8 +8,10 @@ import (
"net/url"
"os"
"os/exec"
"path/filepath"
"time"
"github.com/eiblog/eiblog/pkg/cache/store"
"github.com/eiblog/eiblog/pkg/config"
"github.com/eiblog/eiblog/pkg/internal"
)
@@ -23,7 +25,8 @@ func (s Storage) BackupData(now time.Time) error {
case "mongodb":
return backupFromMongoDB(now)
default:
return errors.New("unsupported database source backup to qiniu")
return errors.New("unsupported source backup to qiniu: " +
config.Conf.Database.Driver)
}
}
@@ -33,7 +36,8 @@ func (s Storage) RestoreData() error {
case "mongodb":
return restoreToMongoDB()
default:
return errors.New("unsupported database source backup to qiniu")
return errors.New("unsupported source restore from qiniu: " +
config.Conf.Database.Driver)
}
}
@@ -71,7 +75,7 @@ func backupFromMongoDB(now time.Time) error {
return err
}
uploadParams := internal.UploadParams{
Name: name,
Name: filepath.Join("blog", name), // blog/eiblog-xx.tar.gz
Size: s.Size(),
Data: f,
NoCompletePath: true,
@@ -94,8 +98,9 @@ func backupFromMongoDB(now time.Time) error {
}
func restoreToMongoDB() error {
// backup file
params := internal.ContentParams{
Prefix: "eiblog",
Prefix: "blog/",
Conf: config.Conf.BackupApp.Qiniu,
}
@@ -112,6 +117,16 @@ func restoreToMongoDB() error {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*20)
defer cancel()
// drop database
store, err := store.NewStore(config.Conf.Database.Driver,
config.Conf.Database.Source)
if err != nil {
return err
}
err = store.DropDatabase(ctx)
if err != nil {
return err
}
// unarchive
arg := fmt.Sprintf("tar xzf /tmp/eiblog.tar.gz -C /tmp")
cmd := exec.CommandContext(ctx, "sh", "-c", arg)
@@ -120,7 +135,11 @@ func restoreToMongoDB() error {
return err
}
// restore
arg = fmt.Sprintf("mongorestore -h %s -d eiblog /tmp/eiblog", config.Conf.Database.Source)
u, err := url.Parse(config.Conf.Database.Source)
if err != nil {
return err
}
arg = fmt.Sprintf("mongorestore -h %s -d eiblog /tmp/eiblog", u.Host)
cmd = exec.CommandContext(ctx, "sh", "-c", arg)
return cmd.Run()
}

View File

@@ -29,6 +29,7 @@ func Start(restore bool) (err error) {
if err != nil {
return err
}
logrus.Info("timer: RestoreData success")
}
// parse duration
interval, err := ParseDuration(config.Conf.BackupApp.Interval)

View File

@@ -7,6 +7,7 @@ import (
"fmt"
htemplate "html/template"
"io/ioutil"
"math/rand"
"net/http"
"strconv"
"strings"
@@ -203,7 +204,7 @@ func handleDisqusList(c *gin.Context) {
if artc != nil {
dcs.Data.Thread = artc.Thread
}
postsList, err := internal.PostsList(slug, cursor)
postsList, err := internal.PostsList(artc, cursor)
if err != nil {
logrus.Error("hadnleDisqusList.PostsList: ", err)
dcs.ErrNo = 0
@@ -335,27 +336,34 @@ func handleDisqusCreate(c *gin.Context) {
}
// handleBeaconPage 服务端推送谷歌统计
// https://www.thyngster.com/ga4-measurement-protocol-cheatsheet/
func handleBeaconPage(c *gin.Context) {
ua := c.Request.UserAgent()
vals := c.Request.URL.Query()
vals.Set("v", config.Conf.EiBlogApp.Google.V)
vals.Set("tid", config.Conf.EiBlogApp.Google.Tid)
vals.Set("t", config.Conf.EiBlogApp.Google.T)
cookie, _ := c.Cookie("u")
vals.Set("cid", cookie)
vals.Set("dl", c.Request.Referer())
vals.Set("uip", c.ClientIP())
vals.Set("dl", c.Request.Referer()) // document location
vals.Set("en", "page_view") // event name
vals.Set("sct", "1") // Session Count
vals.Set("seg", "1") // Session Engagment
vals.Set("_uip", c.ClientIP()) // user ip
vals.Set("_p", fmt.Sprint(201226219+rand.Intn(499999999))) // random page load hash
vals.Set("_ee", "1") // external event
go func() {
req, err := http.NewRequest("POST", config.Conf.EiBlogApp.Google.URL,
strings.NewReader(vals.Encode()))
url := config.Conf.EiBlogApp.Google.URL + "?" + vals.Encode()
req, err := http.NewRequest("POST", url, nil)
if err != nil {
logrus.Error("HandleBeaconPage.NewRequest: ", err)
return
}
req.Header.Set("User-Agent", ua)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Sec-Ch-Ua", c.GetHeader("Sec-Ch-Ua"))
req.Header.Set("Sec-Ch-Ua-Platform", c.GetHeader("Sec-Ch-Ua-Platform"))
req.Header.Set("Sec-Ch-Ua-Mobile", c.GetHeader("Sec-Ch-Ua-Mobile"))
res, err := http.DefaultClient.Do(req)
if err != nil {
logrus.Error("HandleBeaconPage.Do: ", err)

View File

@@ -5,8 +5,8 @@ import (
_ "github.com/eiblog/eiblog/pkg/core/eiblog/docs" // docs
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"github.com/swaggo/gin-swagger/swaggerFiles"
)
// RegisterRoutes register routes

View File

@@ -17,11 +17,13 @@ import (
// disqus api
const (
apiPostsCount = "https://disqus.com/api/3.0/threads/set.json"
apiPostsList = "https://disqus.com/api/3.0/threads/listPosts.json"
apiPostsList = "https://disqus.com/api/3.0/threads/listPostsThreaded"
apiPostCreate = "https://disqus.com/api/3.0/posts/create.json"
apiPostApprove = "https://disqus.com/api/3.0/posts/approve.json"
apiThreadCreate = "https://disqus.com/api/3.0/threads/create.json"
apiThreadDetails = "https://disqus.com/api/3.0/threads/details.json"
disqusAPIKey = "E8Uh5l5fHZ6gD8U3KycjAIAk46f68Zw7C6eW8WSjZvCLXebZ7p0r1yrYDrLilk2F"
)
func checkDisqusConfig() error {
@@ -123,16 +125,17 @@ type postDetail struct {
}
// PostsList 评论列表
func PostsList(slug, cursor string) (*PostsListResp, error) {
func PostsList(article *model.Article, cursor string) (*PostsListResp, error) {
if err := checkDisqusConfig(); err != nil {
return nil, err
}
vals := url.Values{}
vals.Set("api_key", config.Conf.EiBlogApp.Disqus.PublicKey)
vals.Set("api_key", disqusAPIKey)
vals.Set("forum", config.Conf.EiBlogApp.Disqus.ShortName)
vals.Set("thread:ident", "post-"+slug)
vals.Set("thread", article.Thread)
vals.Set("cursor", cursor)
vals.Set("order", "popular")
vals.Set("limit", "50")
resp, err := httpGet(apiPostsList + "?" + vals.Encode())
@@ -181,7 +184,7 @@ func PostCreate(pc *PostComment) (*PostCreateResp, error) {
return nil, err
}
vals := url.Values{}
vals.Set("api_key", "E8Uh5l5fHZ6gD8U3KycjAIAk46f68Zw7C6eW8WSjZvCLXebZ7p0r1yrYDrLilk2F")
vals.Set("api_key", disqusAPIKey)
vals.Set("message", pc.Message)
vals.Set("parent", pc.Parent)
vals.Set("thread", pc.Thread)

View File

@@ -128,7 +128,7 @@ func QiniuContent(params ContentParams) ([]byte, error) {
// manager
bucketManager := storage.NewBucketManager(mac, cfg)
// list file
files, _, _, _, err := bucketManager.ListFiles(params.Conf.Bucket, params.Prefix, "", "", 2)
files, _, _, _, err := bucketManager.ListFiles(params.Conf.Bucket, params.Prefix, "", "", 1)
if err != nil {
return nil, err
}

View File

@@ -1,3 +1,3 @@
{{define "ana_js"}}
!function(e,n,o){var t=e.screen,a=encodeURIComponent,r=["dt="+a(n.title),"dr="+a(n.referrer),"ul="+(o.language||o.browserLanguage),"sd="+t.colorDepth+"-bit","sr="+t.width+"x"+t.height,"_="+ +new Date],i="?"+r.join("&");e.__beacon_img=new Image,e.__beacon_img.src="/beacon.html"+i}(window,document,navigator,location);
{{end}}
!function(e,n,o){var t=e.screen,a=encodeURIComponent,r=["dt="+a(n.title),"dr="+a(n.referrer),"ul="+(o.language||o.browserLanguage).toLowerCase(),"sd="+t.colorDepth+"-bit","sr="+t.width+"x"+t.height,"_="+ +new Date],i="?"+r.join("&");e.__beacon_img=new Image,e.__beacon_img.src="/beacon.html"+i}(window,document,navigator,location);
{{end}}