Compare commits
200 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c4fa6d08a | ||
|
|
ccb5e4546e | ||
|
|
6ce6411da0 | ||
|
|
cb2ed7cb82 | ||
|
|
ea566d1650 | ||
|
|
88dccca295 | ||
|
|
cb11a2b8db | ||
|
|
ed03a264f0 | ||
|
|
aee4194c71 | ||
|
|
b69248f6a4 | ||
|
|
24bfe528b2 | ||
|
|
23e35dcefa | ||
|
|
f4c70b46c1 | ||
|
|
e5100fa018 | ||
|
|
91e1731909 | ||
|
|
4abe528742 | ||
|
|
be0280ac56 | ||
|
|
a0b41d08bd | ||
|
|
8fcabd5e15 | ||
|
|
0a410f09f3 | ||
|
|
0fe849ae67 | ||
|
|
c06a32a268 | ||
|
|
79fccb958c | ||
|
|
8e2679e49f | ||
|
|
52fe7303f3 | ||
|
|
616248d33f | ||
|
|
6e1965a764 | ||
|
|
27bc610a31 | ||
|
|
b53fc91ce7 | ||
|
|
720387ecd5 | ||
|
|
88f23bd1a0 | ||
|
|
6a2d720d36 | ||
|
|
95e55ee13c | ||
|
|
ca293a4933 | ||
|
|
c82d73ca34 | ||
|
|
433064de00 | ||
|
|
9d71ca8198 | ||
|
|
7c938bf024 | ||
|
|
65fcc69efa | ||
|
|
d06bab72a5 | ||
|
|
95900eec1a | ||
|
|
dfae78891d | ||
|
|
c515e33e2c | ||
|
|
5b12dd625b | ||
|
|
9b918caccd | ||
|
|
2be53379e1 | ||
|
|
944e27c58a | ||
|
|
92baf970bc | ||
|
|
64a754167a | ||
|
|
af2a20c34a | ||
|
|
f28d0e77e0 | ||
|
|
9a1b4db61a | ||
|
|
c9d04aded3 | ||
|
|
ee51f678cb | ||
|
|
434c1bf168 | ||
|
|
d2de603957 | ||
|
|
e7fdf6b1db | ||
|
|
305ae0ee70 | ||
|
|
a5749fdab6 | ||
|
|
391f19e2a9 | ||
|
|
2c6c5bb977 | ||
|
|
860a85e209 | ||
|
|
2a8d9b3bbd | ||
|
|
1509a68cda | ||
|
|
7f26503247 | ||
|
|
235145ed46 | ||
|
|
20e89d6a76 | ||
|
|
d86ab71ad9 | ||
|
|
4600ed5094 | ||
|
|
5fcadd1c81 | ||
|
|
42b106d582 | ||
|
|
bb06be36fe | ||
|
|
cb3fb2d2e7 | ||
|
|
779a23cb75 | ||
|
|
e2fa96cd62 | ||
|
|
db26fb51e5 | ||
|
|
994be5d508 | ||
|
|
a5c3d33565 | ||
|
|
1ffc58eccf | ||
|
|
b6ad4e8949 | ||
|
|
41704917db | ||
|
|
f6ba716f55 | ||
|
|
b2e6c168c5 | ||
|
|
eca741896f | ||
|
|
17792e5a7e | ||
|
|
04289c633e | ||
|
|
3a5eb6fccc | ||
|
|
f6d8656c83 | ||
|
|
4690d5123b | ||
|
|
a9e8e39d34 | ||
|
|
c51055a0db | ||
|
|
445b188517 | ||
|
|
4bfff2e5e9 | ||
|
|
aa91997c0c | ||
|
|
3b2a6689be | ||
|
|
4c46be3f03 | ||
|
|
da47e9880f | ||
|
|
4f92e0d619 | ||
|
|
3a8f7d120b | ||
|
|
cf0a897ad0 | ||
|
|
418b604946 | ||
|
|
b93c320987 | ||
|
|
b24f7c0666 | ||
|
|
efe80fbc6b | ||
|
|
65b89bcae5 | ||
|
|
289b8145bc | ||
|
|
bf0ad811ff | ||
|
|
db00a9b527 | ||
|
|
38aa704198 | ||
|
|
9c58447e3b | ||
|
|
34fc5f368c | ||
|
|
daa561e67e | ||
|
|
364d293660 | ||
|
|
5170844623 | ||
|
|
7047a3599d | ||
|
|
d0c830c1e6 | ||
|
|
bf699e4957 | ||
|
|
c315737871 | ||
|
|
d844c0e8f8 | ||
|
|
f6cb55c00f | ||
|
|
a5292027c0 | ||
|
|
00cf0b5c9f | ||
|
|
6805afa759 | ||
|
|
4f6f85a85a | ||
|
|
dc3e6659b5 | ||
|
|
ca74d13598 | ||
|
|
82fba0ddb4 | ||
|
|
2b6bae1f74 | ||
|
|
6387412776 | ||
|
|
cfaa25e123 | ||
|
|
6ff6acdbda | ||
|
|
b3b3be448f | ||
|
|
78f5bfc1ce | ||
|
|
4b9eb1ff4d | ||
|
|
7d04b8f5c0 | ||
|
|
d000090e30 | ||
|
|
56e396f252 | ||
|
|
f6662fa4c5 | ||
|
|
a570c783f3 | ||
|
|
e2046d0d39 | ||
|
|
cdbe082764 | ||
|
|
3a86c6a65c | ||
|
|
c1c9e6025a | ||
|
|
a15791a792 | ||
|
|
ea87f4b2e6 | ||
|
|
a0653cf67f | ||
|
|
397d47bc00 | ||
|
|
00d9df4406 | ||
|
|
2b277bd901 | ||
|
|
c18f3b7da9 | ||
|
|
79ac024312 | ||
|
|
1e4c0afc19 | ||
|
|
055d7d2164 | ||
|
|
ed7c510744 | ||
|
|
488c0f04fe | ||
|
|
a99ed9504b | ||
|
|
6cde9323b1 | ||
|
|
2b226977ab | ||
|
|
aa076e5e3c | ||
|
|
26635790e1 | ||
|
|
569a1fe2a1 | ||
|
|
182eaff085 | ||
|
|
90e7082322 | ||
|
|
e71e42571f | ||
|
|
3527e11b04 | ||
|
|
a407bdfe72 | ||
|
|
05aa254e70 | ||
|
|
4ec3065f9d | ||
|
|
7bec238f9c | ||
|
|
605787958d | ||
|
|
c06f02622a | ||
|
|
f431bf5adc | ||
|
|
7922043bc6 | ||
|
|
2fbc5fa024 | ||
|
|
9c341f88d2 | ||
|
|
0ae5e6c9fc | ||
|
|
3e2b746319 | ||
|
|
2cd72e190e | ||
|
|
1c955769f4 | ||
|
|
a2769f0913 | ||
|
|
bf3d45a404 | ||
|
|
4b92636079 | ||
|
|
753aaa4ace | ||
|
|
43d7a26e19 | ||
|
|
872d0b1987 | ||
|
|
897b05d071 | ||
|
|
c5a3bd6eab | ||
|
|
beea4f1746 | ||
|
|
9f563f0ae9 | ||
|
|
4749b1e681 | ||
|
|
a39e3aac3b | ||
|
|
63b55b2df8 | ||
|
|
cb091532d5 | ||
|
|
6b74e1d208 | ||
|
|
1815cea2cd | ||
|
|
c3fdbfcb78 | ||
|
|
990e6abbd8 | ||
|
|
bb40570053 | ||
|
|
e2df642a46 | ||
|
|
68e01cdf1f |
@@ -1,16 +1,12 @@
|
||||
.git
|
||||
conf
|
||||
vendor
|
||||
setting
|
||||
# Ignore all files and dirs
|
||||
|
||||
|
||||
# Unignore files or dirs
|
||||
.github
|
||||
bin
|
||||
docs
|
||||
static/*.*
|
||||
!static/favicon.ico
|
||||
**/.DS_Store
|
||||
Dockerfile
|
||||
glide.yaml
|
||||
glide.lock
|
||||
*.yml
|
||||
*.go
|
||||
*.sh
|
||||
.gitignore
|
||||
.dockerignore
|
||||
db.sqlite
|
||||
docker-compose.yml
|
||||
eiblog.conf
|
||||
Makefile
|
||||
|
||||
12
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: eiblog
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
245
.github/workflows/release.yml
vendored
@@ -1,86 +1,169 @@
|
||||
name: release image & asset
|
||||
name: Release Image & Asset
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
package:
|
||||
runs-on: ubuntu-16.04
|
||||
steps:
|
||||
- name: Golang env
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ^1.15
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Cache mod
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
- name: Docker tag
|
||||
id: vars
|
||||
run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})
|
||||
- name: Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Docker login
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
registry: registry.cn-hangzhou.aliyuncs.com
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
- name: Build binary
|
||||
run: GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
tags: |
|
||||
registry.cn-hangzhou.aliyuncs.com/deepzz/eiblog:latest
|
||||
registry.cn-hangzhou.aliyuncs.com/deepzz/eiblog:${{ steps.vars.outputs.tag }}
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
id-token: write # for SLSA provenance
|
||||
attestations: write # for attestations
|
||||
|
||||
- name: Package tar
|
||||
run: ./dist.sh
|
||||
- name: Create release
|
||||
id: create_release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ steps.vars.outputs.tag }}
|
||||
release_name: Release ${{ steps.vars.outputs.tag }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
- name: Upload asset darwin
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: eiblog-${{ steps.vars.outputs.tag }}.darwin-amd64.tar.gz
|
||||
asset_name: eiblog-${{ steps.vars.outputs.tag }}.darwin-amd64.tar.gz
|
||||
asset_content_type: application/gzip
|
||||
- name: Upload asset linux
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: eiblog-${{ steps.vars.outputs.tag }}.linux-amd64.tar.gz
|
||||
asset_name: eiblog-${{ steps.vars.outputs.tag }}.linux-amd64.tar.gz
|
||||
asset_content_type: application/gzip
|
||||
- name: Upload asset windows
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: eiblog-${{ steps.vars.outputs.tag }}.windows-amd64.tar.gz
|
||||
asset_name: eiblog-${{ steps.vars.outputs.tag }}.windows-amd64.tar.gz
|
||||
asset_content_type: application/gzip
|
||||
env:
|
||||
REGISTRY: docker.io
|
||||
GOPROXY: https://goproxy.io,direct
|
||||
|
||||
jobs:
|
||||
# Job 1: 打包源码 tar 文件
|
||||
package-source:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
tag: ${{ steps.vars.outputs.tag }}
|
||||
sha: ${{ steps.vars.outputs.sha }}
|
||||
date: ${{ steps.vars.outputs.date }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache: true
|
||||
|
||||
- name: Extract metadata
|
||||
id: vars
|
||||
run: |
|
||||
echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||
echo "sha=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT
|
||||
echo "date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Package tar archive
|
||||
run: scripts/dist_tar.sh ${{ steps.vars.outputs.tag }}
|
||||
|
||||
- name: Upload tar artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-archives
|
||||
path: "*.tar.gz"
|
||||
retention-days: 7
|
||||
|
||||
# Job 2: 构建并推送 Docker 镜像
|
||||
build-images:
|
||||
runs-on: ubuntu-latest
|
||||
needs: package-source
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
app: [eiblog, backup]
|
||||
include:
|
||||
- app: eiblog
|
||||
port: 9000
|
||||
- app: backup
|
||||
port: 9001
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
with:
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Extract metadata for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/deepzz0/${{ matrix.app }}
|
||||
tags: |
|
||||
type=ref,event=tag
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
labels: |
|
||||
org.opencontainers.image.title=${{ matrix.app }}
|
||||
org.opencontainers.image.description=eiblog ${{ matrix.app }} service
|
||||
org.opencontainers.image.vendor=deepzz
|
||||
org.opencontainers.image.revision=${{ needs.package-source.outputs.sha }}
|
||||
org.opencontainers.image.created=${{ needs.package-source.outputs.date }}
|
||||
|
||||
- name: Build and push ${{ matrix.app }} image
|
||||
id: build
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: ./build/package/${{ matrix.app }}/Dockerfile
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha,scope=${{ matrix.app }}
|
||||
cache-to: type=gha,mode=max,scope=${{ matrix.app }}
|
||||
provenance: true
|
||||
sbom: true
|
||||
|
||||
- name: Generate SLSA attestation
|
||||
uses: actions/attest-build-provenance@v1
|
||||
with:
|
||||
subject-name: ${{ env.REGISTRY }}/deepzz0/${{ matrix.app }}
|
||||
subject-digest: ${{ steps.build.outputs.digest }}
|
||||
|
||||
# Job 3: 创建 GitHub Release
|
||||
create-release:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [package-source, build-images]
|
||||
steps:
|
||||
- name: Download tar artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: release-archives
|
||||
|
||||
- name: Create release summary
|
||||
run: |
|
||||
cat >> $GITHUB_STEP_SUMMARY << 'EOF'
|
||||
# 🎉 Release ${{ needs.package-source.outputs.tag }} Created!
|
||||
|
||||
## 📦 Docker Images
|
||||
- **eiblog**: `deepzz0/eiblog:${{ needs.package-source.outputs.tag }}`
|
||||
- **backup**: `deepzz0/backup:${{ needs.package-source.outputs.tag }}`
|
||||
|
||||
## 🏗️ Build Info
|
||||
- **Tag**: ${{ needs.package-source.outputs.tag }}
|
||||
- **Commit**: ${{ needs.package-source.outputs.sha }}
|
||||
- **Built**: ${{ needs.package-source.outputs.date }}
|
||||
- **Platforms**: linux/amd64, linux/arm64, linux/arm/v7
|
||||
|
||||
## 🔐 Security
|
||||
- ✅ SLSA Build Provenance
|
||||
- ✅ SBOM (Software Bill of Materials)
|
||||
- ✅ Container Signing
|
||||
EOF
|
||||
|
||||
- name: Create GitHub release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: "*.tar.gz"
|
||||
generate_release_notes: true
|
||||
name: Release ${{ needs.package-source.outputs.tag }}
|
||||
body: |
|
||||
## Docker Images
|
||||
```bash
|
||||
docker pull deepzz0/eiblog:${{ needs.package-source.outputs.tag }}
|
||||
docker pull deepzz0/backup:${{ needs.package-source.outputs.tag }}
|
||||
```
|
||||
|
||||
## Multi-Architecture Support
|
||||
- linux/amd64
|
||||
- linux/arm64
|
||||
- linux/arm/v7
|
||||
|
||||
Built with commit ${{ needs.package-source.outputs.sha }} on ${{ needs.package-source.outputs.date }}
|
||||
|
||||
26
.gitignore
vendored
@@ -1,5 +1,23 @@
|
||||
**/.DS_Store
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
conf/ssl/domain.*
|
||||
eiblog
|
||||
static/*.*
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
*.DS_Store
|
||||
*.tar.gz
|
||||
*.db
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
bin
|
||||
cmd/eiblog/etc/assets/*.xml
|
||||
cmd/eiblog/etc/assets/*.txt
|
||||
db.sqlite
|
||||
cmd/*/backend
|
||||
297
CHANGELOG.md
@@ -2,110 +2,263 @@
|
||||
|
||||
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.
|
||||
|
||||
### [1.4.9](https://github.com/eiblog/eiblog/compare/v1.4.8...v1.4.9) (2019-12-18)
|
||||
### [3.0.2](https://github.com/eiblog/eiblog/compare/v3.0.1...v3.0.2) (2025-07-25)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **disqus:** connect reset by peer ([1bdfb6a](https://github.com/eiblog/eiblog/commit/1bdfb6a))
|
||||
* ci ([ccb5e45](https://github.com/eiblog/eiblog/commit/ccb5e4546e224182c949e72e9eae82fbbe1a02fe))
|
||||
|
||||
### v1.4.4 (2018-05-07)
|
||||
### [3.0.1](https://github.com/eiblog/eiblog/compare/v3.0.0...v3.0.1) (2025-07-25)
|
||||
|
||||
* 修复基础评论分钟数计算错误
|
||||
* let's encrypt v2证书内嵌ct,故移除有关ct内容
|
||||
|
||||
### v1.4.3 (2018-02-09)
|
||||
### Bug Fixes
|
||||
|
||||
* 修复博客初始化后,about 页面不能够评论 #6
|
||||
* 修复编辑专题,按钮显示“添加专题”错误
|
||||
* 优化“添加文章”从同步改为异步推送:feed,es,disqus。速度显著提升
|
||||
* (**重要*)头像图片从 avatar.jpg 改为 avatar.png(透明)
|
||||
* docker-compose.yml mongodb 去掉端口映射,防止用户将端口暴露至外网
|
||||
* session key 每次重启随机生成等一些细节的修复
|
||||
* dist tar ([cb2ed7c](https://github.com/eiblog/eiblog/commit/cb2ed7cb8244dda8cbd8c5966c7ed02e177777e5))
|
||||
|
||||
### v1.4.2 (2018-01-25)
|
||||
## [3.0.0](https://github.com/eiblog/eiblog/compare/v2.2.17...v3.0.0) (2025-07-24)
|
||||
|
||||
* fix archive page bug
|
||||
|
||||
### v1.4.1 (2018-01-14)
|
||||
### Features
|
||||
|
||||
* 修复创建新文章,disqus 不收录bug
|
||||
* 修复创建新文章,归档页面不刷新bug
|
||||
* 修复能够删除关于页面和友情链接页面bug
|
||||
* 修复重复添加文章错误
|
||||
* 注释掉 docker-compose.yml 自动备份内容,请自行解开
|
||||
* 添加当月数大于12,归档页面使用年份归档
|
||||
* 优化代码逻辑
|
||||
* support custom page ([b69248f](https://github.com/eiblog/eiblog/commit/b69248f6a4937f8157d2393bd44c6c55174ae3e7))
|
||||
* twofactor bind ([e5100fa](https://github.com/eiblog/eiblog/commit/e5100fa018e2955c3d649b70245e3a379658d7ba))
|
||||
|
||||
### v1.4.0 (2018-01-01)
|
||||
|
||||
* fix 搜索页面 bug
|
||||
* CGO_ENABLED=0 关闭 cgo
|
||||
* 更新Makefile ct log 服务器
|
||||
* 数据库数据终于可以备份了
|
||||
### Bug Fixes
|
||||
|
||||
### v1.3.4 (2017-11-29)
|
||||
* ci ([f4c70b4](https://github.com/eiblog/eiblog/commit/f4c70b46c19d8761c252b767c92016c195299c0c))
|
||||
* ci dist tar ([24bfe52](https://github.com/eiblog/eiblog/commit/24bfe528b28b995c3d5b2c13314c8849a036942b))
|
||||
* custom page support embed ([aee4194](https://github.com/eiblog/eiblog/commit/aee4194c71dd98a7a84da96810a060f716d1ea57))
|
||||
|
||||
* fix page:admin/write-post autocomplete tag
|
||||
### [2.2.16](https://github.com/eiblog/eiblog/compare/v2.2.15...v2.2.16) (2025-03-13)
|
||||
|
||||
### v1.3.3 (2017-11-27)
|
||||
|
||||
* fix docker image: exec user process caused "no such file or directory"
|
||||
### Bug Fixes
|
||||
|
||||
### v1.3.2 (2017-11-17)
|
||||
* empty "beian" display issue ([79fccb9](https://github.com/eiblog/eiblog/commit/79fccb958c3eb8e21615389359c1d613c5fb079b))
|
||||
|
||||
* 修复文章自动保存引起的发布文章不成功的bug
|
||||
### [2.2.15](https://github.com/eiblog/eiblog/compare/v2.2.14...v2.2.15) (2024-12-31)
|
||||
|
||||
### v1.3.1 (2017-11-05)
|
||||
|
||||
* 修复调整 关于、友情链接 创建时间出现文章乱序
|
||||
* 修复评论时间计算错误
|
||||
* 调整acme文件验证路径
|
||||
* 更改七牛SDK包为github包。
|
||||
* 调整七牛配置文件名称,app.yml: kodo -> qiniu,name -> bucket,请提高静态文件版本 staticversion
|
||||
### Bug Fixes
|
||||
|
||||
### v1.3.0 (2017-07-13)
|
||||
* disqus list posts ([52fe730](https://github.com/eiblog/eiblog/commit/52fe7303f3345421c0f2e2989a6c174d5b1a689e))
|
||||
* disqus thread not store ([616248d](https://github.com/eiblog/eiblog/commit/616248d33fdf44dbc3aed41e92adae001a4f5577))
|
||||
|
||||
* 更改 app.yml 配置项,将大部分配置归在 general 常规配置下。注意,部署时请先更新 app.yml。
|
||||
* 静态文件采用动态渲染,即用户不再需要管理 view、static 目录。
|
||||
* 通过 acme.sh 使用双证书啦,可到 Makefile 查看相关信息。
|
||||
* 使用 autocert 自动生成证书功能,从此再也不用担心证书过期,移步 [证书更新](https://github.com/eiblog/eiblog/blob/master/docs/autocert.md)。
|
||||
* 开启配置项 enablehttps, 将自动重定向 http 到 https 啦。
|
||||
* disqus.js 文件由配置指定,请看 app.yml 下的 disqus 相关配置。
|
||||
### [2.2.14](https://github.com/eiblog/eiblog/compare/v2.2.13...v2.2.14) (2024-10-10)
|
||||
|
||||
### v1.2.0 (2017-06-14)
|
||||
|
||||
* 更新评论功能,基础评论 0 回复也可评论了。
|
||||
* disqus.js 文件由博主自行更新。
|
||||
* 更正描述 README.md 描述错误 [#4f996](https://github.com/eiblog/eiblog/commit/4f9965b6bdefe087dd0805c1840afcb2752cd155)。
|
||||
* docker 镜像版本化。
|
||||
### Bug Fixes
|
||||
|
||||
### v1.1.3 (2017-05-12)
|
||||
* 1. bei_an cannot update error ([b53fc91](https://github.com/eiblog/eiblog/commit/b53fc91ce7b67c3811c232ad6236898f84bc391b)), closes [#43](https://github.com/eiblog/eiblog/issues/43) [#44](https://github.com/eiblog/eiblog/issues/44)
|
||||
* **serie:** update serie did not rerender ([88f23bd](https://github.com/eiblog/eiblog/commit/88f23bd1a0d6183d6de484cb79303506f0506d15))
|
||||
|
||||
* 更新 disqus_78bca4.js 到 disqus_921d24.js,具体请参考 docs/install.md
|
||||
* 更新 vendor
|
||||
### [2.2.13](https://github.com/eiblog/eiblog/compare/v2.2.12...v2.2.13) (2024-01-02)
|
||||
|
||||
### v1.1.2 (2017-03-08)
|
||||
|
||||
* 解决添加文章描述错误的bug
|
||||
* 添加vendor目录
|
||||
* 添加文档docs目录
|
||||
* 删除多余注释
|
||||
### Bug Fixes
|
||||
|
||||
### v1.1.1 (2017-02-07)
|
||||
* load more comments ([95e55ee](https://github.com/eiblog/eiblog/commit/95e55ee13c1af13e2bb2149ccbe60013c93e4e69))
|
||||
|
||||
* 添加文章描述功能。
|
||||
* 修复评论`jQuery`文件引用错误。
|
||||
* 修复`.travis.yml`描述错误。
|
||||
### [2.2.12](https://github.com/eiblog/eiblog/compare/v2.2.11...v2.2.12) (2024-01-02)
|
||||
|
||||
### v1.0.0 (2016-01-09)
|
||||
### [2.2.11](https://github.com/eiblog/eiblog/compare/v2.2.10...v2.2.11) (2024-01-02)
|
||||
|
||||
首次发布版本
|
||||
|
||||
* 全站`HTTPS`设计,安全、极速。
|
||||
* `Elasticsearch`博客搜索系统。
|
||||
* 开源`Typecho`完整博客后台。
|
||||
* 全功能`Markdown`编辑器。
|
||||
* 异步`Google analysts`分析统计。
|
||||
* `Disqus`评论系统。
|
||||
* 后台直接对接七牛`CDN`。
|
||||
### 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)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **ci:** script file name ([20e89d6](https://github.com/eiblog/eiblog/commit/20e89d6a76f01aee60b98f8ae43a2c65b4fb3904))
|
||||
|
||||
### [2.2.2](https://github.com/eiblog/eiblog/compare/v2.2.1...v2.2.2) (2023-05-25)
|
||||
|
||||
### [2.2.1](https://github.com/eiblog/eiblog/compare/v2.2.0...v2.2.1) (2023-05-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* try to fix backup symbol not found ([bb06be3](https://github.com/eiblog/eiblog/commit/bb06be36fe016e753ca56aa2321ce7e39bffe3e0))
|
||||
|
||||
## [2.2.0](https://github.com/eiblog/eiblog/compare/v2.1.18...v2.2.0) (2023-05-17)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **backup:** add restore flag ([779a23c](https://github.com/eiblog/eiblog/commit/779a23cb75ab5059826370d08b754569a4af4aea))
|
||||
|
||||
### [2.1.18](https://github.com/eiblog/eiblog/compare/v2.1.17...v2.1.18) (2023-01-05)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **backup:** can not execute ([f6ba716](https://github.com/eiblog/eiblog/commit/f6ba716f554cfb638752875c4842e4ffb1b7e9a6))
|
||||
* disqus api using http post ([b2e6c16](https://github.com/eiblog/eiblog/commit/b2e6c168c5f63b29cf5c2884e04dd99caa677bc0))
|
||||
|
||||
### [2.1.17](https://github.com/eiblog/eiblog/compare/v2.1.16...v2.1.17) (2023-01-05)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* 1. template read panic ([f6d8656](https://github.com/eiblog/eiblog/commit/f6d8656c83591584581383643d109611d7ed2caa))
|
||||
* **disqus:** failed to commit disqus comments ([a9e8e39](https://github.com/eiblog/eiblog/commit/a9e8e39d342488ec46175997f3df9ab109f2fecf))
|
||||
* fist comment of disqus error ([17792e5](https://github.com/eiblog/eiblog/commit/17792e5a7edb7e84623d9307555e7983ba306565))
|
||||
|
||||
### [2.1.16](https://github.com/eiblog/eiblog/compare/v2.1.15...v2.1.16) (2022-11-20)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **backup:** error path in compressed file ([aa91997](https://github.com/eiblog/eiblog/commit/aa91997c0caca27e9979692879f8877765dabd9d))
|
||||
* rss image path incorrect: data-src -> src ([4bfff2e](https://github.com/eiblog/eiblog/commit/4bfff2e5e9b0efb4112a5f2f6bc55eebcef1c6eb))
|
||||
|
||||
### [2.1.15](https://github.com/eiblog/eiblog/compare/v2.1.14...v2.1.15) (2022-09-28)
|
||||
|
||||
### [2.1.14](https://github.com/eiblog/eiblog/compare/v2.1.13...v2.1.14) (2022-09-28)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* cgo and sqlite build in alpine image closed [#28](https://github.com/eiblog/eiblog/issues/28) ([b93c320](https://github.com/eiblog/eiblog/commit/b93c320987a936db6e5ca50c547022de9ab9a0f1))
|
||||
|
||||
### [2.1.13](https://github.com/eiblog/eiblog/compare/v2.1.12...v2.1.13) (2022-09-27)
|
||||
|
||||
### [2.1.12](https://github.com/eiblog/eiblog/compare/v2.1.11...v2.1.12) (2022-08-09)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* [#35](https://github.com/eiblog/eiblog/issues/35) no pubDate added for feed generation ([289b814](https://github.com/eiblog/eiblog/commit/289b8145bcdabd0060c9a0d5f40f5df69d3882d3))
|
||||
|
||||
### [2.1.11](https://github.com/eiblog/eiblog/compare/v2.1.10...v2.1.11) (2022-07-19)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **backup:** configuration error ([38aa704](https://github.com/eiblog/eiblog/commit/38aa704198070d3e1436b230b40b1deb3e94c5ac))
|
||||
|
||||
### [2.1.10](https://github.com/eiblog/eiblog/compare/v2.1.9...v2.1.10) (2022-04-22)
|
||||
|
||||
### [2.1.9](https://github.com/eiblog/eiblog/compare/v2.1.8...v2.1.9) (2022-02-14)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **eiblog:** comments title error ([5170844](https://github.com/eiblog/eiblog/commit/517084462336ce01c3f79099c1e54297979f5877))
|
||||
|
||||
### [2.1.8](https://github.com/eiblog/eiblog/compare/v2.1.7...v2.1.8) (2021-11-18)
|
||||
|
||||
### [2.1.7](https://github.com/eiblog/eiblog/compare/v2.1.6...v2.1.7) (2021-11-13)
|
||||
|
||||
### [2.1.6](https://github.com/eiblog/eiblog/compare/v2.1.5...v2.1.6) (2021-11-12)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **backup:** backup to qiniu, app.yml->validity change to int ([00cf0b5](https://github.com/eiblog/eiblog/commit/00cf0b5c9f787f3f45f1747b7cb1742c417c6dd6))
|
||||
|
||||
### [2.1.5](https://github.com/eiblog/eiblog/compare/v2.1.4...v2.1.5) (2021-10-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **release:** golang env ([4f6f85a](https://github.com/eiblog/eiblog/commit/4f6f85a85ae56849c49e91d76bbbce1790f16e29))
|
||||
|
||||
### [2.1.4](https://github.com/eiblog/eiblog/compare/v2.1.3...v2.1.4) (2021-10-26)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **release:** github action runner ([82fba0d](https://github.com/eiblog/eiblog/commit/82fba0ddb47c1f66cb659f775c120c08dd2b4447))
|
||||
|
||||
### [2.1.4](https://github.com/eiblog/eiblog/compare/v2.1.3...v2.1.4) (2021-10-26)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **release:** github action runner ([82fba0d](https://github.com/eiblog/eiblog/commit/82fba0ddb47c1f66cb659f775c120c08dd2b4447))
|
||||
|
||||
### [2.1.3](https://github.com/eiblog/eiblog/compare/v2.1.2...v2.1.3) (2021-10-15)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **auto_save:** fix auto save return empty id ([cfaa25e](https://github.com/eiblog/eiblog/commit/cfaa25e1239aba580e0718d40f1a2bf31158b217))
|
||||
* backup app judge db driver ([78f5bfc](https://github.com/eiblog/eiblog/commit/78f5bfc1ce017bf77a7442f40963a706e608df51))
|
||||
* **pwd:** fix init pwd ([7d04b8f](https://github.com/eiblog/eiblog/commit/7d04b8f5c0846bcd0c7e07d0fc3704a535f6360a))
|
||||
|
||||
### [2.1.2](https://github.com/eiblog/eiblog/compare/v2.1.1...v2.1.2) (2021-07-27)
|
||||
|
||||
### [2.1.1](https://github.com/eiblog/eiblog/compare/v2.1.0...v2.1.1) (2021-07-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* sqlite error ([e2046d0](https://github.com/eiblog/eiblog/commit/e2046d0d39d9914473fe7b8fae3b18246ed133ce))
|
||||
|
||||
### [2.0.6](https://github.com/eiblog/eiblog/compare/v2.0.5...v2.0.6) (2021-05-08)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* workdir loop ([2b277bd](https://github.com/eiblog/eiblog/commit/2b277bd90188d53b90fddd0f6a8edad00f888f53))
|
||||
* workdir path error ([c18f3b7](https://github.com/eiblog/eiblog/commit/c18f3b7da96e3181b40867a88f9c8cad042d2f44))
|
||||
|
||||
## [1.1.0](https://github.com/deepzz0/appdemo/compare/v1.0.0...v1.1.0) (2020-12-18)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **docker:** make build, build docker image ([3ac2b8b](https://github.com/deepzz0/appdemo/commit/3ac2b8b2efadf024dfcf58e7ef8341b1a89cf1b1))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* config path fixed [#1](https://github.com/deepzz0/appdemo/issues/1) ([4343eb4](https://github.com/deepzz0/appdemo/commit/4343eb44e8fffc6825be57393e024c75c4f68b7b))
|
||||
|
||||
## 1.0.0 (2020-10-31)
|
||||
|
||||
10
Dockerfile
@@ -1,10 +0,0 @@
|
||||
FROM alpine
|
||||
MAINTAINER deepzz <deepzz.qi@gmail.com>
|
||||
|
||||
RUN apk add --update --no-cache ca-certificates
|
||||
ADD static/tzdata/Shanghai /etc/localtime
|
||||
|
||||
COPY . /eiblog
|
||||
EXPOSE 9000
|
||||
WORKDIR /eiblog
|
||||
CMD ["sh","-c","/eiblog/eiblog"]
|
||||
3
LICENSE
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 deepzz deepzz.qi@gmail.com
|
||||
Copyright (c) 2020-NOW deepzz0 <deepzz.qi@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
82
Makefile
@@ -1,73 +1,27 @@
|
||||
.PHONY: test build deploy dist gencert dhparams ssticket makedir clean
|
||||
# use aliyun dns api to auto renew cert.
|
||||
# env:
|
||||
# export Ali_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
|
||||
# export Ali_Secret="jlsdflanljkljlfdsaklkjflsa"
|
||||
.PHONY: demo build swag
|
||||
|
||||
docker_registry?=registry.cn-hangzhou.aliyuncs.com
|
||||
acme?=~/.acme.sh
|
||||
acme.sh?=$(acme)/acme.sh
|
||||
config?=/data/eiblog/conf
|
||||
tag=`git describe --abbrev=0 --tags`
|
||||
|
||||
swag:
|
||||
@scripts/swag_init.sh
|
||||
|
||||
test:
|
||||
_app:
|
||||
@scripts/new_app.sh
|
||||
|
||||
mongodb:
|
||||
@if ! docker ps | grep mongodb; then \
|
||||
docker run -d --name mongodb -v mongo-data:/data/db -p 27018:27017 mongo:3.2; \
|
||||
fi
|
||||
# below you should write
|
||||
|
||||
run: mongodb
|
||||
@echo "run eiblog..."
|
||||
@go build && ./eiblog
|
||||
# run eiblog app
|
||||
eiblog:
|
||||
@scripts/run_app.sh eiblog
|
||||
|
||||
build:
|
||||
@echo "go build..."
|
||||
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build && \
|
||||
docker build -t $(docker_registry)/deepzz/eiblog:latest .
|
||||
|
||||
deploy:build
|
||||
@docker push $(docker_registry)/deepzz/eiblog:latest
|
||||
# run backup app
|
||||
backup:
|
||||
@scripts/run_app.sh backup
|
||||
|
||||
# dist tar
|
||||
dist:
|
||||
@./dist.sh
|
||||
@scripts/dist_tar.sh $(tag)
|
||||
|
||||
gencert:makedir
|
||||
@if [ ! -n "$(sans)" ]; then \
|
||||
printf "Need one argument [sans=params]\n"; \
|
||||
printf "example: sans=\"-d domain -d *.domain\"\n"; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
if [ ! -n "$(cn)" ]; then \
|
||||
printf "Need one argument [cn=params]\n"; \
|
||||
printf "example: cn=domain\n"; \
|
||||
exit 1; \
|
||||
fi
|
||||
@if [ ! -f $(acme.sh) ]; then \
|
||||
curl https://get.acme.sh | sh; \
|
||||
fi
|
||||
|
||||
@echo "generate rsa cert..."
|
||||
@$(acme.sh) --force --issue --dns dns_ali $(sans) \
|
||||
--renew-hook "$(acme.sh) --install-cert -d $(cn) \
|
||||
--key-file $(config)/ssl/domain.rsa.key \
|
||||
--fullchain-file $(config)/ssl/domain.rsa.pem \
|
||||
--reloadcmd \"service nginx force-reload\""
|
||||
|
||||
@echo "generate ecc cert..."
|
||||
@$(acme.sh) --force --issue --dns dns_ali $(sans) -k ec-256 \
|
||||
--renew-hook "$(acme.sh) --install-cert -d $(cn) --ecc \
|
||||
--key-file $(config)/ssl/domain.ecc.key \
|
||||
--fullchain-file $(config)/ssl/domain.ecc.pem \
|
||||
--reloadcmd \"service nginx force-reload\""
|
||||
|
||||
dhparams:
|
||||
@openssl dhparam -out $(config)/ssl/dhparams.pem 2048
|
||||
|
||||
ssticket:
|
||||
@openssl rand 48 > $(config)/ssl/session_ticket.key
|
||||
|
||||
makedir:
|
||||
@mkdir -p $(config)/ssl
|
||||
|
||||
clean:
|
||||
# protoc
|
||||
protoc:
|
||||
@cd pkg/proto && make protoc
|
||||
|
||||
158
README.md
@@ -1,94 +1,106 @@
|
||||
# EiBlog [](https://travis-ci.org/eiblog/eiblog) [](LICENSE.md) [](https://github.com/eiblog/eiblog/releases)
|
||||
# EiBlog [](LICENSE.md) [](https://github.com/eiblog/eiblog/releases)
|
||||
|
||||
> 系统根据[https://imququ.com](https://imququ.com)一系列文章和方向进行搭建,期间获得了QuQu的很大帮助,在此表示感谢。
|
||||
> 博客项目结构参考模版:https://github.com/deepzz0/appdemo
|
||||
|
||||
用过其它博客系统,不喜欢,不够轻,不够快!自己做过共两款博客系统,完美主义的我(毕竟处女座)也实在是不想再在这件事情上过多纠结了。`Eiblog` 应该是一个比较稳定的博客系统,且是博主以后使用的博客系统,稳定性和维护你是不用担心的,唯独该系统部署过程太过复杂,并且不推荐没有计算机知识的朋友搭建,欢迎咨询。该博客的个中优点(明显快,安全),等你体验。
|
||||
用过其它博客系统,不喜欢,不够轻,不够快!这是我开发的第二款博客系统,也实在不想再在这件事情上过多纠结了。`EiBlog` 是一个比较稳定的博客系统,现已迭代至 `2.0` 版本,稳定性和维护你是不用担心的。
|
||||
|
||||
<!--more-->
|
||||
但它有着部署简单(上线复杂!)的特点,不推荐没有计算机知识的朋友搭建,欢迎咨询。该博客的个中优点(简洁、轻快,安全),等你体验。
|
||||
|
||||
### 介绍
|
||||
Docker镜像地址:
|
||||
|
||||
整个博客系统涉及到模块如下:
|
||||
* 博客服务:[deepzz0/eiblog](https://hub.docker.com/r/deepzz0/eiblog)
|
||||
* 博客搜索:[deepzz0/elasticsearch](https://hub.docker.com/r/deepzz0/elasticsearch)
|
||||
* 数据备份:[deepzz0/backup](https://hub.docker.com/r/deepzz0/backup)
|
||||
|
||||
* 自动更新证书:
|
||||
* 接入 [acme/autocert](https://github.com/golang/crypto/tree/master/acme/autocert),在 TLS 层开启全自动更新证书,从此证书的更新再也不用惦记了,不过 Go 的 HTTPS 兼容性不够好(不想兼容),在如部分 IE 和 UC 之类的浏览器不能访问,请悉知。
|
||||
* 如果你采用如 Nginx 代理,推荐使用 [acme.sh](https://github.com/Neilpang/acme.sh) 实现证书的自动部署。博主实现 aliyun dns 的自动验证方式,详见 [Makefile/gencert](https://github.com/eiblog/eiblog/blob/master/Makefile)。
|
||||
* `MongoDB`,博客采用 mongodb 作为存储数据库。
|
||||
* `Elasticsearch`,采用 `elasticsearch` 作为博客的站内搜索,尽管占用内存稍高。
|
||||
* `Disqus`,作为博客评论系统,国内大部分被墙,故实现两种评论方式。
|
||||
* `Nginx`,作为反向代理服务器,并做相关 `http header` 和证书的设置。
|
||||
* `Google Analytics`,作为博客系统的数据分析统计工具。
|
||||
* `七牛 CDN`,作为博客系统的静态文件存储,博文的图片附件什么上传至这里。
|
||||
### 快速体验
|
||||
|
||||
### 图片展示
|
||||
**二进制**
|
||||
|
||||
可以容易的看到 [httpsecurityreport](https://httpsecurityreport.com/?report=deepzz.com) 评分`96`,[ssllabs](https://www.ssllabs.com/ssltest/analyze.html?d=deepzz.com&latest) 评分`A+`,[myssl](https://myssl.com/deepzz.com) 评分`A+`,堪称完美。这些安全的相关配置会在后面的部署过程中接触到。
|
||||
1、下载压缩包,到 [这里](https://github.com/eiblog/eiblog/releases) 下载 eiblog(非backup) 相应系统压缩包,然后解压缩。
|
||||
|
||||
相关图片展示:
|
||||

|
||||
2、启动服务:`./backend`
|
||||
|
||||

|
||||
**Docker**
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
> `注`:图片1,图片2是博客界面,图片3是后台界面,图片4是内存占用。
|
||||
|
||||
### 极速体验
|
||||
`eiblog` 默认监听 `:9000` 端口,默认连接 `MongoDB` 地址 `mongodb:27017`,默认连接 `Elasticsearch` 地址 `http://elasticsearch:9200`。
|
||||
|
||||
1、手动启动执行
|
||||
|
||||
1. 到 [这里](https://github.com/eiblog/eiblog/releases) 下载对应平台 `.tar.gz` 文件。
|
||||
2. 搭建 `MongoDB`(必须)和 `Elasticsearch`(可选)服务,正式部署需要。
|
||||
3. `MongoDB` 服务地址也可通过环境变量指定连接地址如:`export EIBLOG_MGO_ADDR=127.0.0.1:27017`。
|
||||
4. 执行 `./eiblog`,运行博客系统。看到 `...Listening and serving HTTP on :9000` 代表运行成功了。
|
||||
|
||||
默认监听 `HTTP 9000` 端口,后台 `/admin/login`,默认账号密码均为 `deepzz`。更多详细请查阅 [安装部署](https://github.com/eiblog/eiblog/blob/master/docs/install.md) 文档。
|
||||
|
||||
2、Docker 与 Go 环境
|
||||
|
||||
如果你有 `docker` 和 `go` 环境,可直接使用如下命令启动:
|
||||
```
|
||||
$ EIBLOG_MGO_ADDR=127.0.0.1:27017 make run
|
||||
$ docker run --name eiblog \
|
||||
-p 9000:9000 \
|
||||
deepzz0/eiblog:latest
|
||||
```
|
||||
请提前指定 `mongodb` 的连接地址。该命令会启动一个 `mognodb` 容器,然后编译 `eiblog` 并运行。
|
||||
|
||||
### 特色功能
|
||||
**Compose**
|
||||
|
||||
作为博主之心血之作,`Eiblog` 实现了什么功能,有什么特点,做了什么优化呢?
|
||||
参考项目根目录下的 [docker-compose.yml](https://github.com/eiblog/eiblog/blob/v2/docker-compose.yml),修改相关配置:
|
||||
|
||||
1. 系统目前只有 `首页`、`专题`、`归档`、`友链`、`关于`、`搜索` 界面。相信已经可以满足大部分用户的需求。
|
||||
2. `.js`、`.css` 等静态文件本地存储,小图片 base64 内置到 css 中,不会产生网络所带来的延迟,加速网页访问。版本控制方式,动态更新静态文件。
|
||||
3. 采用谷歌统计,并实现异步(将访问信息发给后端,后端提交给谷歌)统计,加速访问速度。
|
||||
4. 采用直接缓存 markdown 转过的 html 文档的方式,加速后端处理。响应速度均在 3ms 以内,真正极速。
|
||||
5. 通过 Nginx 的配置,开启压缩缩小传输量,服务器传输证书链、开启 `Session Resumption`、`Session Ticket`、`OCSP Stapling `等加速证书握手,再次提高速度。
|
||||
* `CDN`,使用七牛融合CDN,并 `https` 化,实现全站 `https`。七牛可申请免费证书了。
|
||||
* `CT`,证书透明度检测,提供一个开放的审计和监控系统。可以让任何域名所有者或者 CA 确定证书是否被错误签发或者被恶意使用,从而提高 HTTPS 网站的安全性。
|
||||
* `OSCP`,在线证书状态协议。用来检验证书合法性的在线查询服务.
|
||||
* `HSTS`,强制客户端(如浏览器)使用 HTTPS 与服务器创建连接。可以很好的解决 HTTPS 降级攻击。
|
||||
* `HPKP`,HTTP 公钥固定扩展,防范由「伪造或不正当手段获得网站证书」造成的中间人攻击。该功能让我们选择信任哪些`CA`。请不要轻易尝试 Nginx 线上运行,因为该配置目前只指定了 Letsencrypt X3 和 TrustAsia G5 证书 pin-sha256。
|
||||
* `SSL Protocols`,罗列支持的 `TLS` 协议,SSLv3 被证实是不安全的。
|
||||
* `SSL dhparam`,迪菲赫尔曼密钥交换。
|
||||
* `Cipher suite`,罗列服务器支持加密套件。
|
||||
6. 文章评论数量(不重要)后端跑定时脚本,定时更新,所以有时评论数是不对的。这样减少了 api 调用,又再次达到加速访问的目的。
|
||||
7. 针对 `disqus` 被墙原因,实现 [Jerry Qu](https://imququ.com) 的另类评论方式,保证评论的流畅。
|
||||
8. 开源 `Typecho` 完整后台系统,全功能 `markdown` 编辑器,让你体验什么是简洁清爽。
|
||||
9. 博客后台直接对接 `七牛 SDK`,实现后台上传文件和删除文件的简单功能。
|
||||
10. 采用 `Elasticsearch` 作为站内搜索,结合 `google opensearch` 功能,搜索更加自然。
|
||||
11. 自动备份数据库数据到七牛云。
|
||||
```
|
||||
$ docker compose up -d
|
||||
或
|
||||
$ docker-compose up -d
|
||||
```
|
||||
|
||||
### 文档
|
||||
然后访问 `localhost:9000` 就可以了,后台地址 `localhost:9000/admin/login`,默认账户密码 `deepzz/deepzz`。
|
||||
|
||||
* [证书更新](https://github.com/eiblog/eiblog/blob/master/docs/autocert.md)
|
||||
* [安装部署](https://github.com/eiblog/eiblog/blob/master/docs/install.md)
|
||||
* [写作需知](https://github.com/eiblog/eiblog/blob/master/docs/writing.md)
|
||||
* [好玩的功能](https://github.com/eiblog/eiblog/blob/master/docs/amusing.md)
|
||||
* [关于备份](https://github.com/eiblog/backup)
|
||||
> 默认情况下未开启博客搜索 `elasticsearch`,需要的话需要启动 es 服务并修改配置 `app.yml`。
|
||||
|
||||
### 成功搭建者博客
|
||||
**数据库支持**
|
||||
|
||||
* [https://blog.netcj.com](https://blog.netcj.com) - Razeen's Blog
|
||||
| 类型(driver) | 地址(source)示例 |
|
||||
| -------------- | ------------------------------------------------------------ |
|
||||
| mongodb | mongodb://localhost:27017 |
|
||||
| mysql | user:password@tcp(localhost:3306)/eiblog?charset=utf8mb4&parseTime=True&loc=Local |
|
||||
| postgres | host=localhost port=5432 user=user password=password dbname=eiblog sslmode=disable |
|
||||
| sqlite | /path/eiblog.db |
|
||||
| sqlserver | sqlserver://user:password@localhost:9930?database=eiblog |
|
||||
| clickhouse | tcp://localhost:9000?database=eiblog&username=user&password=password&read_timeout=10&write_timeout=20 |
|
||||
|
||||
### 功能特性
|
||||
|
||||
本着博客本质用来分享知识的特点,`EiBlog` 不会有较强的定制功能(包括主题,CDN支持等),仅保持常用简单页面与功能:
|
||||
|
||||
```
|
||||
首页、专题、归档、友链、关于、搜索
|
||||
```
|
||||
|
||||
功能说明:
|
||||
|
||||
* 博客归档,利用时间线帮助我们将归纳博文,内容少于一年按月归档,大于则按年归档。
|
||||
* 博客专题,有时候博文是同一系列,专题能够帮助我们很好归纳博文,对阅读者是非常友好的。
|
||||
* 标签系统,每篇博文都可以打上不同标签,使得在归档和专题不满足的情况下自定义归档,这块辅助搜索简直完美。
|
||||
* 搜索系统,依托ElasticSearch实现的站内搜索,速度与效率并存,再加上google opensearch,搜索只流畅。
|
||||
* 管理后台,内嵌全功能 `Typecho` 后台系统,全功能 `Markdown` 编辑器让你感觉什么是简洁清爽。
|
||||
* 谷歌统计,由于google api的速度问题,从而实现了后端API异步统计,使得博客页面加载飞速。
|
||||
* Disqus评论,国内评论系统不友好,因此选择disqus,又由于众所周知原因国内不能用,实现另类disqus评论方式。
|
||||
* 多存储后端,支持mongodb、mysql、postgres、sqlite等存储后端。
|
||||
* 七牛CDN,支持在 `Markdown` 编辑器直接上传附件,让你只考虑编辑内容,解放思想。
|
||||
* 自动备份,支持多存储后端的备份功能,备份数据保存到七牛CDN上。
|
||||
|
||||
当然,为了让整个系统加载速度更快,还做了更多优化措施:
|
||||
|
||||
* 文章评论数量(不重要)通过后端跑定时任务获取,所以有时评论数量是不对的,这样减少了 API 调用。
|
||||
* 整站内容全部内存缓存,`mardown` 文档全部转换为 html 进行缓存,减少了转换过程。
|
||||
* `.js`、`.css` 等静态文件浏览器本地存储,小图片 base64 内置到 css 中,二次访问不会产生网络带来的延迟,加速访问。通过版本控制更新。
|
||||
* 最佳实践 nginx 配置,可以查看 `eiblog.conf`,开启压缩缩小传输量,服务器传输证书链、开启 `Session Resumption`、`Session Ticket`、`OCSP Stapling `等加速证书握手,再次提高速度。
|
||||
|
||||
### 博客页面
|
||||
|
||||
可以容易的看到 [ssllabs](https://www.ssllabs.com/ssltest/analyze.html?d=deepzz.com&latest) 评分`A+`,[myssl](https://myssl.com/deepzz.com) 评分`A+`,堪称完美。这些安全的相关配置会在后面的部署过程中接触到。
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
### 更多文档
|
||||
|
||||
* [安装部署](https://eiblog.github.io/eiblog/install)
|
||||
* [写作须知](https://eiblog.github.io/eiblog/writing)
|
||||
* [好玩功能](https://eiblog.github.io/eiblog/amusing)
|
||||
* [如何备份](https://eiblog.github.io/eiblog/backup)
|
||||
|
||||
### 贡献成员
|
||||
|
||||

|
||||
|
||||
### 授权许可
|
||||
|
||||
本项目采用 MIT 开源授权许可证,完整的授权说明已放置在 [LICENSE](https://github.com/eiblog/eiblog/blob/master/LICENSE) 文件中。
|
||||
|
||||
如果你的博客使用`Eiblog`搭建,你可以在 [这里](https://github.com/eiblog/eiblog/issues/1) 提交网址。
|
||||
|
||||
448
api.go
@@ -1,448 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/eiblog/setting"
|
||||
"github.com/eiblog/utils/logd"
|
||||
"github.com/eiblog/utils/mgo"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
const (
|
||||
// 成功
|
||||
NOTICE_SUCCESS = "success"
|
||||
// 注意
|
||||
NOTICE_NOTICE = "notice"
|
||||
// 错误
|
||||
NOTICE_ERROR = "error"
|
||||
)
|
||||
|
||||
// 全局 API
|
||||
var APIs = make(map[string]func(c *gin.Context))
|
||||
|
||||
func init() {
|
||||
// 更新账号信息
|
||||
APIs["account"] = apiAccount
|
||||
// 更新博客信息
|
||||
APIs["blog"] = apiBlog
|
||||
// 更新密码
|
||||
APIs["password"] = apiPassword
|
||||
// 删除文章
|
||||
APIs["post-delete"] = apiPostDelete
|
||||
// 添加文章
|
||||
APIs["post-add"] = apiPostAdd
|
||||
// 删除专题
|
||||
APIs["serie-delete"] = apiSerieDelete
|
||||
// 添加专题
|
||||
APIs["serie-add"] = apiSerieAdd
|
||||
// 专题排序
|
||||
APIs["serie-sort"] = apiSerieSort
|
||||
// 删除草稿箱
|
||||
APIs["draft-delete"] = apiDraftDelete
|
||||
// 删除回收箱
|
||||
APIs["trash-delete"] = apiTrashDelete
|
||||
// 恢复回收箱
|
||||
APIs["trash-recover"] = apiTrashRecover
|
||||
// 上传文件
|
||||
APIs["file-upload"] = apiFileUpload
|
||||
// 删除文件
|
||||
APIs["file-delete"] = apiFileDelete
|
||||
}
|
||||
|
||||
// 更新账号信息,Email、PhoneNumber、Address
|
||||
func apiAccount(c *gin.Context) {
|
||||
e := c.PostForm("email")
|
||||
pn := c.PostForm("phoneNumber")
|
||||
ad := c.PostForm("address")
|
||||
logd.Debug(e, pn, ad)
|
||||
if (e != "" && !CheckEmail(e)) || (pn != "" && !CheckSMS(pn)) {
|
||||
responseNotice(c, NOTICE_NOTICE, "参数错误", "")
|
||||
return
|
||||
}
|
||||
|
||||
err := UpdateAccountField(mgo.M{"$set": mgo.M{"email": e, "phonen": pn, "address": ad}})
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
Ei.Email = e
|
||||
Ei.PhoneN = pn
|
||||
Ei.Address = ad
|
||||
responseNotice(c, NOTICE_SUCCESS, "更新成功", "")
|
||||
}
|
||||
|
||||
// 更新博客信息
|
||||
func apiBlog(c *gin.Context) {
|
||||
bn := c.PostForm("blogName")
|
||||
bt := c.PostForm("bTitle")
|
||||
ba := c.PostForm("beiAn")
|
||||
st := c.PostForm("subTitle")
|
||||
ss := c.PostForm("seriessay")
|
||||
as := c.PostForm("archivessay")
|
||||
if bn == "" || bt == "" {
|
||||
responseNotice(c, NOTICE_NOTICE, "参数错误", "")
|
||||
return
|
||||
}
|
||||
|
||||
err := UpdateAccountField(mgo.M{"$set": mgo.M{"blogger.blogname": bn,
|
||||
"blogger.btitle": bt, "blogger.beian": ba, "blogger.subtitle": st,
|
||||
"blogger.seriessay": ss, "blogger.archivessay": as}})
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
Ei.BlogName = bn
|
||||
Ei.BTitle = bt
|
||||
Ei.BeiAn = ba
|
||||
Ei.SubTitle = st
|
||||
Ei.SeriesSay = ss
|
||||
Ei.ArchivesSay = as
|
||||
Ei.CH <- SERIES_MD
|
||||
Ei.CH <- ARCHIVE_MD
|
||||
responseNotice(c, NOTICE_SUCCESS, "更新成功", "")
|
||||
}
|
||||
|
||||
// 更新密码
|
||||
func apiPassword(c *gin.Context) {
|
||||
logd.Debug(c.Request.PostForm.Encode())
|
||||
od := c.PostForm("old")
|
||||
nw := c.PostForm("new")
|
||||
cf := c.PostForm("confirm")
|
||||
if nw != cf {
|
||||
responseNotice(c, NOTICE_NOTICE, "两次密码输入不一致", "")
|
||||
return
|
||||
}
|
||||
if !CheckPwd(nw) {
|
||||
responseNotice(c, NOTICE_NOTICE, "密码格式错误", "")
|
||||
return
|
||||
}
|
||||
if !VerifyPasswd(Ei.Password, Ei.Username, od) {
|
||||
responseNotice(c, NOTICE_NOTICE, "原始密码不正确", "")
|
||||
return
|
||||
}
|
||||
newPwd := EncryptPasswd(Ei.Username, nw)
|
||||
|
||||
err := UpdateAccountField(mgo.M{"$set": mgo.M{"password": newPwd}})
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
Ei.Password = newPwd
|
||||
responseNotice(c, NOTICE_SUCCESS, "更新成功", "")
|
||||
}
|
||||
|
||||
// 删除文章,软删除:移入到回收箱
|
||||
func apiPostDelete(c *gin.Context) {
|
||||
var ids []int32
|
||||
for _, v := range c.PostFormArray("cid[]") {
|
||||
i, err := strconv.Atoi(v)
|
||||
if err != nil || int32(i) < setting.Conf.General.StartID {
|
||||
responseNotice(c, NOTICE_NOTICE, "参数错误", "")
|
||||
return
|
||||
}
|
||||
ids = append(ids, int32(i))
|
||||
}
|
||||
err := DelArticles(ids...)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
|
||||
// elasticsearch
|
||||
err = ElasticDelIndex(ids)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
}
|
||||
// TODO disqus delete
|
||||
responseNotice(c, NOTICE_SUCCESS, "删除成功", "")
|
||||
}
|
||||
|
||||
func apiPostAdd(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
do string
|
||||
cid int
|
||||
)
|
||||
defer func() {
|
||||
switch do {
|
||||
case "auto": // 自动保存
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"fail": FAIL, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"success": SUCCESS, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
|
||||
case "save", "publish": // 草稿,发布
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
uri := "/admin/manage-draft"
|
||||
if do == "publish" {
|
||||
uri = "/admin/manage-posts"
|
||||
}
|
||||
c.Redirect(http.StatusFound, uri)
|
||||
}
|
||||
}()
|
||||
|
||||
do = c.PostForm("do") // auto or save or publish
|
||||
slug := c.PostForm("slug")
|
||||
title := c.PostForm("title")
|
||||
text := c.PostForm("text")
|
||||
date := CheckDate(c.PostForm("date"))
|
||||
serie := c.PostForm("serie")
|
||||
tag := c.PostForm("tags")
|
||||
update := c.PostForm("update")
|
||||
if slug == "" || title == "" || text == "" {
|
||||
err = errors.New("参数错误")
|
||||
return
|
||||
}
|
||||
var tags []string
|
||||
if tag != "" {
|
||||
tags = strings.Split(tag, ",")
|
||||
}
|
||||
serieid := CheckSerieID(serie)
|
||||
artc := &Article{
|
||||
Title: title,
|
||||
Content: text,
|
||||
Slug: slug,
|
||||
CreateTime: date,
|
||||
IsDraft: do != "publish",
|
||||
Author: Ei.Username,
|
||||
SerieID: serieid,
|
||||
Tags: tags,
|
||||
}
|
||||
cid, err = strconv.Atoi(c.PostForm("cid"))
|
||||
// 新文章
|
||||
if err != nil || cid < 1 {
|
||||
err = AddArticle(artc)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return
|
||||
}
|
||||
cid = int(artc.ID)
|
||||
if !artc.IsDraft {
|
||||
// 异步执行,快
|
||||
go func() {
|
||||
// elastic
|
||||
ElasticIndex(artc)
|
||||
// rss
|
||||
DoPings(slug)
|
||||
// disqus
|
||||
ThreadCreate(artc)
|
||||
}()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 旧文章
|
||||
artc.ID = int32(cid)
|
||||
_, a := GetArticle(artc.ID)
|
||||
if a != nil {
|
||||
artc.IsDraft = false
|
||||
artc.Count = a.Count
|
||||
artc.UpdateTime = a.UpdateTime
|
||||
}
|
||||
if CheckBool(update) {
|
||||
artc.UpdateTime = time.Now()
|
||||
}
|
||||
// 数据库更新
|
||||
err = UpdateArticle(mgo.M{"id": artc.ID}, artc)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return
|
||||
}
|
||||
if !artc.IsDraft {
|
||||
ReplaceArticle(a, artc)
|
||||
// 异步执行,快
|
||||
go func() {
|
||||
// elastic
|
||||
ElasticIndex(artc)
|
||||
// rss
|
||||
DoPings(slug)
|
||||
// disqus
|
||||
if a == nil {
|
||||
ThreadCreate(artc)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
// 只能逐一删除,专题下不能有文章
|
||||
func apiSerieDelete(c *gin.Context) {
|
||||
for _, v := range c.PostFormArray("mid[]") {
|
||||
id, err := strconv.Atoi(v)
|
||||
if err != nil || id < 1 {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
err = DelSerie(int32(id))
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
}
|
||||
responseNotice(c, NOTICE_SUCCESS, "删除成功", "")
|
||||
}
|
||||
|
||||
// 添加专题,如果专题有提交 mid 即更新专题
|
||||
func apiSerieAdd(c *gin.Context) {
|
||||
name := c.PostForm("name")
|
||||
slug := c.PostForm("slug")
|
||||
desc := c.PostForm("description")
|
||||
if name == "" || slug == "" || desc == "" {
|
||||
responseNotice(c, NOTICE_NOTICE, "参数错误", "")
|
||||
return
|
||||
}
|
||||
mid, err := strconv.Atoi(c.PostForm("mid"))
|
||||
if err == nil && mid > 0 {
|
||||
serie := QuerySerie(int32(mid))
|
||||
if serie == nil {
|
||||
responseNotice(c, NOTICE_NOTICE, "专题不存在", "")
|
||||
return
|
||||
}
|
||||
serie.Name = name
|
||||
serie.Slug = slug
|
||||
serie.Desc = desc
|
||||
serie.ID = int32(mid)
|
||||
err = UpdateSerie(serie)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
err = AddSerie(name, slug, desc)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
}
|
||||
responseNotice(c, NOTICE_SUCCESS, "操作成功", "")
|
||||
}
|
||||
|
||||
// NOTE 排序专题,暂未实现
|
||||
func apiSerieSort(c *gin.Context) {
|
||||
v := c.PostFormArray("mid[]")
|
||||
logd.Debug(v)
|
||||
}
|
||||
|
||||
// 删除草稿箱,物理删除
|
||||
func apiDraftDelete(c *gin.Context) {
|
||||
for _, v := range c.PostFormArray("mid[]") {
|
||||
i, err := strconv.Atoi(v)
|
||||
if err != nil || i < 1 {
|
||||
responseNotice(c, NOTICE_NOTICE, "参数错误", "")
|
||||
return
|
||||
}
|
||||
err = RemoveArticle(int32(i))
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
}
|
||||
responseNotice(c, NOTICE_SUCCESS, "删除成功", "")
|
||||
}
|
||||
|
||||
// 删除垃圾箱,物理删除
|
||||
func apiTrashDelete(c *gin.Context) {
|
||||
for _, v := range c.PostFormArray("mid[]") {
|
||||
i, err := strconv.Atoi(v)
|
||||
if err != nil || i < 1 {
|
||||
responseNotice(c, NOTICE_NOTICE, "参数错误", "")
|
||||
return
|
||||
}
|
||||
err = RemoveArticle(int32(i))
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
}
|
||||
responseNotice(c, NOTICE_SUCCESS, "删除成功", "")
|
||||
}
|
||||
|
||||
// 从垃圾箱恢复到草稿箱
|
||||
func apiTrashRecover(c *gin.Context) {
|
||||
for _, v := range c.PostFormArray("mid[]") {
|
||||
i, err := strconv.Atoi(v)
|
||||
if err != nil || i < 1 {
|
||||
responseNotice(c, NOTICE_NOTICE, "参数错误", "")
|
||||
return
|
||||
|
||||
}
|
||||
err = RecoverArticle(int32(i))
|
||||
if err != nil {
|
||||
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
|
||||
return
|
||||
}
|
||||
}
|
||||
responseNotice(c, NOTICE_SUCCESS, "恢复成功", "")
|
||||
}
|
||||
|
||||
// 上传文件到 qiniu 云
|
||||
func apiFileUpload(c *gin.Context) {
|
||||
type Size interface {
|
||||
Size() int64
|
||||
}
|
||||
file, header, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
s, ok := file.(Size)
|
||||
if !ok {
|
||||
logd.Error("assert failed")
|
||||
c.String(http.StatusBadRequest, "false")
|
||||
return
|
||||
}
|
||||
filename := strings.ToLower(header.Filename)
|
||||
url, err := FileUpload(filename, s.Size(), file)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
typ := header.Header.Get("Content-Type")
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"title": filename,
|
||||
"isImage": typ[:5] == "image",
|
||||
"url": url,
|
||||
"bytes": fmt.Sprintf("%dkb", s.Size()/1000),
|
||||
})
|
||||
}
|
||||
|
||||
// 删除七牛 CDN 文件
|
||||
func apiFileDelete(c *gin.Context) {
|
||||
defer c.String(http.StatusOK, "删掉了吗?鬼知道。。。")
|
||||
|
||||
name := c.PostForm("title")
|
||||
if name == "" {
|
||||
logd.Error("参数错误")
|
||||
return
|
||||
}
|
||||
err := FileDelete(name)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func responseNotice(c *gin.Context, typ, content, hl string) {
|
||||
if hl != "" {
|
||||
c.SetCookie("notice_highlight", hl, 86400, "/", "", true, false)
|
||||
}
|
||||
c.SetCookie("notice_type", typ, 86400, "/", "", true, false)
|
||||
c.SetCookie("notice", fmt.Sprintf("[\"%s\"]", content), 86400, "/", "", true, false)
|
||||
c.Redirect(http.StatusFound, c.Request.Referer())
|
||||
}
|
||||
1
assets/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Other assets to go along with your repository (images, logos, etc).
|
||||
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 92 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
307
back.go
@@ -1,307 +0,0 @@
|
||||
// Package main provides ...
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/eiblog/setting"
|
||||
"github.com/eiblog/utils/logd"
|
||||
"github.com/eiblog/utils/mgo"
|
||||
"github.com/gin-gonic/contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 是否登录
|
||||
func isLogin(c *gin.Context) bool {
|
||||
session := sessions.Default(c)
|
||||
v := session.Get("username")
|
||||
if v == nil || v.(string) != Ei.Username {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// 登陆过滤
|
||||
func AuthFilter() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if !isLogin(c) {
|
||||
c.Abort()
|
||||
c.Redirect(http.StatusFound, "/admin/login")
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// 登录界面
|
||||
func HandleLogin(c *gin.Context) {
|
||||
logout := c.Query("logout")
|
||||
if logout == "true" {
|
||||
session := sessions.Default(c)
|
||||
session.Delete("username")
|
||||
session.Save()
|
||||
} else if isLogin(c) {
|
||||
c.Redirect(http.StatusFound, "/admin/profile")
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "login.html", gin.H{"BTitle": Ei.BTitle})
|
||||
}
|
||||
|
||||
// 登陆接口
|
||||
func HandleLoginPost(c *gin.Context) {
|
||||
user := c.PostForm("user")
|
||||
pwd := c.PostForm("password")
|
||||
// code := c.PostForm("code") // 二次验证
|
||||
if user == "" || pwd == "" {
|
||||
logd.Print("参数错误", user, pwd)
|
||||
c.Redirect(http.StatusFound, "/admin/login")
|
||||
return
|
||||
}
|
||||
if Ei.Username != user || !VerifyPasswd(Ei.Password, user, pwd) {
|
||||
logd.Printf("账号或密码错误 %s, %s\n", user, pwd)
|
||||
c.Redirect(http.StatusFound, "/admin/login")
|
||||
return
|
||||
}
|
||||
session := sessions.Default(c)
|
||||
session.Set("username", user)
|
||||
session.Save()
|
||||
Ei.LoginIP = c.ClientIP()
|
||||
Ei.LoginTime = time.Now()
|
||||
UpdateAccountField(mgo.M{"$set": mgo.M{"loginip": Ei.LoginIP, "logintime": Ei.LoginTime}})
|
||||
c.Redirect(http.StatusFound, "/admin/profile")
|
||||
}
|
||||
|
||||
func GetBack() gin.H {
|
||||
return gin.H{"Author": Ei.Username, "Qiniu": setting.Conf.Qiniu}
|
||||
}
|
||||
|
||||
// 个人配置
|
||||
func HandleProfile(c *gin.Context) {
|
||||
h := GetBack()
|
||||
h["Console"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "个人配置 | " + Ei.BTitle
|
||||
h["Account"] = Ei
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-profile", h)
|
||||
}
|
||||
|
||||
// 写文章==>Write
|
||||
type T struct {
|
||||
ID string `json:"id"`
|
||||
Tags string `json:"tags"`
|
||||
}
|
||||
|
||||
func HandlePost(c *gin.Context) {
|
||||
h := GetBack()
|
||||
id, err := strconv.Atoi(c.Query("cid"))
|
||||
if err == nil && id > 0 {
|
||||
artc := QueryArticle(int32(id))
|
||||
if artc != nil {
|
||||
h["Title"] = "编辑文章 | " + Ei.BTitle
|
||||
h["Edit"] = artc
|
||||
}
|
||||
}
|
||||
if h["Title"] == nil {
|
||||
h["Title"] = "撰写文章 | " + Ei.BTitle
|
||||
}
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Domain"] = setting.Conf.Mode.Domain
|
||||
h["Series"] = Ei.Series
|
||||
var tags []T
|
||||
for tag, _ := range Ei.Tags {
|
||||
tags = append(tags, T{tag, tag})
|
||||
}
|
||||
str, _ := json.Marshal(tags)
|
||||
h["Tags"] = string(str)
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-post", h)
|
||||
}
|
||||
|
||||
// 删除草稿
|
||||
func HandleDraftDelete(c *gin.Context) {
|
||||
id, err := strconv.Atoi(c.Query("cid"))
|
||||
if err != nil || id < 1 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "参数错误"})
|
||||
return
|
||||
}
|
||||
if err = RemoveArticle(int32(id)); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "删除错误"})
|
||||
return
|
||||
}
|
||||
c.Redirect(http.StatusFound, "/admin/write-post")
|
||||
}
|
||||
|
||||
// 文章管理==>Manage
|
||||
func HandlePosts(c *gin.Context) {
|
||||
kw := c.Query("keywords")
|
||||
tmp := c.Query("serie")
|
||||
se, err := strconv.Atoi(tmp)
|
||||
if err != nil || se < 1 {
|
||||
se = 0
|
||||
}
|
||||
pg, err := strconv.Atoi(c.Query("page"))
|
||||
if err != nil || pg < 1 {
|
||||
pg = 1
|
||||
}
|
||||
vals := c.Request.URL.Query()
|
||||
h := GetBack()
|
||||
h["Manage"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "文章管理 | " + Ei.BTitle
|
||||
h["Series"] = Ei.Series
|
||||
h["Serie"] = se
|
||||
h["KW"] = kw
|
||||
var max int
|
||||
max, h["List"] = PageListBack(se, kw, false, false, pg, setting.Conf.General.PageSize)
|
||||
if pg < max {
|
||||
vals.Set("page", fmt.Sprint(pg+1))
|
||||
h["Next"] = vals.Encode()
|
||||
}
|
||||
if pg > 1 {
|
||||
vals.Set("page", fmt.Sprint(pg-1))
|
||||
h["Prev"] = vals.Encode()
|
||||
}
|
||||
h["PP"] = make(map[int]string, max)
|
||||
for i := 0; i < max; i++ {
|
||||
vals.Set("page", fmt.Sprint(i+1))
|
||||
h["PP"].(map[int]string)[i+1] = vals.Encode()
|
||||
}
|
||||
h["Cur"] = pg
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-posts", h)
|
||||
}
|
||||
|
||||
// 专题列表
|
||||
func HandleSeries(c *gin.Context) {
|
||||
h := GetBack()
|
||||
h["Manage"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "专题管理 | " + Ei.BTitle
|
||||
h["List"] = Ei.Series
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-series", h)
|
||||
}
|
||||
|
||||
// 编辑专题
|
||||
func HandleSerie(c *gin.Context) {
|
||||
h := GetBack()
|
||||
id, err := strconv.Atoi(c.Query("mid"))
|
||||
if serie := QuerySerie(int32(id)); err == nil && id > 0 && serie != nil {
|
||||
h["Title"] = "编辑专题 | " + Ei.BTitle
|
||||
h["Edit"] = serie
|
||||
} else {
|
||||
h["Title"] = "新增专题 | " + Ei.BTitle
|
||||
}
|
||||
h["Manage"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-serie", h)
|
||||
}
|
||||
|
||||
// 标签列表
|
||||
func HandleTags(c *gin.Context) {
|
||||
h := GetBack()
|
||||
h["Manage"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "标签管理 | " + Ei.BTitle
|
||||
h["List"] = Ei.Tags
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-tags", h)
|
||||
}
|
||||
|
||||
// 草稿箱
|
||||
func HandleDraft(c *gin.Context) {
|
||||
h := GetBack()
|
||||
h["Manage"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "草稿箱 | " + Ei.BTitle
|
||||
var err error
|
||||
h["List"], err = LoadDraft()
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
c.Status(http.StatusBadRequest)
|
||||
} else {
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
RenderHTMLBack(c, "admin-draft", h)
|
||||
}
|
||||
|
||||
// 回收箱
|
||||
func HandleTrash(c *gin.Context) {
|
||||
h := GetBack()
|
||||
h["Manage"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "回收箱 | " + Ei.BTitle
|
||||
var err error
|
||||
h["List"], err = LoadTrash()
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
c.HTML(http.StatusBadRequest, "backLayout.html", h)
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-trash", h)
|
||||
}
|
||||
|
||||
// 基本设置==>Setting
|
||||
func HandleGeneral(c *gin.Context) {
|
||||
h := GetBack()
|
||||
h["Setting"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "基本设置 | " + Ei.BTitle
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-general", h)
|
||||
}
|
||||
|
||||
// 阅读设置
|
||||
func HandleDiscussion(c *gin.Context) {
|
||||
h := GetBack()
|
||||
h["Setting"] = true
|
||||
h["Path"] = c.Request.URL.Path
|
||||
h["Title"] = "阅读设置 | " + Ei.BTitle
|
||||
c.Status(http.StatusOK)
|
||||
RenderHTMLBack(c, "admin-discussion", h)
|
||||
}
|
||||
|
||||
// api
|
||||
func HandleAPI(c *gin.Context) {
|
||||
action := c.Param("action")
|
||||
logd.Debug("action=======>", action)
|
||||
api := APIs[action]
|
||||
if api == nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "Invalid API Request"})
|
||||
return
|
||||
}
|
||||
api(c)
|
||||
}
|
||||
|
||||
// 渲染 html
|
||||
func RenderHTMLBack(c *gin.Context, name string, data gin.H) {
|
||||
if name == "login.html" {
|
||||
err := Tmpl.ExecuteTemplate(c.Writer, name, data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||
return
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
err := Tmpl.ExecuteTemplate(&buf, name, data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
data["LayoutContent"] = template.HTML(buf.String())
|
||||
err = Tmpl.ExecuteTemplate(c.Writer, "backLayout.html", data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||
}
|
||||
5
build/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
Packaging and Continuous Integration.
|
||||
|
||||
Put your cloud (AMI), container (Docker), OS (deb, rpm, pkg) package configurations and scripts in the `/build/package` directory.
|
||||
|
||||
Put your CI (travis, circle, drone) configurations and scripts in the `/build/ci` directory. Note that some of the CI tools (e.g., Travis CI) are very picky about the location of their config files. Try putting the config files in the `/build/ci` directory linking them to the location where the CI tools expect them (when possible).
|
||||
23
build/package/backup/Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
||||
FROM golang:1.20 AS builder
|
||||
|
||||
WORKDIR /eiblog
|
||||
COPY . .
|
||||
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 gcompat
|
||||
|
||||
COPY README.md /app/README.md
|
||||
COPY CHANGELOG.md /app/CHANGELOG.md
|
||||
COPY LICENSE /app/LICENSE
|
||||
|
||||
COPY --from=builder /eiblog/cmd/backup/backend /app/backend
|
||||
COPY cmd/backup/etc /app/etc
|
||||
|
||||
EXPOSE 9001
|
||||
|
||||
WORKDIR /app
|
||||
CMD ["./backend"]
|
||||
22
build/package/eiblog/Dockerfile
Normal file
@@ -0,0 +1,22 @@
|
||||
FROM golang:1.20 AS builder
|
||||
|
||||
WORKDIR /eiblog
|
||||
COPY . .
|
||||
RUN scripts/run_build.sh eiblog
|
||||
|
||||
FROM alpine:latest
|
||||
LABEL maintainer="deepzz.qi@gmail.com"
|
||||
|
||||
RUN apk add --update --no-cache tzdata ca-certificates
|
||||
|
||||
COPY README.md /app/README.md
|
||||
COPY CHANGELOG.md /app/CHANGELOG.md
|
||||
COPY LICENSE /app/LICENSE
|
||||
|
||||
COPY --from=builder /eiblog/cmd/eiblog/backend /app/backend
|
||||
COPY cmd/eiblog/etc /app/etc
|
||||
|
||||
EXPOSE 9000
|
||||
|
||||
WORKDIR /app
|
||||
CMD ["./backend"]
|
||||
51
check.go
@@ -1,51 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 检查 email
|
||||
func CheckEmail(e string) bool {
|
||||
reg := regexp.MustCompile(`^(\w)+([\.\-]\w+)*@(\w)+((\.\w+)+)$`)
|
||||
return reg.MatchString(e)
|
||||
}
|
||||
|
||||
// 检查 domain
|
||||
func CheckDomain(domain string) bool {
|
||||
reg := regexp.MustCompile(`^(http://|https://)?[0-9a-zA-Z]+[0-9a-zA-Z\.-]*\.[a-zA-Z]{2,4}$`)
|
||||
return reg.MatchString(domain)
|
||||
}
|
||||
|
||||
// 检查 sms
|
||||
func CheckSMS(sms string) bool {
|
||||
reg := regexp.MustCompile(`^\+\d+$`)
|
||||
return reg.MatchString(sms)
|
||||
}
|
||||
|
||||
// 检查 password
|
||||
func CheckPwd(pwd string) bool {
|
||||
return len(pwd) > 5 && len(pwd) < 19
|
||||
}
|
||||
|
||||
// 检查日期
|
||||
func CheckDate(date string) time.Time {
|
||||
if t, err := time.ParseInLocation("2006-01-02 15:04", date, time.Local); err == nil {
|
||||
return t
|
||||
}
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
// 检查 id
|
||||
func CheckSerieID(sid string) int32 {
|
||||
if id, err := strconv.Atoi(sid); err == nil {
|
||||
return int32(id)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// bool
|
||||
func CheckBool(str string) bool {
|
||||
return str == "true" || str == "1"
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCheckEmail(t *testing.T) {
|
||||
emails := []string{
|
||||
"xx@email.com",
|
||||
"xxxxemail.com",
|
||||
"xxx#email.com",
|
||||
}
|
||||
|
||||
for i, v := range emails {
|
||||
if i == 0 {
|
||||
assert.True(t, CheckEmail(v))
|
||||
} else {
|
||||
assert.False(t, CheckEmail(v))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckDomain(t *testing.T) {
|
||||
domains := []string{
|
||||
"123.com",
|
||||
"http://123.com",
|
||||
"https://123.com",
|
||||
"123#.com",
|
||||
"123.coooom",
|
||||
}
|
||||
|
||||
for i, v := range domains {
|
||||
if i > 2 {
|
||||
assert.False(t, CheckDomain(v))
|
||||
} else {
|
||||
assert.True(t, CheckDomain(v))
|
||||
}
|
||||
}
|
||||
}
|
||||
7
cmd/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
Main applications for this project.
|
||||
|
||||
The directory name for each application should match the name of the executable you want to have (e.g., `/cmd/myapp`).
|
||||
|
||||
Don't put a lot of code in the application directory. If you think the code can be imported and used in other projects, then it should live in the `/pkg` directory. If the code is not reusable or if you don't want others to reuse it, put that code in the `/internal` directory. You'll be surprised what others will do, so be explicit about your intentions!
|
||||
|
||||
It's common to have a small `main` function that imports and invokes the code from the `/internal` and `/pkg` directories and nothing else.
|
||||
67
cmd/backup/config/config.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/eiblog/eiblog/pkg/config"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// Config config
|
||||
type Config struct {
|
||||
config.APIMode
|
||||
|
||||
Database config.Database // 数据库配置
|
||||
BackupTo string // 备份到, default: qiniu
|
||||
Interval string // 备份周期, default: 7d
|
||||
Validity int // 备份保留时间, default: 60
|
||||
Qiniu config.Qiniu // 七牛OSS配置
|
||||
}
|
||||
|
||||
// Conf 配置
|
||||
var Conf Config
|
||||
|
||||
// load config file
|
||||
func init() {
|
||||
// run mode
|
||||
mode := config.RunMode(os.Getenv("RUN_MODE"))
|
||||
if !mode.IsRunMode() {
|
||||
panic("config: unsupported env RUN_MODE: " + mode)
|
||||
}
|
||||
logrus.Infof("Run mode:%s", mode)
|
||||
|
||||
// 加载配置文件
|
||||
etc, err := config.WorkEtcPath()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
path := filepath.Join(etc, "app.yml")
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = yaml.Unmarshal(data, &Conf)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
Conf.RunMode = mode
|
||||
|
||||
// read env
|
||||
readDatabaseEnv()
|
||||
}
|
||||
|
||||
func readDatabaseEnv() {
|
||||
key := strings.ToUpper(Conf.Name) + "_DB_DRIVER"
|
||||
if d := os.Getenv(key); d != "" {
|
||||
Conf.Database.Driver = d
|
||||
}
|
||||
key = strings.ToUpper(Conf.Name) + "_DB_SOURCE"
|
||||
if s := os.Getenv(key); s != "" {
|
||||
Conf.Database.Source = s
|
||||
}
|
||||
}
|
||||
60
cmd/backup/docs/docs.go
Normal file
@@ -0,0 +1,60 @@
|
||||
// Package docs Code generated by swaggo/swag. DO NOT EDIT
|
||||
package docs
|
||||
|
||||
import "github.com/swaggo/swag"
|
||||
|
||||
const docTemplate = `{
|
||||
"schemes": {{ marshal .Schemes }},
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "{{escape .Description}}",
|
||||
"title": "{{.Title}}",
|
||||
"contact": {},
|
||||
"version": "{{.Version}}"
|
||||
},
|
||||
"host": "{{.Host}}",
|
||||
"basePath": "{{.BasePath}}",
|
||||
"paths": {
|
||||
"/ping": {
|
||||
"get": {
|
||||
"description": "ping",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"ping"
|
||||
],
|
||||
"summary": "ping",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "it's ok",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||
var SwaggerInfo = &swag.Spec{
|
||||
Version: "1.0",
|
||||
Host: "",
|
||||
BasePath: "",
|
||||
Schemes: []string{},
|
||||
Title: "backup API",
|
||||
Description: "This is a backup server.",
|
||||
InfoInstanceName: "swagger",
|
||||
SwaggerTemplate: docTemplate,
|
||||
LeftDelim: "{{",
|
||||
RightDelim: "}}",
|
||||
}
|
||||
|
||||
func init() {
|
||||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
|
||||
}
|
||||
34
cmd/backup/docs/swagger.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "This is a backup server.",
|
||||
"title": "backup API",
|
||||
"contact": {},
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/ping": {
|
||||
"get": {
|
||||
"description": "ping",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"ping"
|
||||
],
|
||||
"summary": "ping",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "it's ok",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
cmd/backup/docs/swagger.yaml
Normal file
@@ -0,0 +1,22 @@
|
||||
info:
|
||||
contact: {}
|
||||
description: This is a backup server.
|
||||
title: backup API
|
||||
version: "1.0"
|
||||
paths:
|
||||
/ping:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: ping
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: it's ok
|
||||
schema:
|
||||
type: string
|
||||
summary: ping
|
||||
tags:
|
||||
- ping
|
||||
swagger: "2.0"
|
||||
14
cmd/backup/etc/app.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
apimode:
|
||||
name: cmd-backup
|
||||
listen: 0.0.0.0:9000
|
||||
database: # 数据库配置
|
||||
driver: mongodb
|
||||
source: mongodb://localhost:27017
|
||||
backupto: qiniu # 备份到, default: qiniu
|
||||
interval: 7d # 备份周期, default: 7d
|
||||
validity: 60 # 备份保留时间, default: 60
|
||||
qiniu: # 七牛OSS
|
||||
bucket: eiblog
|
||||
domain: st.deepzz.com
|
||||
accesskey: MB6AXl_Sj_mmFsL-Lt59Dml2Vmy2o8XMmiCbbSeC
|
||||
secretkey: BIrMy0fsZ0_SHNceNXk3eDuo7WmVYzj2-zrmd5Tf
|
||||
17
cmd/backup/handler/internal/internal.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"github.com/eiblog/eiblog/cmd/backup/config"
|
||||
"github.com/eiblog/eiblog/pkg/third/qiniu"
|
||||
)
|
||||
|
||||
// QiniuClient 七牛客户端
|
||||
var QiniuClient *qiniu.QiniuClient
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
QiniuClient, err = qiniu.NewQiniuClient(config.Conf.Qiniu)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
24
cmd/backup/handler/ping/ping.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package ping
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// RegisterRoutes register routes
|
||||
func RegisterRoutes(group gin.IRoutes) {
|
||||
group.GET("/ping", handlePing)
|
||||
}
|
||||
|
||||
// handlePing ping
|
||||
// @Summary ping
|
||||
// @Description ping
|
||||
// @Tags ping
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {string} string "it's ok"
|
||||
// @Router /ping [get]
|
||||
func handlePing(c *gin.Context) {
|
||||
c.String(http.StatusOK, "it's ok")
|
||||
}
|
||||
14
cmd/backup/handler/swag/swag.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package swag
|
||||
|
||||
import (
|
||||
_ "github.com/eiblog/eiblog/cmd/eiblog/docs" // docs
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
swaggerFiles "github.com/swaggo/files"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
)
|
||||
|
||||
// RegisterRoutes register routes
|
||||
func RegisterRoutes(group gin.IRoutes) {
|
||||
group.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
}
|
||||
7
cmd/backup/handler/timer/db/db.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package db
|
||||
|
||||
// Storage 备份恢复器
|
||||
type Storage interface {
|
||||
Backup(name string) (string, error)
|
||||
Restore(path string) error
|
||||
}
|
||||
72
cmd/backup/handler/timer/db/mgodb.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/eiblog/cmd/backup/config"
|
||||
"github.com/eiblog/eiblog/pkg/connector/db"
|
||||
)
|
||||
|
||||
// MongoStorage 备份恢复器
|
||||
type MongoStorage struct{}
|
||||
|
||||
// Backup 备份
|
||||
func (r MongoStorage) Backup(name string) (string, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
|
||||
defer cancel()
|
||||
|
||||
// dump
|
||||
u, err := url.Parse(config.Conf.Database.Source)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
arg := fmt.Sprintf("mongodump -h %s -d eiblog -o /tmp", u.Host)
|
||||
cmd := exec.CommandContext(ctx, "sh", "-c", arg)
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// tar
|
||||
arg = fmt.Sprintf("tar czf /tmp/%s -C /tmp eiblog", name)
|
||||
cmd = exec.CommandContext(ctx, "sh", "-c", arg)
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return "/tmp/" + name, nil
|
||||
}
|
||||
|
||||
// Restore 恢复
|
||||
func (r MongoStorage) Restore(path string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
|
||||
defer cancel()
|
||||
|
||||
// drop database
|
||||
mdb, err := db.NewMDB(config.Conf.Database)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = mdb.Drop(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// unarchive
|
||||
arg := fmt.Sprintf("tar xzf %s -C /tmp", path)
|
||||
cmd := exec.CommandContext(ctx, "sh", "-c", arg)
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// restore
|
||||
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()
|
||||
}
|
||||
95
cmd/backup/handler/timer/timer.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package timer
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/eiblog/cmd/backup/config"
|
||||
"github.com/eiblog/eiblog/cmd/backup/handler/timer/db"
|
||||
"github.com/eiblog/eiblog/cmd/backup/handler/timer/to"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Start to backup with ticker
|
||||
func Start(restore bool) (err error) {
|
||||
var (
|
||||
storage db.Storage
|
||||
backupTo to.BackupRestorer
|
||||
)
|
||||
|
||||
// backup from
|
||||
switch config.Conf.Database.Driver {
|
||||
case "mongodb":
|
||||
storage = db.MongoStorage{}
|
||||
|
||||
default:
|
||||
return errors.New("timer: unknown backup from driver: " +
|
||||
config.Conf.Database.Driver)
|
||||
}
|
||||
|
||||
// backup to
|
||||
switch config.Conf.BackupTo {
|
||||
case "qiniu":
|
||||
backupTo = to.QiniuBackupRestorer{}
|
||||
|
||||
default:
|
||||
return errors.New("timer: unknown backup to driver: " +
|
||||
config.Conf.BackupTo)
|
||||
}
|
||||
|
||||
// restore
|
||||
if restore {
|
||||
path, err := backupTo.Download()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = storage.Restore(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Info("timer: Restore success")
|
||||
}
|
||||
|
||||
// backup
|
||||
interval, err := ParseDuration(config.Conf.Interval)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t := time.NewTicker(interval)
|
||||
for now := range t.C {
|
||||
name := fmt.Sprintf("eiblog-%s.tar.gz", now.Format("2006-01-02"))
|
||||
path, err := storage.Backup(name)
|
||||
if err != nil {
|
||||
logrus.Error("timer: Start.Backup: ", now.Format(time.RFC3339), err)
|
||||
continue
|
||||
}
|
||||
err = backupTo.Upload(path)
|
||||
if err != nil {
|
||||
logrus.Error("timer: Start.Backup: ", now.Format(time.RFC3339), err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ParseDuration parse string to duration
|
||||
func ParseDuration(d string) (time.Duration, error) {
|
||||
if len(d) == 0 {
|
||||
return 0, errors.New("timer: incorrect duration input")
|
||||
}
|
||||
|
||||
length := len(d)
|
||||
switch d[length-1] {
|
||||
case 's', 'm', 'h':
|
||||
return time.ParseDuration(d)
|
||||
case 'd':
|
||||
di, err := strconv.Atoi(d[:length-1])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return time.Duration(di) * time.Hour * 24, nil
|
||||
}
|
||||
return 0, errors.New("timer: unsupported duration:" + d)
|
||||
}
|
||||
66
cmd/backup/handler/timer/to/qiniu.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package to
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/eiblog/eiblog/cmd/backup/config"
|
||||
"github.com/eiblog/eiblog/cmd/backup/handler/internal"
|
||||
"github.com/eiblog/eiblog/pkg/third/qiniu"
|
||||
)
|
||||
|
||||
// QiniuBackupRestorer qiniu backup restorer
|
||||
type QiniuBackupRestorer struct{}
|
||||
|
||||
// Upload implements timer.BackupRestorer
|
||||
func (s QiniuBackupRestorer) Upload(path string) error {
|
||||
name := filepath.Base(path)
|
||||
|
||||
// upload file
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fi, err := f.Stat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
uploadParams := qiniu.UploadParams{
|
||||
Name: filepath.Join("blog", name), // blog/eiblog-xx.tar.gz
|
||||
Size: fi.Size(),
|
||||
Data: f,
|
||||
NoCompletePath: true,
|
||||
}
|
||||
_, err = internal.QiniuClient.Upload(uploadParams)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// after days delete
|
||||
deleteParams := qiniu.DeleteParams{
|
||||
Name: filepath.Join("blog", name), // blog/eiblog-xx.tar.gz
|
||||
Days: config.Conf.Validity,
|
||||
NoCompletePath: true,
|
||||
}
|
||||
return internal.QiniuClient.Delete(deleteParams)
|
||||
}
|
||||
|
||||
// Download implements timer.BackupRestorer
|
||||
func (s QiniuBackupRestorer) Download() (string, error) {
|
||||
// backup file
|
||||
params := qiniu.ContentParams{
|
||||
Prefix: "blog/",
|
||||
}
|
||||
raw, err := internal.QiniuClient.Content(params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
path := filepath.Join("/tmp", "eiblog.tar.gz")
|
||||
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
_, _ = f.Write(raw)
|
||||
defer f.Close()
|
||||
return path, nil
|
||||
}
|
||||
7
cmd/backup/handler/timer/to/to.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package to
|
||||
|
||||
// BackupRestorer 备份存储接口
|
||||
type BackupRestorer interface {
|
||||
Upload(path string) error
|
||||
Download() (path string, err error)
|
||||
}
|
||||
61
cmd/backup/main.go
Normal file
@@ -0,0 +1,61 @@
|
||||
// Package main provides ...
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/eiblog/eiblog/cmd/backup/config"
|
||||
"github.com/eiblog/eiblog/cmd/backup/handler/ping"
|
||||
"github.com/eiblog/eiblog/cmd/backup/handler/swag"
|
||||
"github.com/eiblog/eiblog/cmd/backup/handler/timer"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// @title backup API
|
||||
// @version 1.0
|
||||
// @description This is a backup server.
|
||||
|
||||
var restore bool
|
||||
|
||||
func init() {
|
||||
flag.BoolVar(&restore, "restore", false, "restore data into mongodb")
|
||||
}
|
||||
|
||||
func main() {
|
||||
logrus.Info("Hi, it's App " + config.Conf.Name)
|
||||
|
||||
flag.Parse()
|
||||
endRun := make(chan error, 1)
|
||||
|
||||
runCommand(restore, endRun)
|
||||
|
||||
runHTTPServer(endRun)
|
||||
logrus.Fatal(<-endRun)
|
||||
}
|
||||
|
||||
func runCommand(restore bool, endRun chan error) {
|
||||
go func() {
|
||||
endRun <- timer.Start(restore)
|
||||
}()
|
||||
}
|
||||
|
||||
func runHTTPServer(endRun chan error) {
|
||||
if config.Conf.RunMode.IsReleaseMode() {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
e := gin.Default()
|
||||
|
||||
// swag
|
||||
swag.RegisterRoutes(e)
|
||||
|
||||
// route
|
||||
ping.RegisterRoutes(e)
|
||||
|
||||
// start
|
||||
go func() {
|
||||
endRun <- e.Run(config.Conf.Listen)
|
||||
}()
|
||||
logrus.Info("HTTP server running on: " + config.Conf.Listen)
|
||||
}
|
||||
83
cmd/eiblog/config/config.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/eiblog/eiblog/pkg/config"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var (
|
||||
// Conf 配置
|
||||
Conf Config
|
||||
// EtcDir 工作目录
|
||||
EtcDir string
|
||||
)
|
||||
|
||||
// Config config
|
||||
type Config struct {
|
||||
config.APIMode
|
||||
// 静态资源版本, 每次更改了 js/css 都需要提高该值
|
||||
StaticVersion int
|
||||
// 数据库配置
|
||||
Database config.Database
|
||||
// 热词, 手动指定, 用于搜索
|
||||
HotWords []string
|
||||
// Elasticsearch 配置
|
||||
ESHost string
|
||||
|
||||
General config.General
|
||||
Disqus config.Disqus
|
||||
Google config.Google
|
||||
Qiniu config.Qiniu
|
||||
Twitter config.Twitter
|
||||
FeedRPC config.FeedRPC
|
||||
Account config.Account
|
||||
Pages []config.CustomPage
|
||||
}
|
||||
|
||||
// init 初始化配置
|
||||
func init() {
|
||||
// run mode
|
||||
mode := config.RunMode(os.Getenv("RUN_MODE"))
|
||||
if !mode.IsRunMode() {
|
||||
panic("config: unsupported env RUN_MODE: " + mode)
|
||||
}
|
||||
logrus.Infof("Run mode:%s", mode)
|
||||
|
||||
// 加载配置文件
|
||||
var err error
|
||||
EtcDir, err = config.WorkEtcPath()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
path := filepath.Join(EtcDir, "app.yml")
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = yaml.Unmarshal(data, &Conf)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
Conf.RunMode = mode
|
||||
|
||||
// 读取环境变量配置
|
||||
readDatabaseEnv()
|
||||
}
|
||||
|
||||
func readDatabaseEnv() {
|
||||
key := strings.ToUpper(Conf.Name) + "_DB_DRIVER"
|
||||
if d := os.Getenv(key); d != "" {
|
||||
Conf.Database.Driver = d
|
||||
}
|
||||
key = strings.ToUpper(Conf.Name) + "_DB_SOURCE"
|
||||
if s := os.Getenv(key); s != "" {
|
||||
Conf.Database.Source = s
|
||||
}
|
||||
}
|
||||
36
cmd/eiblog/docs/docs.go
Normal file
@@ -0,0 +1,36 @@
|
||||
// Package docs Code generated by swaggo/swag. DO NOT EDIT
|
||||
package docs
|
||||
|
||||
import "github.com/swaggo/swag"
|
||||
|
||||
const docTemplate = `{
|
||||
"schemes": {{ marshal .Schemes }},
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "{{escape .Description}}",
|
||||
"title": "{{.Title}}",
|
||||
"contact": {},
|
||||
"version": "{{.Version}}"
|
||||
},
|
||||
"host": "{{.Host}}",
|
||||
"basePath": "{{.BasePath}}",
|
||||
"paths": {}
|
||||
}`
|
||||
|
||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||
var SwaggerInfo = &swag.Spec{
|
||||
Version: "",
|
||||
Host: "",
|
||||
BasePath: "",
|
||||
Schemes: []string{},
|
||||
Title: "",
|
||||
Description: "",
|
||||
InfoInstanceName: "swagger",
|
||||
SwaggerTemplate: docTemplate,
|
||||
LeftDelim: "{{",
|
||||
RightDelim: "}}",
|
||||
}
|
||||
|
||||
func init() {
|
||||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
|
||||
}
|
||||
7
cmd/eiblog/docs/swagger.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"contact": {}
|
||||
},
|
||||
"paths": {}
|
||||
}
|
||||
4
cmd/eiblog/docs/swagger.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
info:
|
||||
contact: {}
|
||||
paths: {}
|
||||
swagger: "2.0"
|
||||
59
cmd/eiblog/etc/app.yml
Normal file
@@ -0,0 +1,59 @@
|
||||
apimode:
|
||||
name: cmd-eiblog
|
||||
listen: 0.0.0.0:9000
|
||||
host: example.com
|
||||
database: # 数据库配置
|
||||
driver: sqlite
|
||||
source: ./db.sqlite
|
||||
hotwords: # 热搜词
|
||||
- docker
|
||||
- mongodb
|
||||
- curl
|
||||
- dns
|
||||
staticversion: 1
|
||||
eshost: # http://elasticsearch:9200
|
||||
pages:
|
||||
- name: 自定义页面
|
||||
path: /page/custom.html
|
||||
showinnav: true
|
||||
isembed: false
|
||||
- name: 自定义页面2
|
||||
path: /page/custom2.html
|
||||
showinnav: true
|
||||
isembed: true
|
||||
general: # 常规配置
|
||||
pagenum: 10 # 首页展示文章数量
|
||||
pagesize: 20 # 管理界面
|
||||
descprefix: "Desc:" # 文章描述前缀
|
||||
identifier: <!--more--> # 截取预览标识
|
||||
length: 400 # 自动截取预览, 字符数
|
||||
timezone: Asia/Shanghai # 时区
|
||||
twofactor: true # 是否启用两步验证
|
||||
disqus: # 评论相关
|
||||
shortname: xxxxxx
|
||||
publickey: wdSgxRm9rdGAlLKFcFdToBe3GT4SibmV7Y8EjJQ0r4GWXeKtxpopMAeIeoI2dTEg
|
||||
accesstoken: 50023908f39f4607957e909b495326af
|
||||
google: # 谷歌分析
|
||||
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
|
||||
accesskey: MB6AXl_Sj_mmFsL-Lt59Dml2Vmy2o8XMmiCbbSeC
|
||||
secretkey: BIrMy0fsZ0_SHNceNXk3eDuo7WmVYzj2-zrmd5Tf
|
||||
twitter: # twitter card
|
||||
card: summary
|
||||
site: deepzz02
|
||||
image: st.deepzz.com/static/img/avatar.jpg
|
||||
address: twitter.com/deepzz02
|
||||
feedrpc: # rss ping
|
||||
feedrurl: https://deepzz.superfeedr.com/
|
||||
pingrpc:
|
||||
- http://ping.baidu.com/ping/RPC2
|
||||
- http://rpc.pingomatic.com/
|
||||
# 数据初始化操作,可到博客后台修改
|
||||
account:
|
||||
username: deepzz # *后台登录用户名
|
||||
password: deepzz # *登录明文密码
|
||||
|
Before Width: | Height: | Size: 847 B After Width: | Height: | Size: 847 B |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
8
cmd/eiblog/etc/page/custom.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Custom Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Custom Page</h1>
|
||||
</body>
|
||||
</html>
|
||||
10
cmd/eiblog/etc/page/custom2.html
Normal file
@@ -0,0 +1,10 @@
|
||||
{{define "custom2.html"}}
|
||||
<div id=content class=inner>
|
||||
<article class="post" itemscope itemtype="http://schema.org/Article">
|
||||
<h1 class=title itemprop=headline>Custom Page</h1>
|
||||
<div class="entry-content" itemprop=articleBody>
|
||||
<p>Custom Page</p>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
{{end}}
|
||||
1
cmd/eiblog/etc/template/README.md
Normal file
@@ -0,0 +1 @@
|
||||
This is the place to put your project's website data if you are not using GitHub pages.
|
||||
@@ -50,8 +50,8 @@
|
||||
<td><a href="/admin/write-post?cid={{.ID}}">{{.Title}}</a></td>
|
||||
<td>{{.Author}}</td>
|
||||
<td>{{if gt .SerieID 0}}专题ID:{{.SerieID}}{{else}}--{{end}}</td>
|
||||
<td>{{dateformat .CreateTime "2006/01/02 15:04"}}</td>
|
||||
<td>{{dateformat .UpdateTime "2006/01/02 15:04"}}</td>
|
||||
<td>{{dateformat .CreatedAt "2006/01/02 15:04"}}</td>
|
||||
<td>{{dateformat .UpdatedAt "2006/01/02 15:04"}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
@@ -22,10 +22,10 @@
|
||||
<label for=password class="sr-only">密码</label>
|
||||
<input type=password id=password name=password class="text-l w-100" placeholder="密码">
|
||||
</p>
|
||||
<!-- <p>
|
||||
{{if .TwoFactor}}<p>
|
||||
<label for=code class="sr-only">两步验证</label>
|
||||
<input type=text id=code name=code class="text-l w-100" placeholder="两步验证">
|
||||
</p> -->
|
||||
</p>{{end}}
|
||||
<p class=submit>
|
||||
<button type=submit class="btn btn-l w-100 primary">登录</button>
|
||||
</p>
|
||||
@@ -35,7 +35,7 @@
|
||||
<section class="typecho-post-option" role="application">
|
||||
<label for="date" class="typecho-label">发布日期</label>
|
||||
<p>
|
||||
<input class="typecho-date w-100" type="text" name="date" id="date" {{with .Edit}}value="{{dateformat .CreateTime "2006-01-02 15:04"}}"{{end}} />
|
||||
<input class="typecho-date w-100" type="text" name="date" id="date" {{with .Edit}}value="{{dateformat .CreatedAt "2006-01-02 15:04"}}"{{end}} />
|
||||
</p>
|
||||
</section>
|
||||
<section class="typecho-post-option category-option">
|
||||
@@ -68,8 +68,8 @@
|
||||
</td>
|
||||
<td>{{.Author}}</td>
|
||||
<td>{{if gt .SerieID 0}}专题ID:{{.SerieID}}{{else}}--{{end}}</td>
|
||||
<td>{{dateformat .CreateTime "06/01/02 15:04"}}</td>
|
||||
<td>{{dateformat .UpdateTime "06/01/02 15:04"}}</td>
|
||||
<td>{{dateformat .CreatedAt "06/01/02 15:04"}}</td>
|
||||
<td>{{dateformat .UpdatedAt "06/01/02 15:04"}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
@@ -3,15 +3,41 @@
|
||||
<div class="typecho-page-title">
|
||||
<h2>个人设置</h2>
|
||||
</div>
|
||||
{{with .Account}}
|
||||
{{with .Ei}}
|
||||
<div class="row typecho-page-main">
|
||||
<div class="col-mb-12 col-tb-3">
|
||||
<p>
|
||||
<img class="profile-avatar" src="//{{$.Qiniu.Domain}}/static/img/avatar.png" alt="{{.BlogName}}" />
|
||||
<img class="profile-avatar" src="//{{$.Qiniu.Domain}}/static/img/avatar.png" alt="{{.Blogger.BlogName}}" />
|
||||
</p>
|
||||
<h2>{{.BlogName}}</h2>
|
||||
<p>{{.SubTitle}}</p>
|
||||
<p>最后登录: {{dateformat .LoginTime "2006/01/02 15:04"}}</p>
|
||||
<h2>{{.Blogger.BlogName}}</h2>
|
||||
<p>{{.Blogger.SubTitle}}</p>
|
||||
<p>最后登录: {{dateformat .Account.LoginAt "2006/01/02 15:04"}}</p>
|
||||
{{if .Account.TwoFactorSecret}}
|
||||
<strong>2FA 已绑定 <a class="unbind-2fa" href="/admin/profile?unbind=true">解绑</a></strong>
|
||||
{{end}}
|
||||
{{if $.TwoFactorSecret}}
|
||||
<strong>2FA 绑定</strong>
|
||||
<form action="/admin/api/twofactor" method="post" enctype="application/x-www-form-urlencoded">
|
||||
<ul class="typecho-option">
|
||||
<li>
|
||||
<img src="{{$.TwoFactorSecret}}" alt="2fa code" style="width:180px;height:180px;">
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="typecho-option">
|
||||
<li>
|
||||
<input id="2fa-0-1" name="code" type="text" class="text" />
|
||||
<p class="description">
|
||||
输入 2FA 验证码, 用于确认绑定.</p>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="typecho-option typecho-option-submit">
|
||||
<li>
|
||||
<button type="submit" class="btn primary">
|
||||
确认绑定</button>
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="col-mb-12 col-tb-6 col-tb-offset-1 typecho-content-panel" role="form">
|
||||
<section>
|
||||
@@ -21,7 +47,7 @@
|
||||
<li>
|
||||
<label class="typecho-label" for="info-0-1">
|
||||
个人邮箱</label>
|
||||
<input id="info-0-1" name="email" type="text" class="text" value="{{.Email}}" />
|
||||
<input id="info-0-1" name="email" type="text" class="text" value="{{.Account.Email}}" />
|
||||
<p class="description">
|
||||
用于发送告警邮件及其它通知, 建议填写, 如: example@163.com.</p>
|
||||
</li>
|
||||
@@ -30,7 +56,7 @@
|
||||
<li>
|
||||
<label class="typecho-label" for="info-0-2">
|
||||
移动电话</label>
|
||||
<input id="info-0-2" name="phoneNumber" type="text" class="text" value="{{.PhoneN}}" />
|
||||
<input id="info-0-2" name="phoneNumber" type="text" class="text" value="{{.Account.PhoneN}}" />
|
||||
<p class="description">
|
||||
选择填写, 如: +8615123456789.</p>
|
||||
</li>
|
||||
@@ -39,7 +65,7 @@
|
||||
<li>
|
||||
<label class="typecho-label" for="info-0-3">
|
||||
家庭住址</label>
|
||||
<input id="info-0-3" name="address" type="text" class="text" value="{{.Address}}" />
|
||||
<input id="info-0-3" name="address" type="text" class="text" value="{{.Account.Address}}" />
|
||||
<p class="description">
|
||||
选择填写, 如: xx省xx市xx区(县)xxxx小区xxx号.</p>
|
||||
</li>
|
||||
@@ -60,7 +86,7 @@
|
||||
<li>
|
||||
<label class="typecho-label" for="blog-0-1">
|
||||
博客昵称 *</label>
|
||||
<input id="blog-0-1" name="blogName" type="text" class="text" value="{{.BlogName}}" />
|
||||
<input id="blog-0-1" name="blogName" type="text" class="text" value="{{.Blogger.BlogName}}" />
|
||||
<p class="description">
|
||||
用户昵称可以与用户名不同, 用于前台显示.
|
||||
<br />如果你将此项留空, 将默认使用登录用户名.</p>
|
||||
@@ -70,7 +96,7 @@
|
||||
<li>
|
||||
<label class="typecho-label" for="blog-0-2">
|
||||
标题显示 *</label>
|
||||
<input id="blog-0-2" name="bTitle" type="text" class="text" value="{{.BTitle}}" />
|
||||
<input id="blog-0-2" name="bTitle" type="text" class="text" value="{{.Blogger.BTitle}}" />
|
||||
<p class="description">
|
||||
用于所有页面的title组成, 如: Deepzz's Blog</p>
|
||||
</li>
|
||||
@@ -79,7 +105,7 @@
|
||||
<li>
|
||||
<label class="typecho-label" for="blog-0-3">
|
||||
个人格言</label>
|
||||
<input id="blog-0-3" name="subTitle" type="text" class="text" value="{{.SubTitle}}" />
|
||||
<input id="blog-0-3" name="subTitle" type="text" class="text" value="{{.Blogger.SubTitle}}" />
|
||||
<p class="description">
|
||||
简介或格言, 如: 生活百般滋味, 人生需要笑对.</p>
|
||||
</li>
|
||||
@@ -88,7 +114,7 @@
|
||||
<li>
|
||||
<label class="typecho-label" for="blog-0-4">
|
||||
备案号</label>
|
||||
<input id="blog-0-4" name="beiAn" type="text" class="text" value="{{.BeiAn}}" />
|
||||
<input id="blog-0-4" name="beiAn" type="text" class="text" value="{{.Blogger.BeiAn}}" />
|
||||
<p class="description">
|
||||
用于底部显示, 不添加则不显示, 如: 蜀 ICP 备 16021362 号</p>
|
||||
</li>
|
||||
@@ -97,7 +123,7 @@
|
||||
<li>
|
||||
<label class="typecho-label" for="blog-0-5">
|
||||
专题前说</label>
|
||||
<textarea id="blog-0-5" name="seriessay">{{.SeriesSay}}</textarea>
|
||||
<textarea id="blog-0-5" name="seriessay">{{.Blogger.SeriesSay}}</textarea>
|
||||
<p class="description">
|
||||
此文字用于专题前述, 会在专题最前方显示.</p>
|
||||
</li>
|
||||
@@ -106,7 +132,7 @@
|
||||
<li>
|
||||
<label class="typecho-label" for="blog-0-6">
|
||||
归档前说</label>
|
||||
<textarea id="blog-0-6" name="archivessay">{{.ArchivesSay}}</textarea>
|
||||
<textarea id="blog-0-6" name="archivessay">{{.Blogger.ArchivesSay}}</textarea>
|
||||
<p class="description">
|
||||
此文字用于归档前述, 会在归档最前方显示.</p>
|
||||
</li>
|
||||
@@ -50,7 +50,7 @@
|
||||
<a href="/admin/add-serie?mid={{.ID}}">{{.Name}}</a>
|
||||
<a target="_blank" href="/series.html#toc-{{.ID}}" title="浏览 {{.Name}}"><i class="i-exlink"></i></a>
|
||||
</td>
|
||||
<td>{{dateformat .CreateTime "2006/01/02 15:04"}}</td>
|
||||
<td>{{dateformat .CreatedAt "2006/01/02 15:04"}}</td>
|
||||
<td><a class="balloon-button left size-50" href="#">{{len .Articles}}</a></td>
|
||||
</tr>
|
||||
{{end}}
|
||||
@@ -51,8 +51,8 @@
|
||||
<td>{{.Title}}</td>
|
||||
<td>{{.Author}}</td>
|
||||
<td>{{if gt .SerieID 0}}专题ID:{{.SerieID}}{{else}}--{{end}}</td>
|
||||
<td>{{dateformat .CreateTime "2006/01/02 15:04"}}</td>
|
||||
<td>{{dateformat .DeleteTime "2006/01/02 15:04"}}</td>
|
||||
<td>{{dateformat .CreatedAt "2006/01/02 15:04"}}</td>
|
||||
<td>{{dateformat .DeletedAt "2006/01/02 15:04"}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
1
cmd/eiblog/etc/template/article.html
Normal file
@@ -0,0 +1 @@
|
||||
{{define "article"}}<div id=content class=inner>{{with .Article}}<article class="post post-{{.ID}}" itemscope itemtype="http://schema.org/Article"><div class=meta><div class=date><time itemprop=datePublished content="{{dateformat .CreatedAt "2006-01-02T15:04:05Z07:00"}}">{{dateformat .CreatedAt "Jan 02, 2006"}}</time></div><div class="date-modified"><time itemprop=dateModified content="{{dateformat .UpdatedAt "2006-01-02T15:04:05Z07:00"}}">{{dateformat .UpdatedAt "Jan 02, 2006"}}</time></div><div class=comment><a href="#comments">{{.Count}} Comments</a></div></div><h1 class=title itemprop=headline>{{.Title}}</h1><div class="entry-content" itemprop=articleBody>{{str2html .Header}}{{str2html .Content}}<p>本文链接:<a rel="bookmark" title="Permalink to {{.Title}}" href="//{{$.Domain}}/post/{{.Slug}}.html" itemprop="url">https://{{$.Domain}}/post/{{.Slug}}.html</a>,<a href="//{{$.Domain}}/post/{{.Slug}}.html#comments">参与评论 »</a></p><p>--<acronym title="End of File">EOF</acronym>--</p><p class="post-info">发表于 <span class="date">{{dateformat .CreatedAt "2006-01-02 15:04:05"}}</span>{{if gt (.Tags|len) 0}},并被添加「{{range $index, $elem := .Tags}}{{if gt $index 0}}、{{end}}<a href="/search.html?q=tag:{{$elem}}">{{$elem}}</a>{{end}}」标签{{end}}{{if .UpdatedAt|isnotzero}},最后修改于 <span class="date">{{dateformat .UpdatedAt "2006-01-02 15:04:05"}}</span>{{end}}。</p>{{with $.Copyright}}<p class="copyright-info">{{str2html $.Copyright}}<a href="//{{$.Domain}}/post/about.html#toc_1">更多说明 »</a></p>{{end}}{{if gt $.Days 100}}<p class="expire-tips">提醒:本文最后更新于 {{$.Days}} 天前,文中所描述的信息可能已发生改变,请谨慎使用。</p>{{end}}{{with $.Serie}}<div class="entry-series"><h3>专题「{{.Name}}」的其它文章 <a href="/series.html#toc-{{.ID}}" title="更多">»</a></h3><ul>{{range .Articles}}{{if ne .ID $.Article.ID}}<li><a href="/post/{{.Slug}}.html">{{.Title}}</a> <span class="date">({{dateformat .CreatedAt "Jan 02, 2006"}})</span></li>{{end}}{{end}}</ul></div>{{end}}</div></article><nav class="page-navi">{{with .Prev}}<a href="/post/{{.Slug}}.html" class=prev>« {{.Title}}</a>{{end}}{{with .Next}}<a href="/post/{{.Slug}}.html" class=next>{{.Title}} »</a>{{end}}</nav><section id=comments><h1 class=title>Comments</h1><div class=total_thread data-identifier="post-{{.Slug}}" data-url="https://{{$.Domain}}/post/{{.Slug}}.html"></div></section>{{end}}</div>{{end}}
|
||||
1
cmd/eiblog/etc/template/home.html
Normal file
@@ -0,0 +1 @@
|
||||
{{define "home"}}<div id="content" class="inner">{{range .List}}<article class="post post-list"><div class="meta"><div class="date"><time>{{dateformat .CreatedAt "Jan 02, 2006"}}</time></div><div class="comment"><a href="/post/{{.Slug}}.html#comments">{{.Count}} Comments</a></div></div><h1 class="title"><a href="/post/{{.Slug}}.html">{{.Title}}</a></h1><div class="entry-content"><p>{{str2html .Excerpt}}[...]</p><p><a href="/post/{{.Slug}}.html" class="more-link">继续阅读 »</a></p></div></article>{{end}}<nav class="page-navi">{{if gt .Prev 0}}<a href="?pn={{.Prev}}" class="prev">« 上一页</a>{{end}}{{if gt .Next 0}}<a href="?pn={{.Next}}" class="next">下一页 »</a>{{end}}<div class="center"><a href="/archives.html">博客归档</a></div></nav></div>{{end}}
|
||||
1
cmd/eiblog/etc/template/homeLayout.html
Normal file
@@ -0,0 +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>{{.AdSense}}<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+864e5*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="//{{.Qiniu.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}}"><meta name="twitter:card" content={{.Twitter.Card}}><meta name="twitter:site" content="@{{.Twitter.Site}}"><meta name="twitter:title" content="{{.Title}}"><meta name="twitter:description" content="{{.Description}}"><meta name="twitter:image" content="https://{{.Twitter.Image}}"></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>{{range $index, $element := .Pages}}{{if .ShowInNav}}<li {{if eq $.Path .Path}}class="on" {{end}}><a href="{{.Path}}" {{if not .IsEmbed}}target="_blank"{{end}}><span>{{.Name}}</span></a></li>{{end}}{{end}}</ul></nav><nav id="sub-nav"><div class="social"><a target="_blank" class="twitter external" rel="nofollow" href="//{{.Twitter.Address}}" title="Twitter" aria-label="Twitter">Twitter</a><a target="_blank" class="rss" href="//{{.Domain}}/rss.html" title="RSS 订阅" aria-label="RSS 订阅">RSS</a><a class="search" href="/search.html" title="站内搜索" aria-label="站内搜索">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}}{{if .BeiAn}} - <a target="_blank" rel="nofollow designer" class="external beian" href="https://beian.miit.gov.cn">{{.BeiAn}}</a>{{end}}<br>Powered by <a target=_blank href="//github.com/eiblog/eiblog">Eiblog</a> & <a target=_blank rel="nofollow designer" class=external href="//github.com/deepzz0">Deepzz</a></footer></div></div><input type=hidden id=CURRENT_PAGE value="{{.CurrentPage}}"><input type=hidden id=CDN_DOMAIN value="//{{.Qiniu.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>
|
||||
3
cmd/eiblog/etc/template/st_ana.js
Normal file
@@ -0,0 +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).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}}
|
||||
3
cmd/eiblog/etc/template/st_blog.css
Normal file
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<cross-domain-policy>
|
||||
<allow-access-from domain="*.{{.Domain}}" />
|
||||
<allow-access-from domain="*.{{.Host}}" />
|
||||
</cross-domain-policy>
|
||||
24
cmd/eiblog/etc/xml/feedTpl.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
<title>{{.Title}}</title>
|
||||
<link>https://{{.Host}}</link>
|
||||
<description>{{.SubTitle}}</description>
|
||||
<atom:link href="https://{{.Host}}/rss.html" rel="self" />
|
||||
<atom:link href="{{.FeedrURL}}" rel="hub" />
|
||||
<language>zh-CN</language>
|
||||
<lastBuildDate>{{.BuildDate}}</lastBuildDate>
|
||||
{{range .Articles}}
|
||||
<item>
|
||||
<title>{{.Title}}</title>
|
||||
<link>https://{{$.Host}}/post/{{.Slug}}.html</link>
|
||||
<comments>https://{{$.Host}}/post/{{.Slug}}.html#comments</comments>
|
||||
<guid>https://{{$.Host}}/post/{{.Slug}}.html</guid>
|
||||
<description>
|
||||
<![CDATA[{{imgtonormal .Content}}<p>本文链接:<a href="https://{{$.Host}}/post/{{.Slug}}.html">https://{{$.Host}}/post/{{.Slug}}.html</a>,<a href="https://{{$.Host}}/post/{{.Slug}}.html#comments">参与评论 »</a></p>]]>
|
||||
</description>
|
||||
<pubDate>{{dateformat .CreatedAt "Mon, 02 Jan 2006 15:04:05 -0700"}}</pubDate>
|
||||
</item>
|
||||
{{end}}
|
||||
</channel>
|
||||
</rss>
|
||||
9
cmd/eiblog/etc/xml/opensearchTpl.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
|
||||
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
|
||||
<ShortName>{{.BTitle}}</ShortName>
|
||||
<Description>{{.SubTitle}}</Description>
|
||||
<InputEncoding>UTF-8</InputEncoding>
|
||||
<Url type="text/html" method="get" template="https://{{.Host}}/search.html?q={searchTerms}" />
|
||||
<moz:SearchForm>https://{{.Host}}/search.html</moz:SearchForm>
|
||||
</OpenSearchDescription>
|
||||
3
cmd/eiblog/etc/xml/robotsTpl.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
User-agent: *
|
||||
Allow: /
|
||||
Sitemap: https://{{.Host}}/sitemap.xml
|
||||
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
{{range .Artcs}}
|
||||
{{range .Articles}}
|
||||
<url>
|
||||
<loc>https://{{$.Domain}}/post/{{.Slug}}.html</loc>
|
||||
<lastmod>{{dateformat .CreateTime "2006-01-02"}}</lastmod>
|
||||
<loc>https://{{$.Host}}/post/{{.Slug}}.html</loc>
|
||||
<lastmod>{{dateformat .CreatedAt "2006-01-02"}}</lastmod>
|
||||
<priority>0.6</priority>
|
||||
</url>
|
||||
{{end}}
|
||||
575
cmd/eiblog/handler/admin/admin.go
Normal file
@@ -0,0 +1,575 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/eiblog/cmd/eiblog/config"
|
||||
"github.com/eiblog/eiblog/cmd/eiblog/handler/internal"
|
||||
"github.com/eiblog/eiblog/pkg/middleware"
|
||||
"github.com/eiblog/eiblog/pkg/model"
|
||||
"github.com/eiblog/eiblog/pkg/third/qiniu"
|
||||
"github.com/eiblog/eiblog/tools"
|
||||
"github.com/pquerna/otp/totp"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// 通知cookie
|
||||
const (
|
||||
NoticeSuccess = "success"
|
||||
NoticeNotice = "notice"
|
||||
NoticeError = "error"
|
||||
)
|
||||
|
||||
// RegisterRoutes register routes
|
||||
func RegisterRoutes(e *gin.Engine) {
|
||||
e.POST("/admin/login", handleAcctLogin)
|
||||
}
|
||||
|
||||
// RegisterRoutesAuthz register routes
|
||||
func RegisterRoutesAuthz(group gin.IRoutes) {
|
||||
group.POST("/api/account", handleAPIAccount)
|
||||
group.POST("/api/blog", handleAPIBlogger)
|
||||
group.POST("/api/password", handleAPIPassword)
|
||||
group.POST("/api/post-delete", handleAPIPostDelete)
|
||||
group.POST("/api/post-add", handleAPIPostCreate)
|
||||
group.POST("/api/serie-delete", handleAPISerieDelete)
|
||||
group.POST("/api/serie-add", handleAPISerieCreate)
|
||||
group.POST("/api/serie-sort", handleAPISerieSort)
|
||||
group.POST("/api/draft-delete", handleDraftDelete)
|
||||
group.POST("/api/trash-delete", handleAPITrashDelete)
|
||||
group.POST("/api/trash-recover", handleAPITrashRecover)
|
||||
group.POST("/api/file-upload", handleAPIQiniuUpload)
|
||||
group.POST("/api/file-delete", handleAPIQiniuDelete)
|
||||
group.POST("/api/twofactor", handleAPITwoFactor)
|
||||
}
|
||||
|
||||
// handleAcctLogin 登录接口
|
||||
func handleAcctLogin(c *gin.Context) {
|
||||
user := c.PostForm("user")
|
||||
pwd := c.PostForm("password")
|
||||
code := c.PostForm("code")
|
||||
if user == "" || pwd == "" {
|
||||
logrus.Warnf("参数错误: %s %s", user, pwd)
|
||||
c.Redirect(http.StatusFound, "/admin/login")
|
||||
return
|
||||
}
|
||||
if internal.Ei.Account.Username != user ||
|
||||
internal.Ei.Account.Password != tools.EncryptPasswd(user, pwd) {
|
||||
logrus.Warnf("账号或密码错误 %s, %s", user, pwd)
|
||||
c.Redirect(http.StatusFound, "/admin/login")
|
||||
return
|
||||
}
|
||||
// 两步验证
|
||||
if config.Conf.General.TwoFactor &&
|
||||
internal.Ei.Account.TwoFactorSecret != "" {
|
||||
valid := totp.Validate(code, internal.Ei.Account.TwoFactorSecret)
|
||||
if !valid {
|
||||
logrus.Warnf("两步验证: %s", code)
|
||||
c.Redirect(http.StatusFound, "/admin/login")
|
||||
return
|
||||
}
|
||||
}
|
||||
// 登录成功
|
||||
middleware.SetLogin(c, user)
|
||||
|
||||
internal.Ei.Account.LoginIP = c.ClientIP()
|
||||
internal.Ei.Account.LoginAt = time.Now()
|
||||
internal.Store.UpdateAccount(context.Background(), user, map[string]interface{}{
|
||||
"login_ip": internal.Ei.Account.LoginIP,
|
||||
"login_at": internal.Ei.Account.LoginAt,
|
||||
})
|
||||
c.Redirect(http.StatusFound, "/admin/profile")
|
||||
}
|
||||
|
||||
// handleAPITwoFactor 两步验证
|
||||
func handleAPITwoFactor(c *gin.Context) {
|
||||
code := c.PostForm("code")
|
||||
if code == "" {
|
||||
responseNotice(c, NoticeNotice, "验证码不能为空", "")
|
||||
return
|
||||
}
|
||||
valid := totp.Validate(code, internal.TwoFactorSecret)
|
||||
if !valid {
|
||||
responseNotice(c, NoticeNotice, "验证码错误", "")
|
||||
return
|
||||
}
|
||||
err := internal.Store.UpdateAccount(context.Background(), internal.Ei.Account.Username,
|
||||
map[string]interface{}{
|
||||
"two_factor_secret": internal.TwoFactorSecret,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Error("handleAPITwoFactor.UpdateAccount: ", err)
|
||||
responseNotice(c, NoticeNotice, err.Error(), "")
|
||||
return
|
||||
}
|
||||
internal.Ei.Account.TwoFactorSecret = internal.TwoFactorSecret
|
||||
internal.TwoFactorSecret = ""
|
||||
c.Request.Header.Set("Referer", "/admin/profile")
|
||||
responseNotice(c, NoticeSuccess, "绑定成功", "")
|
||||
}
|
||||
|
||||
// handleAPIBlogger 更新博客信息
|
||||
func handleAPIBlogger(c *gin.Context) {
|
||||
bn := c.PostForm("blogName")
|
||||
bt := c.PostForm("bTitle")
|
||||
ba := c.PostForm("beiAn")
|
||||
st := c.PostForm("subTitle")
|
||||
ss := c.PostForm("seriessay")
|
||||
as := c.PostForm("archivessay")
|
||||
if bn == "" || bt == "" {
|
||||
responseNotice(c, NoticeNotice, "参数错误", "")
|
||||
return
|
||||
}
|
||||
|
||||
err := internal.Store.UpdateBlogger(context.Background(), map[string]interface{}{
|
||||
"blog_name": bn,
|
||||
"b_title": bt,
|
||||
"bei_an": ba,
|
||||
"sub_title": st,
|
||||
"series_say": ss,
|
||||
"archives_say": as,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Error("handleAPIBlogger.UpdateBlogger: ", err)
|
||||
responseNotice(c, NoticeNotice, err.Error(), "")
|
||||
return
|
||||
}
|
||||
internal.Ei.Blogger.BlogName = bn
|
||||
internal.Ei.Blogger.BTitle = bt
|
||||
internal.Ei.Blogger.BeiAn = ba
|
||||
internal.Ei.Blogger.SubTitle = st
|
||||
internal.Ei.Blogger.SeriesSay = ss
|
||||
internal.Ei.Blogger.ArchivesSay = as
|
||||
internal.PagesCh <- internal.PageSeries
|
||||
internal.PagesCh <- internal.PageArchive
|
||||
responseNotice(c, NoticeSuccess, "更新成功", "")
|
||||
}
|
||||
|
||||
// handleAPIAccount 更新账户信息
|
||||
func handleAPIAccount(c *gin.Context) {
|
||||
e := c.PostForm("email")
|
||||
pn := c.PostForm("phoneNumber")
|
||||
ad := c.PostForm("address")
|
||||
if (e != "" && !tools.ValidateEmail(e)) || (pn != "" &&
|
||||
!tools.ValidatePhoneNo(pn)) {
|
||||
responseNotice(c, NoticeNotice, "参数错误", "")
|
||||
return
|
||||
}
|
||||
|
||||
err := internal.Store.UpdateAccount(context.Background(), internal.Ei.Account.Username,
|
||||
map[string]interface{}{
|
||||
"email": e,
|
||||
"phone_n": pn,
|
||||
"address": ad,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Error("handleAPIAccount.UpdateAccount: ", err)
|
||||
responseNotice(c, NoticeNotice, err.Error(), "")
|
||||
return
|
||||
}
|
||||
internal.Ei.Account.Email = e
|
||||
internal.Ei.Account.PhoneN = pn
|
||||
internal.Ei.Account.Address = ad
|
||||
responseNotice(c, NoticeSuccess, "更新成功", "")
|
||||
}
|
||||
|
||||
// handleAPIPassword 更新密码
|
||||
func handleAPIPassword(c *gin.Context) {
|
||||
od := c.PostForm("old")
|
||||
nw := c.PostForm("new")
|
||||
cf := c.PostForm("confirm")
|
||||
if nw != cf {
|
||||
responseNotice(c, NoticeNotice, "两次密码输入不一致", "")
|
||||
return
|
||||
}
|
||||
if !tools.ValidatePassword(nw) {
|
||||
responseNotice(c, NoticeNotice, "密码格式错误", "")
|
||||
return
|
||||
}
|
||||
if internal.Ei.Account.Password != tools.EncryptPasswd(internal.Ei.Account.Username, od) {
|
||||
responseNotice(c, NoticeNotice, "原始密码不正确", "")
|
||||
return
|
||||
}
|
||||
newPwd := tools.EncryptPasswd(internal.Ei.Account.Username, nw)
|
||||
|
||||
err := internal.Store.UpdateAccount(context.Background(), internal.Ei.Account.Username,
|
||||
map[string]interface{}{
|
||||
"password": newPwd,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Error("handleAPIPassword.UpdateAccount: ", err)
|
||||
responseNotice(c, NoticeNotice, err.Error(), "")
|
||||
return
|
||||
}
|
||||
internal.Ei.Account.Password = newPwd
|
||||
responseNotice(c, NoticeSuccess, "更新成功", "")
|
||||
}
|
||||
|
||||
// handleDraftDelete 删除草稿, 物理删除
|
||||
func handleDraftDelete(c *gin.Context) {
|
||||
for _, v := range c.PostFormArray("mid[]") {
|
||||
id, err := strconv.Atoi(v)
|
||||
if err != nil || id < 1 {
|
||||
responseNotice(c, NoticeNotice, "参数错误", "")
|
||||
return
|
||||
}
|
||||
err = internal.Store.RemoveArticle(context.Background(), id)
|
||||
if err != nil {
|
||||
logrus.Error("handleDraftDelete.RemoveArticle: ", err)
|
||||
responseNotice(c, NoticeNotice, "删除失败", "")
|
||||
return
|
||||
}
|
||||
}
|
||||
responseNotice(c, NoticeSuccess, "删除成功", "")
|
||||
}
|
||||
|
||||
// handleAPIPostDelete 删除文章,移入回收箱
|
||||
func handleAPIPostDelete(c *gin.Context) {
|
||||
var ids []int
|
||||
for _, v := range c.PostFormArray("cid[]") {
|
||||
id, err := strconv.Atoi(v)
|
||||
if err != nil || id < internal.ArticleStartID {
|
||||
responseNotice(c, NoticeNotice, "参数错误", "")
|
||||
return
|
||||
}
|
||||
err = internal.Ei.DelArticle(id)
|
||||
if err != nil {
|
||||
logrus.Error("handleAPIPostDelete.DelArticle: ", err)
|
||||
|
||||
responseNotice(c, NoticeNotice, err.Error(), "")
|
||||
return
|
||||
}
|
||||
ids = append(ids, id)
|
||||
}
|
||||
// elasticsearch
|
||||
if internal.ESClient != nil {
|
||||
err := internal.ESClient.ElasticDelIndex(ids)
|
||||
if err != nil {
|
||||
logrus.Error("handleAPIPostDelete.ElasticDelIndex: ", err)
|
||||
}
|
||||
}
|
||||
// TODO disqus delete
|
||||
responseNotice(c, NoticeSuccess, "删除成功,已移入到回收箱", "")
|
||||
}
|
||||
|
||||
// handleAPIPostCreate 创建文章
|
||||
func handleAPIPostCreate(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
do string
|
||||
cid int
|
||||
)
|
||||
defer func() {
|
||||
now := time.Now().In(tools.TimeLocation)
|
||||
switch do {
|
||||
case "auto": // 自动保存
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"fail": 1, "time": now.Format("15:04:05 PM"), "cid": cid})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"success": 0, "time": now.Format("15:04:05 PM"), "cid": cid})
|
||||
case "save", "publish": // 草稿,发布
|
||||
if err != nil {
|
||||
responseNotice(c, NoticeNotice, err.Error(), "")
|
||||
return
|
||||
}
|
||||
uri := "/admin/manage-draft"
|
||||
if do == "publish" {
|
||||
uri = "/admin/manage-posts"
|
||||
}
|
||||
c.Redirect(http.StatusFound, uri)
|
||||
}
|
||||
}()
|
||||
|
||||
do = c.PostForm("do") // auto or save or publish
|
||||
slug := c.PostForm("slug")
|
||||
title := c.PostForm("title")
|
||||
text := c.PostForm("text")
|
||||
date := parseLocationDate(c.PostForm("date"))
|
||||
serie := c.PostForm("serie")
|
||||
tag := c.PostForm("tags")
|
||||
update := c.PostForm("update")
|
||||
if slug == "" || title == "" || text == "" {
|
||||
err = errors.New("参数错误")
|
||||
return
|
||||
}
|
||||
var tags []string
|
||||
if tag != "" {
|
||||
tags = strings.Split(tag, ",")
|
||||
}
|
||||
serieid, _ := strconv.Atoi(serie)
|
||||
article := &model.Article{
|
||||
Title: title,
|
||||
Content: text,
|
||||
Slug: slug,
|
||||
IsDraft: do != "publish",
|
||||
Author: internal.Ei.Account.Username,
|
||||
SerieID: serieid,
|
||||
Tags: tags,
|
||||
CreatedAt: date,
|
||||
}
|
||||
cid, err = strconv.Atoi(c.PostForm("cid"))
|
||||
// 新文章
|
||||
if err != nil || cid < 1 {
|
||||
err = internal.Ei.AddArticle(article)
|
||||
if err != nil {
|
||||
logrus.Error("handleAPIPostCreate.AddArticle: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
cid = article.ID
|
||||
|
||||
if !article.IsDraft {
|
||||
// disqus
|
||||
internal.DisqusClient.ThreadCreate(article, internal.Ei.Blogger.BTitle)
|
||||
// 异步执行,快
|
||||
go func() {
|
||||
// elastic
|
||||
if internal.ESClient != nil {
|
||||
internal.ESClient.ElasticAddIndex(article)
|
||||
}
|
||||
// rss
|
||||
internal.Pinger.PingFunc(internal.Ei.Blogger.BTitle, slug)
|
||||
}()
|
||||
}
|
||||
return
|
||||
}
|
||||
// 旧文章
|
||||
article.ID = cid
|
||||
artc, _ := internal.Ei.FindArticleByID(article.ID) // cache
|
||||
if artc != nil {
|
||||
article.IsDraft = false
|
||||
article.Count = artc.Count
|
||||
article.UpdatedAt = artc.UpdatedAt
|
||||
}
|
||||
if update == "true" || update == "1" {
|
||||
article.UpdatedAt = time.Now()
|
||||
}
|
||||
// 数据库更新
|
||||
err = internal.Store.UpdateArticle(context.Background(), article.ID, map[string]interface{}{
|
||||
"title": article.Title,
|
||||
"content": article.Content,
|
||||
"serie_id": article.SerieID,
|
||||
"is_draft": article.IsDraft,
|
||||
"tags": article.Tags,
|
||||
"updated_at": article.UpdatedAt,
|
||||
"created_at": article.CreatedAt,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Error("handleAPIPostCreate.UpdateArticle: ", err)
|
||||
return
|
||||
}
|
||||
if !article.IsDraft {
|
||||
internal.Ei.RepArticle(artc, article)
|
||||
// disqus
|
||||
if artc == nil {
|
||||
internal.DisqusClient.ThreadCreate(article, internal.Ei.Blogger.BTitle)
|
||||
}
|
||||
// 异步执行,快
|
||||
go func() {
|
||||
// elastic
|
||||
if internal.ESClient != nil {
|
||||
internal.ESClient.ElasticAddIndex(article)
|
||||
}
|
||||
// rss
|
||||
internal.Pinger.PingFunc(internal.Ei.Blogger.BTitle, slug)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
// handleAPISerieDelete 只能逐一删除,专题下不能有文章
|
||||
func handleAPISerieDelete(c *gin.Context) {
|
||||
for _, v := range c.PostFormArray("mid[]") {
|
||||
id, err := strconv.Atoi(v)
|
||||
if err != nil || id < 1 {
|
||||
responseNotice(c, NoticeNotice, err.Error(), "")
|
||||
return
|
||||
}
|
||||
err = internal.Ei.DelSerie(id)
|
||||
if err != nil {
|
||||
responseNotice(c, NoticeNotice, err.Error(), "")
|
||||
return
|
||||
}
|
||||
}
|
||||
responseNotice(c, NoticeSuccess, "删除成功", "")
|
||||
}
|
||||
|
||||
// handleAPISerieSort 专题排序
|
||||
func handleAPISerieSort(c *gin.Context) {
|
||||
v := c.PostFormArray("mid[]")
|
||||
logrus.Debug(v)
|
||||
}
|
||||
|
||||
// handleAPISerieCreate 添加专题,如果专题有提交 mid 即更新专题
|
||||
func handleAPISerieCreate(c *gin.Context) {
|
||||
name := c.PostForm("name")
|
||||
slug := c.PostForm("slug")
|
||||
desc := c.PostForm("description")
|
||||
if name == "" || slug == "" || desc == "" {
|
||||
responseNotice(c, NoticeNotice, "参数错误", "")
|
||||
return
|
||||
}
|
||||
mid, err := strconv.Atoi(c.PostForm("mid"))
|
||||
if err == nil && mid > 0 {
|
||||
var serie *model.Serie
|
||||
for _, v := range internal.Ei.Series {
|
||||
if v.ID == mid {
|
||||
serie = v
|
||||
break
|
||||
}
|
||||
}
|
||||
if serie == nil {
|
||||
responseNotice(c, NoticeNotice, "专题不存在", "")
|
||||
return
|
||||
}
|
||||
err = internal.Store.UpdateSerie(context.Background(), mid, map[string]interface{}{
|
||||
"slug": slug,
|
||||
"name": name,
|
||||
"desc": desc,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Error("handleAPISerieCreate.UpdateSerie: ", err)
|
||||
responseNotice(c, NoticeNotice, err.Error(), "")
|
||||
return
|
||||
}
|
||||
serie.Slug = slug
|
||||
serie.Name = name
|
||||
serie.Desc = desc
|
||||
internal.PagesCh <- internal.PageSeries
|
||||
} else {
|
||||
err = internal.Ei.AddSerie(&model.Serie{
|
||||
Slug: slug,
|
||||
Name: name,
|
||||
Desc: desc,
|
||||
CreatedAt: time.Now(),
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Error("handleAPISerieCreate.InsertSerie: ", err)
|
||||
responseNotice(c, NoticeNotice, err.Error(), "")
|
||||
return
|
||||
}
|
||||
}
|
||||
responseNotice(c, NoticeSuccess, "操作成功", "")
|
||||
}
|
||||
|
||||
// handleAPITrashDelete 删除回收箱, 物理删除
|
||||
func handleAPITrashDelete(c *gin.Context) {
|
||||
for _, v := range c.PostFormArray("mid[]") {
|
||||
id, err := strconv.Atoi(v)
|
||||
if err != nil || id < 1 {
|
||||
responseNotice(c, NoticeNotice, "参数错误", "")
|
||||
return
|
||||
}
|
||||
err = internal.Store.RemoveArticle(context.Background(), id)
|
||||
if err != nil {
|
||||
responseNotice(c, NoticeNotice, err.Error(), "")
|
||||
return
|
||||
}
|
||||
}
|
||||
responseNotice(c, NoticeSuccess, "删除成功", "")
|
||||
}
|
||||
|
||||
// handleAPITrashRecover 恢复到草稿
|
||||
func handleAPITrashRecover(c *gin.Context) {
|
||||
for _, v := range c.PostFormArray("mid[]") {
|
||||
id, err := strconv.Atoi(v)
|
||||
if err != nil || id < 1 {
|
||||
responseNotice(c, NoticeNotice, "参数错误", "")
|
||||
return
|
||||
|
||||
}
|
||||
err = internal.Store.UpdateArticle(context.Background(), id, map[string]interface{}{
|
||||
"deleted_at": time.Time{},
|
||||
"is_draft": true,
|
||||
})
|
||||
if err != nil {
|
||||
responseNotice(c, NoticeNotice, err.Error(), "")
|
||||
return
|
||||
}
|
||||
}
|
||||
responseNotice(c, NoticeSuccess, "恢复成功", "")
|
||||
}
|
||||
|
||||
// handleAPIQiniuUpload 上传文件
|
||||
func handleAPIQiniuUpload(c *gin.Context) {
|
||||
type Size interface {
|
||||
Size() int64
|
||||
}
|
||||
file, header, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
logrus.Error("handleAPIQiniuUpload.FormFile: ", err)
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
s, ok := file.(Size)
|
||||
if !ok {
|
||||
logrus.Error("assert failed")
|
||||
c.String(http.StatusBadRequest, "false")
|
||||
return
|
||||
}
|
||||
filename := strings.ToLower(header.Filename)
|
||||
|
||||
params := qiniu.UploadParams{
|
||||
Name: filename,
|
||||
Size: s.Size(),
|
||||
Data: file,
|
||||
}
|
||||
url, err := internal.QiniuClient.Upload(params)
|
||||
if err != nil {
|
||||
logrus.Error("handleAPIQiniuUpload.QiniuUpload: ", err)
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
typ := header.Header.Get("Content-Type")
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"title": filename,
|
||||
"isImage": typ[:5] == "image",
|
||||
"url": url,
|
||||
"bytes": fmt.Sprintf("%dkb", s.Size()/1000),
|
||||
})
|
||||
}
|
||||
|
||||
// handleAPIQiniuDelete 删除文件
|
||||
func handleAPIQiniuDelete(c *gin.Context) {
|
||||
defer c.String(http.StatusOK, "删掉了吗?鬼知道。。。")
|
||||
|
||||
name := c.PostForm("title")
|
||||
if name == "" {
|
||||
logrus.Error("handleAPIQiniuDelete.PostForm: 参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
params := qiniu.DeleteParams{
|
||||
Name: name,
|
||||
}
|
||||
err := internal.QiniuClient.Delete(params)
|
||||
if err != nil {
|
||||
logrus.Error("handleAPIQiniuDelete.QiniuDelete: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
// parseLocationDate 解析日期
|
||||
func parseLocationDate(date string) time.Time {
|
||||
t, err := time.ParseInLocation("2006-01-02 15:04", date, tools.TimeLocation)
|
||||
if err == nil {
|
||||
return t.UTC()
|
||||
}
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
func responseNotice(c *gin.Context, typ, content, hl string) {
|
||||
if hl != "" {
|
||||
c.SetCookie("notice_highlight", hl, 86400, "/", "", true, false)
|
||||
}
|
||||
c.SetCookie("notice_type", typ, 86400, "/", "", true, false)
|
||||
c.SetCookie("notice", fmt.Sprintf("[\"%s\"]", content), 86400, "/", "", true, false)
|
||||
c.Redirect(http.StatusFound, c.Request.Referer())
|
||||
}
|
||||