a
@@ -0,0 +1,430 @@
|
||||
# Personal Blog 设计系统文档
|
||||
|
||||
> **设计风格**: 新粗野主义 (Neobrutalism)
|
||||
> **参考来源**: [Slock.ai](https://slock.ai/)
|
||||
> **版本**: v1.0
|
||||
> **更新日期**: 2026-04-06
|
||||
|
||||
---
|
||||
|
||||
## 1. 设计理念
|
||||
|
||||
### 1.1 什么是新粗野主义?
|
||||
|
||||
新粗野主义 (Neobrutalism) 是一种现代网页设计风格,特点包括:
|
||||
|
||||
- **高对比度**: 黑色粗边框 + 明亮背景色
|
||||
- **硬阴影**: 明显的偏移阴影营造立体感
|
||||
- **大胆排版**: 粗体文字、大字号标题
|
||||
- **鲜艳色彩**: 使用高饱和度的强调色
|
||||
- **无圆角**: 直角设计,拒绝圆润
|
||||
- **交互反馈**: 按钮点击时有明显的位移效果
|
||||
|
||||
### 1.2 与 Slock.ai 的对比
|
||||
|
||||
| 特性 | Slock.ai | 我们的博客 |
|
||||
|------|----------|-----------|
|
||||
| 主背景色 | `#FFFFFF` 纯白 | `#FEF9E7` 奶油色 |
|
||||
| 边框风格 | 2px 纯黑 | 2px 纯黑 |
|
||||
| 阴影效果 | 4px 硬阴影 | 4px 硬阴影 |
|
||||
| 强调色 | 粉色、紫色、青色 | 粉色、青色、黄色、绿色 |
|
||||
| 布局风格 | 卡片式网格 | 卡片式/列表式可选 |
|
||||
| 交互反馈 | 点击位移 | 点击位移 + 阴影消失 |
|
||||
|
||||
---
|
||||
|
||||
## 2. 色彩系统
|
||||
|
||||
### 2.1 主色调
|
||||
|
||||
```javascript
|
||||
// tailwind.config.js
|
||||
colors: {
|
||||
'brutal': {
|
||||
'cream': '#FEF9E7', // 主背景色 - 温暖奶油色
|
||||
'yellow': '#FFDE59', // 强调色 - 明黄
|
||||
'pink': '#FF6B9D', // 强调色 - 粉红 (主按钮)
|
||||
'cyan': '#00D9FF', // 强调色 - 青色 (次要按钮)
|
||||
'lavender': '#C084FC', // 强调色 - 薰衣草紫
|
||||
'green': '#4ADE80', // 强调色 - 鲜绿 (成功状态)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2.2 使用规范
|
||||
|
||||
| 颜色 | 用途 |
|
||||
|------|------|
|
||||
| `brutal-cream` | 页面背景、卡片背景 |
|
||||
| `brutal-pink` | 主按钮、主要操作、醒目标题 |
|
||||
| `brutal-cyan` | 次要按钮、链接、信息提示 |
|
||||
| `brutal-yellow` | 警告按钮、高亮文字、选中状态 |
|
||||
| `brutal-green` | 成功状态、确认按钮 |
|
||||
| `brutal-lavender` | 装饰元素、标签背景 |
|
||||
| `black` | 文字、边框、阴影 |
|
||||
| `white` | 卡片背景、输入框背景 |
|
||||
|
||||
---
|
||||
|
||||
## 3. 排版系统
|
||||
|
||||
### 3.1 字体
|
||||
|
||||
```javascript
|
||||
fontFamily: {
|
||||
'display': ['system-ui', '-apple-system', 'sans-serif'],
|
||||
}
|
||||
```
|
||||
|
||||
- 使用系统字体栈,确保跨平台一致性
|
||||
- 无需加载外部字体,提升性能
|
||||
|
||||
### 3.2 字号规范
|
||||
|
||||
| 元素 | 字号 | 字重 | 用途 |
|
||||
|------|------|------|------|
|
||||
| 页面标题 | `text-2xl` (24px) | `font-bold` (700) | 后台页面标题栏 |
|
||||
| 卡片标题 | `text-lg` (18px) | `font-bold` (700) | 文章卡片标题 |
|
||||
| 正文 | `text-sm` (14px) | `font-normal` (400) | 段落文字 |
|
||||
| 小字 | `text-xs` (12px) | `font-medium` (500) | 标签、时间戳 |
|
||||
| 按钮文字 | `text-sm`/`text-xs` | `font-bold` (700) | 按钮内文字 |
|
||||
|
||||
---
|
||||
|
||||
## 4. 阴影系统
|
||||
|
||||
### 4.1 阴影定义
|
||||
|
||||
```javascript
|
||||
boxShadow: {
|
||||
'brutal': '4px 4px 0px 0px rgba(0,0,0,1)', // 标准阴影
|
||||
'brutal-sm': '2px 2px 0px 0px rgba(0,0,0,1)', // 小阴影
|
||||
'brutal-lg': '6px 6px 0px 0px rgba(0,0,0,1)', // 大阴影
|
||||
}
|
||||
```
|
||||
|
||||
### 4.2 使用场景
|
||||
|
||||
| 阴影 | 用途 |
|
||||
|------|------|
|
||||
| `shadow-brutal-lg` | 登录卡片、模态框 |
|
||||
| `shadow-brutal` | 标准卡片、按钮(默认状态) |
|
||||
| `shadow-brutal-sm` | 输入框、小按钮、标签 |
|
||||
| `shadow-none` | 按钮(悬停/点击状态) |
|
||||
|
||||
---
|
||||
|
||||
## 5. 组件规范
|
||||
|
||||
### 5.1 按钮 (Button)
|
||||
|
||||
```jsx
|
||||
// 基础样式
|
||||
const baseClasses = 'inline-flex items-center justify-center font-bold
|
||||
transition-all duration-150 border-2 border-black'
|
||||
|
||||
// 变体
|
||||
primary: 'bg-brutal-pink text-black shadow-brutal ...'
|
||||
secondary: 'bg-brutal-cyan text-black shadow-brutal ...'
|
||||
success: 'bg-brutal-green text-black shadow-brutal ...'
|
||||
warning: 'bg-brutal-yellow text-black shadow-brutal ...'
|
||||
danger: 'bg-red-500 text-white shadow-brutal ...'
|
||||
outline: 'bg-white text-black shadow-brutal-sm ...'
|
||||
|
||||
// 尺寸
|
||||
sm: 'px-3 py-1.5 text-xs'
|
||||
md: 'px-4 py-2 text-sm'
|
||||
lg: 'px-6 py-3 text-base'
|
||||
```
|
||||
|
||||
**交互效果**:
|
||||
- 默认: 有阴影,无位移
|
||||
- 悬停: `hover:shadow-none hover:translate-x-[2px] hover:translate-y-[2px]`
|
||||
- 点击: `active:translate-x-[4px] active:translate-y-[4px]`
|
||||
|
||||
### 5.2 卡片 (Card)
|
||||
|
||||
```jsx
|
||||
// 基础样式
|
||||
'bg-white border-2 border-black shadow-brutal'
|
||||
|
||||
// 内边距选项
|
||||
none: ''
|
||||
small: 'p-3'
|
||||
normal: 'p-4'
|
||||
large: 'p-6'
|
||||
```
|
||||
|
||||
**结构组件**:
|
||||
- `CardHeader`: 带底部边框的头部区域
|
||||
- `CardTitle`: 粗体标题
|
||||
- `CardContent`: 内容区域
|
||||
|
||||
### 5.3 输入框 (Input)
|
||||
|
||||
```jsx
|
||||
// 样式
|
||||
'w-full px-3 py-2 border-2 border-black bg-white
|
||||
focus:outline-none focus:ring-2 focus:ring-brutal-yellow
|
||||
placeholder:text-black/40'
|
||||
```
|
||||
|
||||
### 5.4 导航
|
||||
|
||||
```jsx
|
||||
// 导航链接 - 默认
|
||||
'px-3 py-1 font-bold text-sm border-2 border-transparent
|
||||
hover:border-black hover:bg-white transition-all duration-150'
|
||||
|
||||
// 导航链接 - 激活状态
|
||||
'px-3 py-1 font-bold text-sm border-2 border-black bg-brutal-yellow'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. 布局系统
|
||||
|
||||
### 6.1 后台布局 (Layout)
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────┐
|
||||
│ Sidebar │ Header (标题 + 操作按钮) │
|
||||
│ ├─────────────────────────────────┤
|
||||
│ 导航菜单 │ │
|
||||
│ │ │
|
||||
│ 📁 文章 │ Content Area │
|
||||
│ 🏷️ 分类 │ (可滚动内容区域) │
|
||||
│ 🖼️ 图片 │ │
|
||||
│ ⚙️ 设置 │ │
|
||||
│ │ │
|
||||
└───────────┴─────────────────────────────────┘
|
||||
```
|
||||
|
||||
**结构**:
|
||||
- 左侧固定侧边栏 (Sidebar)
|
||||
- 右侧主内容区
|
||||
- 顶部标题栏带操作按钮区域
|
||||
|
||||
### 6.2 首页布局 (Home)
|
||||
|
||||
两种展示模式:
|
||||
|
||||
**卡片模式 (Card)**:
|
||||
```
|
||||
┌──────────────────────────────────────────┐
|
||||
│ 🏠 博客名称 🔍 分类筛选器 │
|
||||
├──────────────────────────────────────────┤
|
||||
│ │
|
||||
│ ┌──────────┐ ┌──────────┐ ┌────────┐ │
|
||||
│ │ 文章卡片 │ │ 文章卡片 │ │文章卡片 │ │
|
||||
│ │ │ │ │ │ │ │
|
||||
│ └──────────┘ └──────────┘ └────────┘ │
|
||||
│ │
|
||||
│ ┌──────────┐ ┌──────────┐ │
|
||||
│ │ 文章卡片 │ │ 文章卡片 │ │
|
||||
│ └──────────┘ └──────────┘ │
|
||||
│ │
|
||||
└──────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
**列表模式 (List)**:
|
||||
```
|
||||
┌──────────────────────────────────────────┐
|
||||
│ 文章标题 1 .................... 2024-01 │
|
||||
├──────────────────────────────────────────┤
|
||||
│ 文章标题 2 .................... 2024-01 │
|
||||
├──────────────────────────────────────────┤
|
||||
│ 文章标题 3 .................... 2024-01 │
|
||||
└──────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 7. 动效规范
|
||||
|
||||
### 7.1 过渡时间
|
||||
|
||||
```css
|
||||
transition-all duration-150 /* 按钮、链接 */
|
||||
transition-all duration-200 /* 卡片悬停 */
|
||||
transition-all duration-300 /* 页面切换 */
|
||||
```
|
||||
|
||||
### 7.2 交互模式
|
||||
|
||||
**按钮点击**:
|
||||
1. 默认: 阴影 `4px 4px 0px black`
|
||||
2. 悬停: 阴影消失,元素右下移 2px
|
||||
3. 点击: 元素继续右下移 4px
|
||||
|
||||
**卡片悬停**:
|
||||
```css
|
||||
hover:shadow-brutal-lg hover:-translate-y-1
|
||||
```
|
||||
|
||||
**页面过渡**:
|
||||
使用 React Router 的默认过渡,无需额外动画。
|
||||
|
||||
---
|
||||
|
||||
## 8. 自定义样式
|
||||
|
||||
### 8.1 滚动条
|
||||
|
||||
```css
|
||||
/* 自定义滚动条 - 新粗野主义风格 */
|
||||
::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background: #FEF9E7;
|
||||
border-left: 2px solid black;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: #000;
|
||||
border: 2px solid #FEF9E7;
|
||||
}
|
||||
```
|
||||
|
||||
### 8.2 文字选中
|
||||
|
||||
```css
|
||||
::selection {
|
||||
background: #FFDE59; /* 黄色高亮 */
|
||||
color: #000;
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 9. 响应式设计
|
||||
|
||||
### 9.1 断点
|
||||
|
||||
使用 Tailwind 默认断点:
|
||||
- `sm`: 640px
|
||||
- `md`: 768px
|
||||
- `lg`: 1024px
|
||||
- `xl`: 1280px
|
||||
|
||||
### 9.2 适配规则
|
||||
|
||||
| 元素 | 桌面端 | 平板 | 手机 |
|
||||
|------|--------|------|------|
|
||||
| 侧边栏 | 固定显示 | 可折叠 | 隐藏/汉堡菜单 |
|
||||
| 文章网格 | 3列 | 2列 | 1列 |
|
||||
| 卡片内边距 | `p-6` | `p-4` | `p-3` |
|
||||
| 标题字号 | `text-2xl` | `text-xl` | `text-lg` |
|
||||
|
||||
---
|
||||
|
||||
## 10. 技术栈
|
||||
|
||||
### 10.1 前端
|
||||
|
||||
| 技术 | 版本 | 用途 |
|
||||
|------|------|------|
|
||||
| React | 18.x | UI 框架 |
|
||||
| Vite | 5.x | 构建工具 |
|
||||
| React Router | 6.x | 路由管理 |
|
||||
| Tailwind CSS | 3.x | 样式系统 |
|
||||
| react-markdown | latest | Markdown 渲染 |
|
||||
|
||||
### 10.2 后端
|
||||
|
||||
| 技术 | 版本 | 用途 |
|
||||
|------|------|------|
|
||||
| FastAPI | latest | Web 框架 |
|
||||
| SQLAlchemy | 2.x | ORM |
|
||||
| SQLite | 3.x | 数据库 |
|
||||
| Pydantic | 2.x | 数据验证 |
|
||||
| JWT | latest | 认证 |
|
||||
|
||||
### 10.3 部署
|
||||
|
||||
- 前端: 静态文件通过 Nginx serving
|
||||
- 后端: Systemd 服务管理
|
||||
- 端口: 8888 (前端), 8889 (后端)
|
||||
|
||||
---
|
||||
|
||||
## 11. 文件结构
|
||||
|
||||
```
|
||||
personal-blog/
|
||||
├── DESIGN.md # 本文档
|
||||
├── backend/ # FastAPI 后端
|
||||
│ ├── app.py # 主入口
|
||||
│ ├── models.py # 数据库模型
|
||||
│ ├── database.py # 数据库连接
|
||||
│ └── routers/ # API 路由
|
||||
│ ├── auth.py # 认证
|
||||
│ ├── posts.py # 文章
|
||||
│ ├── categories.py # 分类
|
||||
│ ├── images.py # 图片
|
||||
│ ├── settings.py # 设置
|
||||
│ └── crawl.py # 文章采集
|
||||
├── frontend/ # React 前端
|
||||
│ ├── src/
|
||||
│ │ ├── components/ # 通用组件
|
||||
│ │ │ ├── Button.jsx # 按钮组件
|
||||
│ │ │ ├── Card.jsx # 卡片组件
|
||||
│ │ │ ├── Input.jsx # 输入组件
|
||||
│ │ │ ├── Layout.jsx # 布局组件
|
||||
│ │ │ └── Sidebar.jsx # 侧边栏
|
||||
│ │ ├── pages/ # 页面组件
|
||||
│ │ │ ├── Home.jsx # 访客首页
|
||||
│ │ │ ├── PostDetail.jsx # 文章详情
|
||||
│ │ │ ├── Login.jsx # 登录页
|
||||
│ │ │ ├── Dashboard.jsx # 后台首页
|
||||
│ │ │ ├── Posts.jsx # 文章管理
|
||||
│ │ │ └── admin/ # 管理页面
|
||||
│ │ ├── api/ # API 封装
|
||||
│ │ ├── index.css # 全局样式
|
||||
│ │ └── main.jsx # 入口
|
||||
│ └── tailwind.config.js # Tailwind 配置
|
||||
└── uploads/ # 上传文件目录
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 12. 扩展建议
|
||||
|
||||
### 12.1 短期优化
|
||||
|
||||
1. **代码高亮**: 添加 Prism.js 或 highlight.js 支持代码高亮
|
||||
2. **暗色模式**: 考虑添加暗色主题切换
|
||||
3. **动画增强**: 添加页面加载动画、列表进入动画
|
||||
4. **搜索功能**: 添加文章搜索功能
|
||||
|
||||
### 12.2 长期规划
|
||||
|
||||
1. **主题市场**: 支持多套主题切换
|
||||
2. **插件系统**: 允许第三方插件扩展
|
||||
3. **统计分析**: 添加访问统计面板
|
||||
4. **多语言**: i18n 国际化支持
|
||||
|
||||
---
|
||||
|
||||
## 13. 参考资源
|
||||
|
||||
- [Slock.ai](https://slock.ai/) - 新粗野主义设计参考
|
||||
- [Neobrutalism.dev](https://neobrutalism.dev/) - 组件库参考
|
||||
- [Tailwind CSS 文档](https://tailwindcss.com/docs)
|
||||
- [React 文档](https://react.dev/)
|
||||
- [FastAPI 文档](https://fastapi.tiangolo.com/)
|
||||
|
||||
---
|
||||
|
||||
## 14. 更新日志
|
||||
|
||||
| 日期 | 版本 | 变更内容 |
|
||||
|------|------|----------|
|
||||
| 2026-04-06 | v1.0 | 初始版本,整合 Slock.ai 风格 |
|
||||
|
||||
---
|
||||
|
||||
*本文档由 AI 助手生成,如有疑问请联系维护人员。*
|
||||
@@ -0,0 +1,76 @@
|
||||
"""
|
||||
个人博客后端 - FastAPI
|
||||
"""
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
import os
|
||||
|
||||
from database import engine, Base
|
||||
from routers import auth, posts, categories, tags, images, settings, crawl
|
||||
|
||||
# 创建数据库表
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
# 初始化默认管理员
|
||||
from database import SessionLocal
|
||||
from routers.auth import init_admin
|
||||
db = SessionLocal()
|
||||
init_admin(db)
|
||||
db.close()
|
||||
|
||||
app = FastAPI(
|
||||
title="Personal Blog API",
|
||||
description="个人博客后端API",
|
||||
version="1.0.0",
|
||||
redirect_slashes=False
|
||||
)
|
||||
|
||||
# CORS配置 - 允许远程访问
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=[
|
||||
"http://localhost:5173",
|
||||
"http://localhost:3000",
|
||||
"http://127.0.0.1:5173",
|
||||
"http://0.0.0.0:5173",
|
||||
# 允许所有IP访问(开发模式)
|
||||
"*"
|
||||
],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# 注册路由
|
||||
app.include_router(auth.router)
|
||||
app.include_router(posts.router)
|
||||
app.include_router(categories.router)
|
||||
app.include_router(tags.router)
|
||||
app.include_router(images.router)
|
||||
app.include_router(settings.router)
|
||||
app.include_router(crawl.router)
|
||||
|
||||
# 静态文件服务(图片访问)
|
||||
uploads_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "uploads")
|
||||
os.makedirs(uploads_dir, exist_ok=True)
|
||||
app.mount("/uploads", StaticFiles(directory=uploads_dir), name="uploads")
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def root():
|
||||
return {
|
||||
"message": "Personal Blog API",
|
||||
"version": "1.0.0",
|
||||
"docs": "/docs"
|
||||
}
|
||||
|
||||
|
||||
@app.get("/api/health")
|
||||
def health_check():
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=8888)
|
||||
@@ -0,0 +1,27 @@
|
||||
"""
|
||||
数据库配置 - SQLite
|
||||
"""
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
import os
|
||||
|
||||
# 数据库路径
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
DATABASE_URL = f"sqlite:///{os.path.join(BASE_DIR, 'blog.db')}"
|
||||
|
||||
engine = create_engine(
|
||||
DATABASE_URL,
|
||||
connect_args={"check_same_thread": False}
|
||||
)
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
# 依赖注入
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
数据迁移脚本 - 从备份数据库恢复文章数据
|
||||
"""
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
def migrate_posts():
|
||||
"""迁移文章数据"""
|
||||
db_path = 'blog.db'
|
||||
backup_path = 'blog.db.backup'
|
||||
|
||||
if not os.path.exists(backup_path):
|
||||
print("备份文件不存在")
|
||||
return
|
||||
|
||||
# 连接两个数据库
|
||||
conn_new = sqlite3.connect(db_path)
|
||||
conn_old = sqlite3.connect(backup_path)
|
||||
|
||||
cursor_new = conn_new.cursor()
|
||||
cursor_old = conn_old.cursor()
|
||||
|
||||
# 检查旧表结构
|
||||
cursor_old.execute("PRAGMA table_info(posts)")
|
||||
old_columns = [col[1] for col in cursor_old.fetchall()]
|
||||
print(f"旧表字段: {old_columns}")
|
||||
|
||||
# 获取所有文章
|
||||
cursor_old.execute("SELECT * FROM posts")
|
||||
posts = cursor_old.fetchall()
|
||||
print(f"找到 {len(posts)} 篇文章")
|
||||
|
||||
# 清空新表并重新插入
|
||||
cursor_new.execute("DELETE FROM posts")
|
||||
|
||||
for post in posts:
|
||||
# post: (id, title, content, summary, cover_image, is_published, is_draft, view_count, created_at, updated_at, category_id)
|
||||
cursor_new.execute("""
|
||||
INSERT INTO posts (id, title, content, summary, cover_image, is_published, is_draft, view_count, created_at, updated_at, category_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""", post)
|
||||
print(f" 已恢复: {post[1][:30]}...")
|
||||
|
||||
conn_new.commit()
|
||||
conn_new.close()
|
||||
conn_old.close()
|
||||
|
||||
print(f"\n✅ 成功恢复 {len(posts)} 篇文章")
|
||||
|
||||
if __name__ == '__main__':
|
||||
migrate_posts()
|
||||
@@ -0,0 +1,109 @@
|
||||
"""
|
||||
数据库模型
|
||||
"""
|
||||
from sqlalchemy import Column, Integer, String, Text, DateTime, Boolean, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
from database import Base
|
||||
|
||||
class Admin(Base):
|
||||
"""管理员账号"""
|
||||
__tablename__ = "admins"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
username = Column(String, unique=True, index=True, default="admin")
|
||||
password_hash = Column(String)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
class Post(Base):
|
||||
"""文章"""
|
||||
__tablename__ = "posts"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
title = Column(String(200), nullable=False)
|
||||
slug = Column(String(200), unique=True, index=True) # URL友好的标识
|
||||
content = Column(Text, nullable=False)
|
||||
summary = Column(String(500))
|
||||
cover_image = Column(String(500)) # 封面图路径
|
||||
is_published = Column(Boolean, default=True)
|
||||
is_draft = Column(Boolean, default=False)
|
||||
view_count = Column(Integer, default=0)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# 关联
|
||||
category_id = Column(Integer, ForeignKey("categories.id"))
|
||||
category = relationship("Category", back_populates="posts")
|
||||
tags = relationship("Tag", secondary="post_tags", back_populates="posts")
|
||||
|
||||
class Category(Base):
|
||||
"""栏目/分类"""
|
||||
__tablename__ = "categories"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(50), unique=True, nullable=False)
|
||||
description = Column(String(200))
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
posts = relationship("Post", back_populates="category")
|
||||
|
||||
class Tag(Base):
|
||||
"""标签"""
|
||||
__tablename__ = "tags"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(30), unique=True, nullable=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
posts = relationship("Post", secondary="post_tags", back_populates="tags")
|
||||
|
||||
# 文章-标签关联表
|
||||
class PostTag(Base):
|
||||
__tablename__ = "post_tags"
|
||||
|
||||
post_id = Column(Integer, ForeignKey("posts.id"), primary_key=True)
|
||||
tag_id = Column(Integer, ForeignKey("tags.id"), primary_key=True)
|
||||
|
||||
class Image(Base):
|
||||
"""上传的图片"""
|
||||
__tablename__ = "images"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
filename = Column(String(255), nullable=False)
|
||||
original_name = Column(String(255))
|
||||
file_path = Column(String(500), nullable=False) # 原图路径 /uploads/xxx.jpg
|
||||
thumb_path = Column(String(500)) # 缩略图路径 /uploads/thumbnails/xxx.jpg
|
||||
description = Column(String(500))
|
||||
file_size = Column(Integer) # 字节
|
||||
width = Column(Integer) # 图片宽度
|
||||
height = Column(Integer) # 图片高度
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
class Setting(Base):
|
||||
"""博客设置"""
|
||||
__tablename__ = "settings"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
blog_name = Column(String(20), default="我的博客")
|
||||
blog_description = Column(String(200), default="")
|
||||
welcome_message = Column(String(300), default="欢迎来到我的博客 👋 分享技术、生活与思考")
|
||||
blog_logo = Column(String(500))
|
||||
banner_image = Column(String(500))
|
||||
banner_type = Column(String(20), default="text") # text或carousel
|
||||
banner_images = Column(String(1000), default="[]") # JSON数组存储轮播图
|
||||
theme = Column(String(20), default="neobrutalism") # 默认新粗野主义
|
||||
layout = Column(String(20), default="card") # card或list
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
class Page(Base):
|
||||
"""自定义页面"""
|
||||
__tablename__ = "pages"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
title = Column(String(50), nullable=False)
|
||||
slug = Column(String(50), unique=True, nullable=False) # URL标识
|
||||
content = Column(Text, nullable=False)
|
||||
is_nav = Column(Boolean, default=True) # 是否在导航显示
|
||||
nav_order = Column(Integer, default=0) # 导航排序
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
@@ -0,0 +1,8 @@
|
||||
fastapi==0.115.0
|
||||
uvicorn[standard]==0.32.0
|
||||
sqlalchemy==2.0.36
|
||||
pydantic==2.9.2
|
||||
python-jose[cryptography]==3.3.0
|
||||
passlib[bcrypt]==1.7.4
|
||||
python-multipart==0.0.17
|
||||
pillow==11.0.0
|
||||
@@ -0,0 +1,125 @@
|
||||
"""
|
||||
认证路由
|
||||
"""
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime, timedelta
|
||||
from jose import JWTError, jwt
|
||||
from passlib.context import CryptContext
|
||||
import os
|
||||
|
||||
import sys
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from database import get_db
|
||||
from models import Admin
|
||||
from schemas import LoginRequest, LoginResponse, PasswordChange
|
||||
|
||||
router = APIRouter(prefix="/api/auth", tags=["认证"])
|
||||
|
||||
# 安全配置
|
||||
SECRET_KEY = "your-secret-key-change-in-production" # 生产环境修改
|
||||
ALGORITHM = "HS256"
|
||||
ACCESS_TOKEN_EXPIRE_DAYS = 7
|
||||
|
||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/auth/login")
|
||||
|
||||
|
||||
def verify_password(plain_password, hashed_password):
|
||||
"""验证密码"""
|
||||
return pwd_context.verify(plain_password, hashed_password)
|
||||
|
||||
|
||||
def get_password_hash(password):
|
||||
"""生成密码哈希"""
|
||||
return pwd_context.hash(password)
|
||||
|
||||
|
||||
def create_access_token(data: dict, expires_delta: timedelta = None):
|
||||
"""创建JWT令牌"""
|
||||
to_encode = data.copy()
|
||||
if expires_delta:
|
||||
expire = datetime.utcnow() + expires_delta
|
||||
else:
|
||||
expire = datetime.utcnow() + timedelta(days=ACCESS_TOKEN_EXPIRE_DAYS)
|
||||
to_encode.update({"exp": expire})
|
||||
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
|
||||
return encoded_jwt
|
||||
|
||||
|
||||
async def get_current_admin(token: str = Depends(oauth2_scheme), db: Session = Depends(get_db)):
|
||||
"""获取当前登录管理员"""
|
||||
credentials_exception = HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="无法验证凭据",
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
)
|
||||
try:
|
||||
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
|
||||
username: str = payload.get("sub")
|
||||
if username is None:
|
||||
raise credentials_exception
|
||||
except JWTError:
|
||||
raise credentials_exception
|
||||
|
||||
admin = db.query(Admin).filter(Admin.username == username).first()
|
||||
if admin is None:
|
||||
raise credentials_exception
|
||||
return admin
|
||||
|
||||
|
||||
@router.post("/login", response_model=LoginResponse)
|
||||
def login(login_data: LoginRequest, db: Session = Depends(get_db)):
|
||||
"""管理员登录"""
|
||||
admin = db.query(Admin).filter(Admin.username == login_data.username).first()
|
||||
|
||||
if not admin or not verify_password(login_data.password, admin.password_hash):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="用户名或密码错误"
|
||||
)
|
||||
|
||||
access_token = create_access_token(data={"sub": admin.username})
|
||||
return {"access_token": access_token, "token_type": "bearer"}
|
||||
|
||||
|
||||
@router.post("/change-password")
|
||||
def change_password(
|
||||
password_data: PasswordChange,
|
||||
current_admin: Admin = Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""修改密码"""
|
||||
# 验证原密码
|
||||
if not verify_password(password_data.old_password, current_admin.password_hash):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="原密码错误"
|
||||
)
|
||||
|
||||
# 更新密码
|
||||
current_admin.password_hash = get_password_hash(password_data.new_password)
|
||||
db.commit()
|
||||
|
||||
return {"message": "密码修改成功"}
|
||||
|
||||
|
||||
@router.get("/me")
|
||||
def get_me(current_admin: Admin = Depends(get_current_admin)):
|
||||
"""获取当前管理员信息"""
|
||||
return {"username": current_admin.username}
|
||||
|
||||
|
||||
def init_admin(db: Session):
|
||||
"""初始化默认管理员账号"""
|
||||
admin = db.query(Admin).filter(Admin.username == "admin").first()
|
||||
if not admin:
|
||||
admin = Admin(
|
||||
username="admin",
|
||||
password_hash=get_password_hash("admin123")
|
||||
)
|
||||
db.add(admin)
|
||||
db.commit()
|
||||
print("✅ 默认管理员账号已创建: admin / admin123")
|
||||
@@ -0,0 +1,113 @@
|
||||
"""
|
||||
分类管理路由
|
||||
"""
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from database import get_db
|
||||
from models import Category, Post
|
||||
from schemas import CategoryCreate, CategoryResponse
|
||||
from routers.auth import get_current_admin
|
||||
|
||||
router = APIRouter(prefix="/api/categories", tags=["分类"])
|
||||
|
||||
|
||||
@router.get("", response_model=List[CategoryResponse])
|
||||
def get_categories(db: Session = Depends(get_db)):
|
||||
"""获取所有分类"""
|
||||
categories = db.query(Category).all()
|
||||
# 添加文章数量
|
||||
result = []
|
||||
for cat in categories:
|
||||
post_count = db.query(Post).filter(Post.category_id == cat.id).count()
|
||||
cat_dict = {
|
||||
"id": cat.id,
|
||||
"name": cat.name,
|
||||
"description": cat.description,
|
||||
"created_at": cat.created_at,
|
||||
"post_count": post_count
|
||||
}
|
||||
result.append(cat_dict)
|
||||
return result
|
||||
|
||||
|
||||
@router.post("", response_model=CategoryResponse)
|
||||
def create_category(
|
||||
category_data: CategoryCreate,
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""创建分类"""
|
||||
# 检查数量限制
|
||||
count = db.query(Category).count()
|
||||
if count >= 25:
|
||||
raise HTTPException(status_code=400, detail="分类数量已达上限(25个)")
|
||||
|
||||
# 检查名称重复
|
||||
existing = db.query(Category).filter(Category.name == category_data.name).first()
|
||||
if existing:
|
||||
raise HTTPException(status_code=400, detail="分类名称已存在")
|
||||
|
||||
category = Category(**category_data.dict())
|
||||
db.add(category)
|
||||
db.commit()
|
||||
db.refresh(category)
|
||||
|
||||
return {
|
||||
"id": category.id,
|
||||
"name": category.name,
|
||||
"description": category.description,
|
||||
"created_at": category.created_at,
|
||||
"post_count": 0
|
||||
}
|
||||
|
||||
|
||||
@router.put("/{category_id}", response_model=CategoryResponse)
|
||||
def update_category(
|
||||
category_id: int,
|
||||
category_data: CategoryCreate,
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""更新分类"""
|
||||
category = db.query(Category).filter(Category.id == category_id).first()
|
||||
if not category:
|
||||
raise HTTPException(status_code=404, detail="分类不存在")
|
||||
|
||||
category.name = category_data.name
|
||||
category.description = category_data.description
|
||||
db.commit()
|
||||
db.refresh(category)
|
||||
|
||||
post_count = db.query(Post).filter(Post.category_id == category.id).count()
|
||||
return {
|
||||
"id": category.id,
|
||||
"name": category.name,
|
||||
"description": category.description,
|
||||
"created_at": category.created_at,
|
||||
"post_count": post_count
|
||||
}
|
||||
|
||||
|
||||
@router.delete("/{category_id}")
|
||||
def delete_category(
|
||||
category_id: int,
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""删除分类"""
|
||||
category = db.query(Category).filter(Category.id == category_id).first()
|
||||
if not category:
|
||||
raise HTTPException(status_code=404, detail="分类不存在")
|
||||
|
||||
# 将该分类下的文章设为未分类
|
||||
db.query(Post).filter(Post.category_id == category_id).update({"category_id": None})
|
||||
|
||||
db.delete(category)
|
||||
db.commit()
|
||||
return {"message": "分类已删除"}
|
||||
@@ -0,0 +1,541 @@
|
||||
"""
|
||||
图片上传管理路由
|
||||
"""
|
||||
from fastapi import APIRouter, UploadFile, File, Depends, HTTPException, Query
|
||||
from fastapi.responses import FileResponse
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List, Optional
|
||||
import os
|
||||
import uuid
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
from PIL import Image as PILImage
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from database import get_db
|
||||
from models import Image, Post, Setting, Page
|
||||
from routers.auth import get_current_admin
|
||||
|
||||
router = APIRouter(prefix="/api/images", tags=["图片"])
|
||||
|
||||
# 上传配置
|
||||
UPLOAD_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "uploads")
|
||||
THUMB_DIR = os.path.join(UPLOAD_DIR, "thumbnails")
|
||||
ALLOWED_EXTENSIONS = {'.jpg', '.jpeg', '.png', '.gif', '.webp', '.svg'}
|
||||
MAX_FILE_SIZE = 10 * 1024 * 1024 # 10MB
|
||||
THUMB_WIDTH = 320 # 缩略图宽度
|
||||
THUMB_QUALITY = 85
|
||||
|
||||
# 确保上传目录存在
|
||||
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
||||
os.makedirs(THUMB_DIR, exist_ok=True)
|
||||
|
||||
|
||||
def generate_thumbnail(img_path: str, thumb_path: str) -> bool:
|
||||
"""生成缩略图"""
|
||||
try:
|
||||
# 检查是否是 SVG 文件
|
||||
if img_path.lower().endswith('.svg'):
|
||||
# SVG 直接复制作为"缩略图"(矢量图不需要缩放)
|
||||
import shutil
|
||||
shutil.copy2(img_path, thumb_path)
|
||||
return True
|
||||
|
||||
# 使用 Pillow 生成缩略图(不需要 ImageMagick,更轻量)
|
||||
with PILImage.open(img_path) as img:
|
||||
# 转换为 RGB(处理 PNG 透明背景等)
|
||||
if img.mode in ('RGBA', 'LA', 'P'):
|
||||
img = img.convert('RGB')
|
||||
|
||||
# 计算等比例缩放后的高度
|
||||
ratio = THUMB_WIDTH / img.width
|
||||
thumb_height = int(img.height * ratio)
|
||||
|
||||
# 生成缩略图
|
||||
thumb = img.resize((THUMB_WIDTH, thumb_height), PILImage.Resampling.LANCZOS)
|
||||
|
||||
# 保存
|
||||
ext = os.path.splitext(thumb_path)[1].lower()
|
||||
if ext == '.png':
|
||||
thumb.save(thumb_path, 'PNG')
|
||||
else:
|
||||
thumb.save(thumb_path, 'JPEG', quality=THUMB_QUALITY)
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"生成缩略图失败: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def get_image_dimensions(img_path: str) -> tuple:
|
||||
"""获取图片尺寸"""
|
||||
try:
|
||||
# SVG 文件特殊处理
|
||||
if img_path.lower().endswith('.svg'):
|
||||
return get_svg_dimensions(img_path)
|
||||
|
||||
with PILImage.open(img_path) as img:
|
||||
return img.width, img.height
|
||||
except:
|
||||
return None, None
|
||||
|
||||
|
||||
def get_svg_dimensions(svg_path: str) -> tuple:
|
||||
"""从 SVG 文件中提取宽度和高度"""
|
||||
try:
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
# 解析 SVG 文件
|
||||
tree = ET.parse(svg_path)
|
||||
root = tree.getroot()
|
||||
|
||||
# 获取 width 和 height 属性
|
||||
width = root.get('width', '')
|
||||
height = root.get('height', '')
|
||||
|
||||
# 解析 viewBox 作为备选
|
||||
viewbox = root.get('viewBox', '')
|
||||
|
||||
def parse_value(val):
|
||||
"""解析数值,移除单位(如 px)"""
|
||||
if not val:
|
||||
return None
|
||||
# 移除常见单位
|
||||
val = val.strip().replace('px', '').replace('pt', '').replace('em', '').replace('rem', '')
|
||||
try:
|
||||
return int(float(val))
|
||||
except:
|
||||
return None
|
||||
|
||||
w = parse_value(width)
|
||||
h = parse_value(height)
|
||||
|
||||
# 如果没有 width/height,尝试从 viewBox 解析
|
||||
if (w is None or h is None) and viewbox:
|
||||
parts = viewbox.replace(',', ' ').split()
|
||||
if len(parts) >= 4:
|
||||
# viewBox="minX minY width height"
|
||||
w = parse_value(parts[2]) if w is None else w
|
||||
h = parse_value(parts[3]) if h is None else h
|
||||
|
||||
# 返回默认值如果无法解析
|
||||
return w or 100, h or 100
|
||||
except Exception as e:
|
||||
print(f"解析 SVG 尺寸失败: {e}")
|
||||
return 100, 100
|
||||
|
||||
|
||||
def allowed_file(filename):
|
||||
"""检查文件扩展名"""
|
||||
return os.path.splitext(filename.lower())[1] in ALLOWED_EXTENSIONS
|
||||
|
||||
|
||||
@router.get("")
|
||||
def get_images(
|
||||
skip: int = 0,
|
||||
limit: int = 50,
|
||||
db: Session = Depends(get_db),
|
||||
current_admin=Depends(get_current_admin)
|
||||
):
|
||||
"""获取图片列表(按时间倒序)"""
|
||||
total = db.query(Image).count()
|
||||
images = db.query(Image).order_by(Image.created_at.desc()).offset(skip).limit(limit).all()
|
||||
|
||||
return {
|
||||
"items": [
|
||||
{
|
||||
"id": img.id,
|
||||
"filename": img.filename,
|
||||
"original_name": img.original_name,
|
||||
"file_path": img.file_path,
|
||||
"thumb_path": img.thumb_path,
|
||||
"description": img.description,
|
||||
"file_size": img.file_size,
|
||||
"width": img.width,
|
||||
"height": img.height,
|
||||
"created_at": img.created_at.isoformat() if img.created_at else None
|
||||
}
|
||||
for img in images
|
||||
],
|
||||
"total": total,
|
||||
"skip": skip,
|
||||
"limit": limit
|
||||
}
|
||||
|
||||
|
||||
@router.post("/upload")
|
||||
async def upload_image(
|
||||
file: UploadFile = File(...),
|
||||
description: str = "",
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""上传图片(自动生成缩略图)"""
|
||||
# 检查文件类型
|
||||
if not allowed_file(file.filename):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="不支持的文件格式,仅支持 JPG、PNG、GIF、WebP"
|
||||
)
|
||||
|
||||
# 读取文件内容检查大小
|
||||
content = await file.read()
|
||||
if len(content) > MAX_FILE_SIZE:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"文件大小超过10MB限制"
|
||||
)
|
||||
|
||||
# 生成唯一文件名(统一转 jpg 以便处理)
|
||||
ext = os.path.splitext(file.filename.lower())[1]
|
||||
if ext == '.webp':
|
||||
ext = '.jpg' # webp 转 jpg
|
||||
unique_filename = f"{datetime.now().strftime('%Y%m%d')}_{uuid.uuid4().hex[:8]}{ext}"
|
||||
file_path = os.path.join(UPLOAD_DIR, unique_filename)
|
||||
thumb_filename = f"thumb_{unique_filename}"
|
||||
thumb_path_full = os.path.join(THUMB_DIR, thumb_filename)
|
||||
|
||||
# 保存原文件
|
||||
with open(file_path, "wb") as f:
|
||||
f.write(content)
|
||||
|
||||
# 获取图片尺寸
|
||||
width, height = get_image_dimensions(file_path)
|
||||
|
||||
# 生成缩略图
|
||||
thumb_path_db = None
|
||||
if generate_thumbnail(file_path, thumb_path_full):
|
||||
thumb_path_db = f"/uploads/thumbnails/{thumb_filename}"
|
||||
|
||||
# 保存到数据库
|
||||
image = Image(
|
||||
filename=unique_filename,
|
||||
original_name=file.filename,
|
||||
file_path=f"/uploads/{unique_filename}",
|
||||
thumb_path=thumb_path_db,
|
||||
description=description,
|
||||
file_size=len(content),
|
||||
width=width,
|
||||
height=height
|
||||
)
|
||||
db.add(image)
|
||||
db.commit()
|
||||
db.refresh(image)
|
||||
|
||||
return {
|
||||
"id": image.id,
|
||||
"filename": image.filename,
|
||||
"original_name": image.original_name,
|
||||
"description": image.description,
|
||||
"file_size": image.file_size,
|
||||
"file_path": image.file_path,
|
||||
"thumb_path": image.thumb_path,
|
||||
"width": image.width,
|
||||
"height": image.height,
|
||||
"created_at": image.created_at
|
||||
}
|
||||
|
||||
|
||||
async def process_single_image(file: UploadFile, db: Session):
|
||||
"""处理单张图片(内部函数,用于批量上传)"""
|
||||
# 检查文件类型
|
||||
if not allowed_file(file.filename):
|
||||
raise ValueError(f"不支持的文件格式")
|
||||
|
||||
# 读取内容
|
||||
content = await file.read()
|
||||
if len(content) > MAX_FILE_SIZE:
|
||||
raise ValueError(f"文件大小超过10MB限制")
|
||||
|
||||
# 生成唯一文件名
|
||||
ext = os.path.splitext(file.filename.lower())[1]
|
||||
if ext == '.webp':
|
||||
ext = '.jpg'
|
||||
unique_filename = f"{datetime.now().strftime('%Y%m%d')}_{uuid.uuid4().hex[:8]}{ext}"
|
||||
file_path = os.path.join(UPLOAD_DIR, unique_filename)
|
||||
thumb_filename = f"thumb_{unique_filename}"
|
||||
thumb_path_full = os.path.join(THUMB_DIR, thumb_filename)
|
||||
|
||||
# 保存原文件
|
||||
with open(file_path, "wb") as f:
|
||||
f.write(content)
|
||||
|
||||
# 获取图片尺寸
|
||||
width, height = get_image_dimensions(file_path)
|
||||
|
||||
# 生成缩略图
|
||||
thumb_path_db = None
|
||||
if generate_thumbnail(file_path, thumb_path_full):
|
||||
thumb_path_db = f"/uploads/thumbnails/{thumb_filename}"
|
||||
|
||||
# 保存到数据库
|
||||
image = Image(
|
||||
filename=unique_filename,
|
||||
original_name=file.filename,
|
||||
file_path=f"/uploads/{unique_filename}",
|
||||
thumb_path=thumb_path_db,
|
||||
file_size=len(content),
|
||||
width=width,
|
||||
height=height
|
||||
)
|
||||
db.add(image)
|
||||
db.commit()
|
||||
db.refresh(image)
|
||||
|
||||
return {
|
||||
"id": image.id,
|
||||
"filename": image.filename,
|
||||
"original_name": image.original_name,
|
||||
"file_path": image.file_path,
|
||||
"thumb_path": image.thumb_path,
|
||||
"width": image.width,
|
||||
"height": image.height,
|
||||
"file_size": image.file_size,
|
||||
"created_at": image.created_at
|
||||
}
|
||||
|
||||
|
||||
@router.post("/upload-multiple")
|
||||
async def upload_multiple_images(
|
||||
files: List[UploadFile] = File(...),
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""批量上传图片(最多10张,自动生成缩略图)"""
|
||||
if len(files) > 10:
|
||||
raise HTTPException(status_code=400, detail="一次最多上传10张图片")
|
||||
|
||||
uploaded = []
|
||||
errors = []
|
||||
|
||||
for file in files:
|
||||
try:
|
||||
result = await process_single_image(file, db)
|
||||
uploaded.append(result)
|
||||
except Exception as e:
|
||||
errors.append(f"{file.filename}: {str(e)}")
|
||||
|
||||
return {
|
||||
"uploaded": uploaded,
|
||||
"errors": errors,
|
||||
"total": len(files),
|
||||
"success": len(uploaded)
|
||||
}
|
||||
|
||||
|
||||
@router.get("/serve/{filename}")
|
||||
def serve_image(filename: str):
|
||||
"""提供原图访问"""
|
||||
file_path = os.path.join(UPLOAD_DIR, filename)
|
||||
if not os.path.exists(file_path):
|
||||
raise HTTPException(status_code=404, detail="图片不存在")
|
||||
|
||||
return FileResponse(
|
||||
file_path,
|
||||
headers={
|
||||
"Cache-Control": "no-cache, no-store, must-revalidate",
|
||||
"Pragma": "no-cache",
|
||||
"Expires": "0"
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@router.get("/thumb/{filename}")
|
||||
def serve_thumbnail(filename: str):
|
||||
"""提供缩略图访问"""
|
||||
file_path = os.path.join(THUMB_DIR, filename)
|
||||
if not os.path.exists(file_path):
|
||||
raise HTTPException(status_code=404, detail="缩略图不存在")
|
||||
|
||||
return FileResponse(
|
||||
file_path,
|
||||
headers={
|
||||
"Cache-Control": "no-cache, no-store, must-revalidate",
|
||||
"Pragma": "no-cache",
|
||||
"Expires": "0"
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@router.delete("/{image_id}")
|
||||
def delete_image(
|
||||
image_id: int,
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""删除图片(同时删除缩略图)"""
|
||||
image = db.query(Image).filter(Image.id == image_id).first()
|
||||
if not image:
|
||||
raise HTTPException(status_code=404, detail="图片不存在")
|
||||
|
||||
# 删除原图
|
||||
file_path = os.path.join(UPLOAD_DIR, image.filename)
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
|
||||
# 删除缩略图
|
||||
if image.thumb_path:
|
||||
thumb_filename = os.path.basename(image.thumb_path)
|
||||
thumb_path = os.path.join(THUMB_DIR, thumb_filename)
|
||||
if os.path.exists(thumb_path):
|
||||
os.remove(thumb_path)
|
||||
|
||||
# 删除数据库记录
|
||||
db.delete(image)
|
||||
db.commit()
|
||||
|
||||
return {"message": "图片已删除"}
|
||||
|
||||
|
||||
@router.post("/cleanup-unused")
|
||||
def cleanup_unused_images(
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""清理未使用的图片(未被任何文章、页面、设置引用)"""
|
||||
import json
|
||||
|
||||
# 获取所有图片
|
||||
all_images = db.query(Image).all()
|
||||
|
||||
# 收集所有被使用的图片路径
|
||||
used_paths = set()
|
||||
|
||||
# 1. 检查文章content和cover_image
|
||||
posts = db.query(Post).all()
|
||||
for post in posts:
|
||||
if post.cover_image:
|
||||
used_paths.add(post.cover_image)
|
||||
if post.content:
|
||||
# 提取content中的所有图片路径 /uploads/xxx
|
||||
import re
|
||||
paths = re.findall(r'/uploads/[^\s"\')<>]+', post.content)
|
||||
used_paths.update(paths)
|
||||
|
||||
# 2. 检查页面content
|
||||
pages = db.query(Page).all()
|
||||
for page in pages:
|
||||
if page.content:
|
||||
import re
|
||||
paths = re.findall(r'/uploads/[^\s"\')<>]+', page.content)
|
||||
used_paths.update(paths)
|
||||
|
||||
# 3. 检查设置
|
||||
settings = db.query(Setting).first()
|
||||
if settings:
|
||||
if settings.blog_logo:
|
||||
used_paths.add(settings.blog_logo)
|
||||
if settings.banner_image:
|
||||
used_paths.add(settings.banner_image)
|
||||
# 轮播图
|
||||
if settings.banner_images:
|
||||
try:
|
||||
banner_list = json.loads(settings.banner_images)
|
||||
if isinstance(banner_list, list):
|
||||
used_paths.update(banner_list)
|
||||
except:
|
||||
pass
|
||||
|
||||
# 找出未使用的图片
|
||||
unused_images = []
|
||||
for img in all_images:
|
||||
if img.file_path not in used_paths:
|
||||
unused_images.append(img)
|
||||
|
||||
# 删除未使用的图片
|
||||
deleted_count = 0
|
||||
freed_space = 0
|
||||
|
||||
for img in unused_images:
|
||||
# 删除原图文件
|
||||
file_path = os.path.join(UPLOAD_DIR, img.filename)
|
||||
if os.path.exists(file_path):
|
||||
freed_space += os.path.getsize(file_path)
|
||||
os.remove(file_path)
|
||||
|
||||
# 删除缩略图文件
|
||||
if img.thumb_path:
|
||||
thumb_filename = os.path.basename(img.thumb_path)
|
||||
thumb_path = os.path.join(THUMB_DIR, thumb_filename)
|
||||
if os.path.exists(thumb_path):
|
||||
freed_space += os.path.getsize(thumb_path)
|
||||
os.remove(thumb_path)
|
||||
|
||||
# 删除数据库记录
|
||||
db.delete(img)
|
||||
deleted_count += 1
|
||||
|
||||
db.commit()
|
||||
|
||||
return {
|
||||
"message": f"清理完成,删除 {deleted_count} 张未使用的图片",
|
||||
"deleted_count": deleted_count,
|
||||
"freed_space_bytes": freed_space,
|
||||
"freed_space_mb": round(freed_space / (1024 * 1024), 2)
|
||||
}
|
||||
|
||||
|
||||
@router.get("/usage-stats")
|
||||
def get_image_usage_stats(
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""获取图片使用统计"""
|
||||
import json
|
||||
|
||||
total_images = db.query(Image).count()
|
||||
|
||||
# 收集所有被使用的图片路径
|
||||
used_paths = set()
|
||||
|
||||
# 检查文章
|
||||
posts = db.query(Post).all()
|
||||
for post in posts:
|
||||
if post.cover_image:
|
||||
used_paths.add(post.cover_image)
|
||||
if post.content:
|
||||
import re
|
||||
paths = re.findall(r'/uploads/[^\s"\')<>]+', post.content)
|
||||
used_paths.update(paths)
|
||||
|
||||
# 检查页面
|
||||
pages = db.query(Page).all()
|
||||
for page in pages:
|
||||
if page.content:
|
||||
import re
|
||||
paths = re.findall(r'/uploads/[^\s"\')<>]+', page.content)
|
||||
used_paths.update(paths)
|
||||
|
||||
# 检查设置
|
||||
settings = db.query(Setting).first()
|
||||
if settings:
|
||||
if settings.blog_logo:
|
||||
used_paths.add(settings.blog_logo)
|
||||
if settings.banner_image:
|
||||
used_paths.add(settings.banner_image)
|
||||
if settings.banner_images:
|
||||
try:
|
||||
banner_list = json.loads(settings.banner_images)
|
||||
if isinstance(banner_list, list):
|
||||
used_paths.update(banner_list)
|
||||
except:
|
||||
pass
|
||||
|
||||
# 计算未使用图片
|
||||
all_images = db.query(Image).all()
|
||||
unused_count = 0
|
||||
unused_space = 0
|
||||
|
||||
for img in all_images:
|
||||
if img.file_path not in used_paths:
|
||||
unused_count += 1
|
||||
unused_space += (img.file_size or 0)
|
||||
|
||||
return {
|
||||
"total_images": total_images,
|
||||
"used_images": len(used_paths),
|
||||
"unused_images": unused_count,
|
||||
"unused_space_bytes": unused_space,
|
||||
"unused_space_mb": round(unused_space / (1024 * 1024), 2)
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
"""
|
||||
文章管理路由
|
||||
"""
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List, Optional
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from database import get_db
|
||||
from models import Post, Category, Tag, PostTag, Image
|
||||
from schemas import PostCreate, PostUpdate, PostResponse, PostListItem
|
||||
from routers.auth import get_current_admin
|
||||
import re
|
||||
|
||||
router = APIRouter(prefix="/api/posts", tags=["文章"])
|
||||
|
||||
|
||||
@router.get("", response_model=List[PostListItem])
|
||||
def get_posts(
|
||||
skip: int = Query(0, ge=0),
|
||||
limit: int = Query(10, ge=1, le=100),
|
||||
category_id: Optional[int] = None,
|
||||
tag_id: Optional[int] = None,
|
||||
is_draft: Optional[bool] = None,
|
||||
search: Optional[str] = None,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""获取文章列表(支持筛选)"""
|
||||
query = db.query(Post)
|
||||
|
||||
# 筛选条件
|
||||
if category_id:
|
||||
query = query.filter(Post.category_id == category_id)
|
||||
if tag_id:
|
||||
query = query.join(PostTag).filter(PostTag.tag_id == tag_id)
|
||||
if is_draft is not None:
|
||||
query = query.filter(Post.is_draft == is_draft)
|
||||
if search:
|
||||
query = query.filter(Post.title.contains(search) | Post.content.contains(search))
|
||||
|
||||
# 按时间倒序
|
||||
query = query.order_by(Post.created_at.desc())
|
||||
|
||||
posts = query.offset(skip).limit(limit).all()
|
||||
return posts
|
||||
|
||||
|
||||
@router.get("/{post_id}", response_model=PostResponse)
|
||||
def get_post(post_id: str, db: Session = Depends(get_db)):
|
||||
"""获取单篇文章(支持 id 或 slug)"""
|
||||
# 尝试作为 id 查询
|
||||
try:
|
||||
id_int = int(post_id)
|
||||
post = db.query(Post).filter(Post.id == id_int).first()
|
||||
except ValueError:
|
||||
post = None
|
||||
|
||||
# 如果不是 id,尝试作为 slug 查询
|
||||
if not post:
|
||||
post = db.query(Post).filter(Post.slug == post_id).first()
|
||||
if not post:
|
||||
raise HTTPException(status_code=404, detail="文章不存在")
|
||||
|
||||
# 增加浏览量
|
||||
post.view_count += 1
|
||||
db.commit()
|
||||
|
||||
return post
|
||||
|
||||
|
||||
@router.post("", response_model=PostResponse)
|
||||
def create_post(
|
||||
post_data: PostCreate,
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""创建文章"""
|
||||
# 处理标签
|
||||
tags = []
|
||||
if post_data.tag_ids:
|
||||
tags = db.query(Tag).filter(Tag.id.in_(post_data.tag_ids)).all()
|
||||
|
||||
# 创建文章
|
||||
post = Post(
|
||||
title=post_data.title,
|
||||
content=post_data.content,
|
||||
summary=post_data.summary or post_data.content[:200] + "...",
|
||||
cover_image=post_data.cover_image,
|
||||
is_published=post_data.is_published,
|
||||
is_draft=post_data.is_draft,
|
||||
category_id=post_data.category_id,
|
||||
tags=tags
|
||||
)
|
||||
|
||||
db.add(post)
|
||||
db.commit()
|
||||
db.refresh(post)
|
||||
return post
|
||||
|
||||
|
||||
@router.put("/{post_id}", response_model=PostResponse)
|
||||
def update_post(
|
||||
post_id: int,
|
||||
post_data: PostUpdate,
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""更新文章"""
|
||||
post = db.query(Post).filter(Post.id == post_id).first()
|
||||
if not post:
|
||||
raise HTTPException(status_code=404, detail="文章不存在")
|
||||
|
||||
# 更新字段
|
||||
update_data = post_data.dict(exclude_unset=True)
|
||||
|
||||
# 处理标签
|
||||
if "tag_ids" in update_data:
|
||||
tag_ids = update_data.pop("tag_ids")
|
||||
if tag_ids is not None:
|
||||
post.tags = db.query(Tag).filter(Tag.id.in_(tag_ids)).all()
|
||||
|
||||
# 更新其他字段
|
||||
for field, value in update_data.items():
|
||||
setattr(post, field, value)
|
||||
|
||||
# 自动更新摘要
|
||||
if post_data.content and not post_data.summary:
|
||||
post.summary = post_data.content[:200] + "..."
|
||||
|
||||
db.commit()
|
||||
db.refresh(post)
|
||||
return post
|
||||
|
||||
|
||||
def delete_post_images(post: Post, db: Session):
|
||||
"""删除文章关联的所有图片(物理删除文件+数据库记录)"""
|
||||
UPLOAD_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "uploads")
|
||||
THUMB_DIR = os.path.join(UPLOAD_DIR, "thumbnails")
|
||||
|
||||
# 收集所有要删除的图片路径
|
||||
image_paths = set()
|
||||
|
||||
# 1. 封面图
|
||||
if post.cover_image:
|
||||
image_paths.add(post.cover_image)
|
||||
|
||||
# 2. 内容中的图片
|
||||
if post.content:
|
||||
paths = re.findall(r'/uploads/[^\s"\')<>]+', post.content)
|
||||
image_paths.update(paths)
|
||||
|
||||
# 删除每张图片
|
||||
for path in image_paths:
|
||||
filename = os.path.basename(path)
|
||||
|
||||
# 查找数据库记录
|
||||
image = db.query(Image).filter(Image.file_path == path).first()
|
||||
if image:
|
||||
# 删除原图文件
|
||||
file_path = os.path.join(UPLOAD_DIR, filename)
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
|
||||
# 删除缩略图文件
|
||||
if image.thumb_path:
|
||||
thumb_filename = os.path.basename(image.thumb_path)
|
||||
thumb_path = os.path.join(THUMB_DIR, thumb_filename)
|
||||
if os.path.exists(thumb_path):
|
||||
os.remove(thumb_path)
|
||||
|
||||
# 删除数据库记录
|
||||
db.delete(image)
|
||||
|
||||
|
||||
@router.delete("/{post_id}")
|
||||
def delete_post(
|
||||
post_id: int,
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""删除文章(同时删除关联的图片)"""
|
||||
post = db.query(Post).filter(Post.id == post_id).first()
|
||||
if not post:
|
||||
raise HTTPException(status_code=404, detail="文章不存在")
|
||||
|
||||
# 先删除关联图片
|
||||
delete_post_images(post, db)
|
||||
|
||||
# 再删除文章
|
||||
db.delete(post)
|
||||
db.commit()
|
||||
return {"message": "文章已删除"}
|
||||
|
||||
|
||||
@router.get("/stats/overview")
|
||||
def get_stats(db: Session = Depends(get_db)):
|
||||
"""获取统计数据"""
|
||||
from sqlalchemy import func
|
||||
|
||||
total_posts = db.query(Post).filter(Post.is_draft == False).count()
|
||||
total_views = db.query(func.sum(Post.view_count)).scalar() or 0
|
||||
|
||||
# 按分类统计
|
||||
category_counts = {}
|
||||
categories = db.query(Category).all()
|
||||
for cat in categories:
|
||||
count = db.query(Post).filter(Post.category_id == cat.id).count()
|
||||
category_counts[cat.name] = count
|
||||
|
||||
# 最近文章
|
||||
recent_posts = db.query(Post).order_by(Post.created_at.desc()).limit(5).all()
|
||||
|
||||
return {
|
||||
"total_posts": total_posts,
|
||||
"total_views": total_views,
|
||||
"category_counts": category_counts,
|
||||
"recent_posts": recent_posts
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
"""
|
||||
博客设置路由
|
||||
"""
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from database import get_db
|
||||
from models import Setting, Page
|
||||
from schemas import SettingUpdate, SettingResponse, PageCreate, PageUpdate, PageResponse
|
||||
from routers.auth import get_current_admin
|
||||
from typing import List
|
||||
|
||||
router = APIRouter(prefix="/api", tags=["设置"])
|
||||
|
||||
|
||||
def get_or_create_settings(db: Session):
|
||||
"""获取或创建设置"""
|
||||
setting = db.query(Setting).first()
|
||||
if not setting:
|
||||
setting = Setting()
|
||||
db.add(setting)
|
||||
db.commit()
|
||||
db.refresh(setting)
|
||||
return setting
|
||||
|
||||
|
||||
@router.get("/settings", response_model=SettingResponse)
|
||||
def get_settings(db: Session = Depends(get_db)):
|
||||
"""获取博客设置"""
|
||||
setting = get_or_create_settings(db)
|
||||
return setting
|
||||
|
||||
|
||||
@router.put("/settings", response_model=SettingResponse)
|
||||
def update_settings(
|
||||
setting_data: SettingUpdate,
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""更新博客设置"""
|
||||
setting = get_or_create_settings(db)
|
||||
|
||||
update_data = setting_data.dict(exclude_unset=True)
|
||||
for field, value in update_data.items():
|
||||
setattr(setting, field, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(setting)
|
||||
return setting
|
||||
|
||||
|
||||
# ==================== 自定义页面管理 ====================
|
||||
|
||||
@router.get("/pages", response_model=List[PageResponse])
|
||||
def get_pages(db: Session = Depends(get_db)):
|
||||
"""获取所有自定义页面"""
|
||||
pages = db.query(Page).order_by(Page.nav_order.asc(), Page.created_at.desc()).all()
|
||||
return pages
|
||||
|
||||
|
||||
@router.get("/pages/{slug}", response_model=PageResponse)
|
||||
def get_page_by_slug(slug: str, db: Session = Depends(get_db)):
|
||||
"""通过slug获取页面"""
|
||||
page = db.query(Page).filter(Page.slug == slug).first()
|
||||
if not page:
|
||||
raise HTTPException(status_code=404, detail="页面不存在")
|
||||
return page
|
||||
|
||||
|
||||
@router.post("/pages", response_model=PageResponse)
|
||||
def create_page(
|
||||
page_data: PageCreate,
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""创建自定义页面"""
|
||||
# 检查数量限制
|
||||
count = db.query(Page).count()
|
||||
if count >= 5:
|
||||
raise HTTPException(status_code=400, detail="自定义页面数量已达上限(5个)")
|
||||
|
||||
# 检查slug重复
|
||||
existing = db.query(Page).filter(Page.slug == page_data.slug).first()
|
||||
if existing:
|
||||
raise HTTPException(status_code=400, detail="页面标识已存在")
|
||||
|
||||
page = Page(**page_data.dict())
|
||||
db.add(page)
|
||||
db.commit()
|
||||
db.refresh(page)
|
||||
return page
|
||||
|
||||
|
||||
@router.put("/pages/{page_id}", response_model=PageResponse)
|
||||
def update_page(
|
||||
page_id: int,
|
||||
page_data: PageUpdate,
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""更新自定义页面"""
|
||||
page = db.query(Page).filter(Page.id == page_id).first()
|
||||
if not page:
|
||||
raise HTTPException(status_code=404, detail="页面不存在")
|
||||
|
||||
update_data = page_data.dict(exclude_unset=True)
|
||||
for field, value in update_data.items():
|
||||
setattr(page, field, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(page)
|
||||
return page
|
||||
|
||||
|
||||
@router.delete("/pages/{page_id}")
|
||||
def delete_page(
|
||||
page_id: int,
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""删除自定义页面"""
|
||||
page = db.query(Page).filter(Page.id == page_id).first()
|
||||
if not page:
|
||||
raise HTTPException(status_code=404, detail="页面不存在")
|
||||
|
||||
db.delete(page)
|
||||
db.commit()
|
||||
return {"message": "页面已删除"}
|
||||
@@ -0,0 +1,64 @@
|
||||
"""
|
||||
标签管理路由
|
||||
"""
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from database import get_db
|
||||
from models import Tag
|
||||
from schemas import TagCreate, TagResponse
|
||||
from routers.auth import get_current_admin
|
||||
|
||||
router = APIRouter(prefix="/api/tags", tags=["标签"])
|
||||
|
||||
|
||||
@router.get("/", response_model=List[TagResponse])
|
||||
def get_tags(db: Session = Depends(get_db)):
|
||||
"""获取所有标签"""
|
||||
tags = db.query(Tag).all()
|
||||
return tags
|
||||
|
||||
|
||||
@router.post("/", response_model=TagResponse)
|
||||
def create_tag(
|
||||
tag_data: TagCreate,
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""创建标签"""
|
||||
# 检查数量限制
|
||||
count = db.query(Tag).count()
|
||||
if count >= 20:
|
||||
raise HTTPException(status_code=400, detail="标签数量已达上限(20个)")
|
||||
|
||||
# 检查名称重复
|
||||
existing = db.query(Tag).filter(Tag.name == tag_data.name).first()
|
||||
if existing:
|
||||
raise HTTPException(status_code=400, detail="标签名称已存在")
|
||||
|
||||
tag = Tag(**tag_data.dict())
|
||||
db.add(tag)
|
||||
db.commit()
|
||||
db.refresh(tag)
|
||||
return tag
|
||||
|
||||
|
||||
@router.delete("/{tag_id}")
|
||||
def delete_tag(
|
||||
tag_id: int,
|
||||
current_admin=Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""删除标签"""
|
||||
tag = db.query(Tag).filter(Tag.id == tag_id).first()
|
||||
if not tag:
|
||||
raise HTTPException(status_code=404, detail="标签不存在")
|
||||
|
||||
db.delete(tag)
|
||||
db.commit()
|
||||
return {"message": "标签已删除"}
|
||||
@@ -0,0 +1,421 @@
|
||||
"""
|
||||
微信公众号文章采集模块
|
||||
专门用于采集微信公众号文章,独立于通用采集模块
|
||||
todo: 后续可扩展批量采集公众号历史文章
|
||||
"""
|
||||
|
||||
import os
|
||||
import re
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from urllib.parse import urlparse, urljoin
|
||||
from typing import List, Optional
|
||||
|
||||
import requests
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from backend.database import get_db
|
||||
from backend.models import Image
|
||||
from backend.routers.auth import get_current_admin
|
||||
|
||||
router = APIRouter(prefix="/wechat-crawl", tags=["wechat-crawl"])
|
||||
|
||||
# ========== Playwright 检测 ==========
|
||||
try:
|
||||
from playwright.async_api import async_playwright
|
||||
PLAYWRIGHT_AVAILABLE = True
|
||||
except ImportError:
|
||||
PLAYWRIGHT_AVAILABLE = False
|
||||
print("警告: Playwright未安装,微信公众号采集功能不可用")
|
||||
|
||||
|
||||
# ========== Pydantic 模型 ==========
|
||||
class WechatCrawlRequest(BaseModel):
|
||||
url: str
|
||||
|
||||
|
||||
class CrawlImageInfo(BaseModel):
|
||||
original_url: str
|
||||
local_path: Optional[str] = None
|
||||
filename: Optional[str] = None
|
||||
success: bool = False
|
||||
id: Optional[int] = None
|
||||
|
||||
|
||||
class WechatCrawlResponse(BaseModel):
|
||||
success: bool
|
||||
title: Optional[str] = None
|
||||
content: Optional[str] = None
|
||||
summary: Optional[str] = None
|
||||
images: List[CrawlImageInfo] = []
|
||||
error: Optional[str] = None
|
||||
|
||||
|
||||
# ========== 辅助函数 ==========
|
||||
|
||||
def get_image_dimensions(filepath: str):
|
||||
"""获取图片尺寸"""
|
||||
try:
|
||||
from PIL import Image as PILImage
|
||||
with PILImage.open(filepath) as img:
|
||||
return img.width, img.height
|
||||
except Exception as e:
|
||||
print(f"获取图片尺寸失败: {e}")
|
||||
return None, None
|
||||
|
||||
|
||||
def generate_thumbnail(source_path: str, thumb_path: str, max_size: tuple = (400, 300)) -> bool:
|
||||
"""生成缩略图"""
|
||||
try:
|
||||
from PIL import Image as PILImage
|
||||
with PILImage.open(source_path) as img:
|
||||
img.thumbnail(max_size)
|
||||
img.save(thumb_path, 'JPEG', quality=85)
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"生成缩略图失败: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def download_image(url: str, temp_dir: str) -> tuple:
|
||||
"""下载图片到临时目录"""
|
||||
try:
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
||||
'Referer': 'https://mp.weixin.qq.com/'
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=headers, timeout=30, stream=True)
|
||||
response.raise_for_status()
|
||||
|
||||
content_type = response.headers.get('content-type', '')
|
||||
ext = '.jpg'
|
||||
if 'png' in content_type:
|
||||
ext = '.png'
|
||||
elif 'gif' in content_type:
|
||||
ext = '.gif'
|
||||
elif 'webp' in content_type:
|
||||
ext = '.webp'
|
||||
else:
|
||||
parsed = urlparse(url)
|
||||
path_ext = os.path.splitext(parsed.path)[1]
|
||||
if path_ext:
|
||||
ext = path_ext
|
||||
|
||||
filename = f"wechat_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{uuid.uuid4().hex[:8]}{ext}"
|
||||
filepath = os.path.join(temp_dir, filename)
|
||||
|
||||
with open(filepath, 'wb') as f:
|
||||
for chunk in response.iter_content(chunk_size=8192):
|
||||
f.write(chunk)
|
||||
|
||||
return filename, filepath, True
|
||||
except Exception as e:
|
||||
print(f"下载图片失败 {url}: {e}")
|
||||
return None, None, False
|
||||
|
||||
|
||||
def convert_wechat_html_to_markdown(html: str, images: List[CrawlImageInfo], base_url: str) -> str:
|
||||
"""将微信文章HTML转为Markdown"""
|
||||
text = re.sub(r'<style[^>]*>.*?</style>', '', html, flags=re.DOTALL | re.IGNORECASE)
|
||||
text = re.sub(r'<script[^>]*>.*?</script>', '', text, flags=re.DOTALL | re.IGNORECASE)
|
||||
text = re.sub(r'\s+style="[^"]*"', '', text, flags=re.IGNORECASE)
|
||||
text = re.sub(r'\s+class="[^"]*"', '', text, flags=re.IGNORECASE)
|
||||
parsed_base = urlparse(base_url)
|
||||
|
||||
# 微信文章特殊处理:图片使用 data-src
|
||||
text = re.sub(
|
||||
r'<img[^>]+data-src=["\']([^"\']+)["\'][^>]*>',
|
||||
lambda m: f'})',
|
||||
text, flags=re.IGNORECASE
|
||||
)
|
||||
|
||||
# 匹配普通 img 标签
|
||||
def img_to_markdown(match):
|
||||
src = match.group(1)
|
||||
alt = match.group(2) if match.lastindex and match.lastindex >= 2 else ""
|
||||
if src.startswith('//'):
|
||||
src = 'https:' + src
|
||||
elif src.startswith('/'):
|
||||
src = f"{parsed_base.scheme}://{parsed_base.netloc}{src}"
|
||||
return f''
|
||||
|
||||
text = re.sub(
|
||||
r'<img[^>]+src=["\']([^"\']+)["\'][^>]*alt=["\']([^"\']*)["\'][^>]*>',
|
||||
img_to_markdown, text, flags=re.IGNORECASE
|
||||
)
|
||||
|
||||
def img_to_markdown_no_alt(match):
|
||||
src = match.group(1)
|
||||
if src.startswith('//'):
|
||||
src = 'https:' + src
|
||||
elif src.startswith('/'):
|
||||
src = f"{parsed_base.scheme}://{parsed_base.netloc}{src}"
|
||||
return f''
|
||||
|
||||
text = re.sub(
|
||||
r'<img[^>]+src=["\']([^"\']+)["\'][^>]*>',
|
||||
img_to_markdown_no_alt,
|
||||
text, flags=re.IGNORECASE
|
||||
)
|
||||
|
||||
# 处理代码块
|
||||
def convert_code_block(match):
|
||||
code_content = match.group(1)
|
||||
lang_match = re.search(r'class=["\'][^"\']*language-([^"\'\s]+)["\']', match.group(0), re.IGNORECASE)
|
||||
lang = lang_match.group(1) if lang_match else ''
|
||||
return f'\n```{lang}\n{code_content}\n```\n'
|
||||
|
||||
text = re.sub(r'<pre[^>]*>\s*<code[^>]*>(.*?)</code>\s*</pre>', convert_code_block,
|
||||
text, flags=re.DOTALL | re.IGNORECASE)
|
||||
text = re.sub(r'<pre[^>]*>(.*?)</pre>', r'\n```\n\1\n```\n', text, flags=re.DOTALL | re.IGNORECASE)
|
||||
text = re.sub(r'<code[^>]*>(.*?)</code>', r'`\1`', text, flags=re.DOTALL | re.IGNORECASE)
|
||||
|
||||
# 转换其他标签
|
||||
text = re.sub(r'<h1[^>]*>(.*?)</h1>', r'\n# \1\n', text, flags=re.DOTALL | re.IGNORECASE)
|
||||
text = re.sub(r'<h2[^>]*>(.*?)</h2>', r'\n## \1\n', text, flags=re.DOTALL | re.IGNORECASE)
|
||||
text = re.sub(r'<h3[^>]*>(.*?)</h3>', r'\n### \1\n', text, flags=re.DOTALL | re.IGNORECASE)
|
||||
text = re.sub(r'<h4[^>]*>(.*?)</h4>', r'\n#### \1\n', text, flags=re.DOTALL | re.IGNORECASE)
|
||||
text = re.sub(r'<p[^>]*>(.*?)</p>', r'\n\1\n', text, flags=re.DOTALL | re.IGNORECASE)
|
||||
text = re.sub(r'<br\s*/?>', '\n', text, flags=re.IGNORECASE)
|
||||
text = re.sub(r'<strong[^>]*>(.*?)</strong>', r'**\1**', text, flags=re.DOTALL | re.IGNORECASE)
|
||||
text = re.sub(r'<b[^>]*>(.*?)</b>', r'**\1**', text, flags=re.DOTALL | re.IGNORECASE)
|
||||
text = re.sub(r'<em[^>]*>(.*?)</em>', r'*\1*', text, flags=re.DOTALL | re.IGNORECASE)
|
||||
text = re.sub(r'<li[^>]*>(.*?)</li>', r'- \1\n', text, flags=re.DOTALL | re.IGNORECASE)
|
||||
text = re.sub(r'<[^>]+>', '', text)
|
||||
|
||||
# 解码HTML实体
|
||||
text = text.replace(' ', ' ').replace('<', '<').replace('>', '>')
|
||||
text = text.replace('&', '&').replace('"', '"')
|
||||
|
||||
# 清理空行
|
||||
lines = [line for line in text.split('\n')]
|
||||
cleaned = []
|
||||
prev_empty = False
|
||||
for line in lines:
|
||||
stripped = line.strip()
|
||||
if stripped == '':
|
||||
if not prev_empty:
|
||||
cleaned.append('')
|
||||
prev_empty = True
|
||||
else:
|
||||
cleaned.append(line)
|
||||
prev_empty = False
|
||||
|
||||
return '\n'.join(cleaned).strip()
|
||||
|
||||
|
||||
async def crawl_wechat_with_playwright(url: str) -> dict:
|
||||
"""使用Playwright采集微信公众号文章"""
|
||||
if not PLAYWRIGHT_AVAILABLE:
|
||||
raise Exception("Playwright未安装,无法采集微信公众号文章")
|
||||
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch(headless=True)
|
||||
page = await browser.new_page()
|
||||
|
||||
# 模拟微信内打开环境
|
||||
await page.set_extra_http_headers({
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; SM-G960U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36 MicroMessenger/8.0.0',
|
||||
'Accept-Language': 'zh-CN,zh;q=0.9',
|
||||
'Referer': 'https://mp.weixin.qq.com/'
|
||||
})
|
||||
|
||||
await page.goto(url, wait_until='domcontentloaded', timeout=30000)
|
||||
await page.wait_for_timeout(5000)
|
||||
|
||||
# 提取标题
|
||||
title = ""
|
||||
try:
|
||||
if await page.locator('#activity_name').count() > 0:
|
||||
title = await page.locator('#activity_name').first.inner_text()
|
||||
title = title.strip()
|
||||
except:
|
||||
pass
|
||||
if not title:
|
||||
title = await page.title()
|
||||
|
||||
# 提取正文
|
||||
content_html = ""
|
||||
try:
|
||||
if await page.locator('#js_content').count() > 0:
|
||||
content_html = await page.locator('#js_content').first.inner_html()
|
||||
except:
|
||||
pass
|
||||
|
||||
# 提取图片
|
||||
images = []
|
||||
try:
|
||||
img_elements = await page.locator('#js_content img').all()
|
||||
for img in img_elements[:10]:
|
||||
try:
|
||||
src = await img.get_attribute('data-src') or await img.get_attribute('src')
|
||||
alt = await img.get_attribute('alt') or ''
|
||||
if src and src.startswith('http'):
|
||||
images.append(CrawlImageInfo(original_url=src))
|
||||
except:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
|
||||
# 尝试提取公众号名称
|
||||
nickname = ""
|
||||
try:
|
||||
if await page.locator('#js_name').count() > 0:
|
||||
nickname = await page.locator('#js_name').first.inner_text()
|
||||
nickname = nickname.strip()
|
||||
except:
|
||||
pass
|
||||
|
||||
await browser.close()
|
||||
|
||||
return {
|
||||
'title': title if title else "未命名文章",
|
||||
'content_html': content_html,
|
||||
'images': images,
|
||||
'nickname': nickname
|
||||
}
|
||||
|
||||
|
||||
# ========== API 端点 ==========
|
||||
|
||||
@router.post("")
|
||||
async def crawl_wechat_article(request: WechatCrawlRequest, db: Session = Depends(get_db), current_admin = Depends(get_current_admin)):
|
||||
"""
|
||||
采集微信公众号文章(专用接口)
|
||||
todo: 后续支持批量采集公众号历史文章
|
||||
"""
|
||||
try:
|
||||
if not request.url.startswith(('http://', 'https://')):
|
||||
raise HTTPException(status_code=400, detail="无效的URL")
|
||||
|
||||
if 'mp.weixin.qq.com' not in request.url:
|
||||
return WechatCrawlResponse(
|
||||
success=False,
|
||||
error="该接口仅支持微信公众号文章(mp.weixin.qq.com)"
|
||||
)
|
||||
|
||||
if not PLAYWRIGHT_AVAILABLE:
|
||||
return WechatCrawlResponse(
|
||||
success=False,
|
||||
error="微信公众号文章需要Playwright才能采集。请联系管理员安装: pip install playwright && playwright install chromium"
|
||||
)
|
||||
|
||||
print(f"[公众号采集] 开始采集: {request.url}")
|
||||
|
||||
# 使用Playwright采集
|
||||
result = await crawl_wechat_with_playwright(request.url)
|
||||
|
||||
title = result['title']
|
||||
images = result['images']
|
||||
content_html = result['content_html']
|
||||
nickname = result.get('nickname', '')
|
||||
|
||||
# 转换为Markdown
|
||||
markdown_content = convert_wechat_html_to_markdown(content_html, images, request.url)
|
||||
|
||||
# 创建临时目录
|
||||
temp_dir = "/tmp/blog_wechat_crawl"
|
||||
os.makedirs(temp_dir, exist_ok=True)
|
||||
|
||||
# uploads 目录配置
|
||||
backend_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
upload_dir = os.path.join(backend_dir, "uploads")
|
||||
thumb_dir = os.path.join(upload_dir, "thumbnails")
|
||||
os.makedirs(upload_dir, exist_ok=True)
|
||||
os.makedirs(thumb_dir, exist_ok=True)
|
||||
|
||||
# 下载图片(最多5张)
|
||||
downloaded_images = []
|
||||
for i, img in enumerate(images[:5]):
|
||||
filename, filepath, success = download_image(img.original_url, temp_dir)
|
||||
if success:
|
||||
try:
|
||||
ext = os.path.splitext(filename)[1].lower()
|
||||
if ext not in ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.svg']:
|
||||
ext = '.jpg'
|
||||
new_filename = f"wechat_{datetime.now().strftime('%Y%m%d')}_{uuid.uuid4().hex[:8]}{ext}"
|
||||
|
||||
new_filepath = os.path.join(upload_dir, new_filename)
|
||||
with open(filepath, 'rb') as src:
|
||||
with open(new_filepath, 'wb') as dst:
|
||||
dst.write(src.read())
|
||||
|
||||
os.remove(filepath)
|
||||
|
||||
thumb_filename = f"thumb_{new_filename}"
|
||||
thumb_filepath = os.path.join(thumb_dir, thumb_filename)
|
||||
thumb_path_db = None
|
||||
if generate_thumbnail(new_filepath, thumb_filepath):
|
||||
thumb_path_db = f"/uploads/thumbnails/{thumb_filename}"
|
||||
|
||||
width, height = get_image_dimensions(new_filepath)
|
||||
file_size = os.path.getsize(new_filepath)
|
||||
|
||||
image_record = Image(
|
||||
filename=new_filename,
|
||||
original_name=filename,
|
||||
file_path=f"/uploads/{new_filename}",
|
||||
thumb_path=thumb_path_db,
|
||||
description=f"公众号采集自 {request.url}" + (f" ({nickname})" if nickname else ""),
|
||||
file_size=file_size,
|
||||
width=width,
|
||||
height=height
|
||||
)
|
||||
db.add(image_record)
|
||||
db.commit()
|
||||
db.refresh(image_record)
|
||||
|
||||
img.local_path = f"/uploads/{new_filename}"
|
||||
img.filename = new_filename
|
||||
img.success = True
|
||||
img.id = image_record.id
|
||||
downloaded_images.append(img)
|
||||
|
||||
if img.original_url in markdown_content:
|
||||
markdown_content = markdown_content.replace(
|
||||
img.original_url,
|
||||
f"/uploads/{new_filename}"
|
||||
)
|
||||
print(f"[公众号采集] 图片替换: {img.original_url[:60]}... -> /uploads/{new_filename}")
|
||||
|
||||
print(f"[公众号采集] 图片已保存: id={image_record.id}, filename={new_filename}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"[公众号采集] 保存图片失败: {e}")
|
||||
img.local_path = filepath
|
||||
img.filename = filename
|
||||
img.success = True
|
||||
downloaded_images.append(img)
|
||||
|
||||
# 生成摘要
|
||||
summary = markdown_content[:200].replace('#', '').replace('*', '').strip()
|
||||
|
||||
# 在标题前添加公众号名称
|
||||
if nickname and nickname not in title:
|
||||
title_prefix = f"【{nickname}】"
|
||||
else:
|
||||
title_prefix = ""
|
||||
|
||||
print(f"[公众号采集] 完成: {title}")
|
||||
|
||||
return WechatCrawlResponse(
|
||||
success=True,
|
||||
title=title_prefix + title,
|
||||
content=markdown_content,
|
||||
summary=summary,
|
||||
images=downloaded_images
|
||||
)
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
import traceback
|
||||
print(f"[公众号采集] 失败: {e}")
|
||||
print(traceback.format_exc())
|
||||
return WechatCrawlResponse(
|
||||
success=False,
|
||||
error=f"公众号采集失败: {str(e)}"
|
||||
)
|
||||
@@ -0,0 +1,198 @@
|
||||
"""
|
||||
Pydantic 数据验证模型
|
||||
"""
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional, List
|
||||
from datetime import datetime
|
||||
|
||||
# ==================== 认证相关 ====================
|
||||
|
||||
class LoginRequest(BaseModel):
|
||||
username: str
|
||||
password: str
|
||||
|
||||
class LoginResponse(BaseModel):
|
||||
access_token: str
|
||||
token_type: str = "bearer"
|
||||
|
||||
class PasswordChange(BaseModel):
|
||||
old_password: str
|
||||
new_password: str = Field(..., min_length=8, max_length=20)
|
||||
|
||||
# ==================== 文章相关 ====================
|
||||
|
||||
class TagBase(BaseModel):
|
||||
name: str = Field(..., max_length=30)
|
||||
|
||||
class TagCreate(TagBase):
|
||||
pass
|
||||
|
||||
class TagResponse(TagBase):
|
||||
id: int
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
class CategoryBase(BaseModel):
|
||||
name: str = Field(..., max_length=50)
|
||||
description: Optional[str] = Field(None, max_length=200)
|
||||
|
||||
class CategoryCreate(CategoryBase):
|
||||
pass
|
||||
|
||||
class CategoryResponse(CategoryBase):
|
||||
id: int
|
||||
created_at: datetime
|
||||
post_count: int = 0
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
class PostBase(BaseModel):
|
||||
title: str = Field(..., max_length=200)
|
||||
slug: Optional[str] = Field(None, max_length=200)
|
||||
content: str
|
||||
summary: Optional[str] = Field(None, max_length=500)
|
||||
cover_image: Optional[str] = None
|
||||
is_published: bool = True
|
||||
is_draft: bool = False
|
||||
category_id: Optional[int] = None
|
||||
tag_ids: List[int] = []
|
||||
|
||||
class PostCreate(PostBase):
|
||||
pass
|
||||
|
||||
class PostUpdate(BaseModel):
|
||||
title: Optional[str] = Field(None, max_length=200)
|
||||
slug: Optional[str] = Field(None, max_length=200)
|
||||
content: Optional[str] = None
|
||||
summary: Optional[str] = Field(None, max_length=500)
|
||||
cover_image: Optional[str] = None
|
||||
is_published: Optional[bool] = None
|
||||
is_draft: Optional[bool] = None
|
||||
category_id: Optional[int] = None
|
||||
tag_ids: Optional[List[int]] = None
|
||||
|
||||
class PostResponse(BaseModel):
|
||||
id: int
|
||||
title: str
|
||||
slug: Optional[str] = None
|
||||
content: str
|
||||
summary: Optional[str]
|
||||
cover_image: Optional[str]
|
||||
is_published: bool
|
||||
is_draft: bool
|
||||
view_count: int
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
category: Optional[CategoryResponse]
|
||||
tags: List[TagResponse]
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
class PostListItem(BaseModel):
|
||||
id: int
|
||||
title: str
|
||||
slug: Optional[str] = None
|
||||
summary: Optional[str]
|
||||
cover_image: Optional[str]
|
||||
is_published: bool
|
||||
view_count: int
|
||||
created_at: datetime
|
||||
category: Optional[CategoryResponse]
|
||||
tags: List[TagResponse]
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
# ==================== 图片相关 ====================
|
||||
|
||||
class ImageResponse(BaseModel):
|
||||
id: int
|
||||
filename: str
|
||||
original_name: str
|
||||
description: Optional[str]
|
||||
file_size: int
|
||||
file_path: str
|
||||
thumb_path: Optional[str] = None
|
||||
width: Optional[int] = None
|
||||
height: Optional[int] = None
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
class ImageListResponse(BaseModel):
|
||||
items: List[ImageResponse]
|
||||
total: int
|
||||
skip: int
|
||||
limit: int
|
||||
|
||||
# ==================== 设置相关 ====================
|
||||
|
||||
class SettingBase(BaseModel):
|
||||
blog_name: str = Field(..., max_length=20)
|
||||
blog_description: Optional[str] = Field(None, max_length=200)
|
||||
welcome_message: Optional[str] = Field(default="欢迎来到我的博客 👋 分享技术、生活与思考", max_length=300)
|
||||
blog_logo: Optional[str] = None
|
||||
banner_image: Optional[str] = None
|
||||
banner_type: str = Field(default="text") # text或carousel
|
||||
banner_images: Optional[str] = Field(default="[]") # JSON数组
|
||||
theme: str = Field(default="neobrutalism")
|
||||
layout: str = Field(default="card")
|
||||
|
||||
class SettingUpdate(BaseModel):
|
||||
blog_name: Optional[str] = Field(None, max_length=20)
|
||||
blog_description: Optional[str] = Field(None, max_length=200)
|
||||
welcome_message: Optional[str] = Field(None, max_length=300)
|
||||
blog_logo: Optional[str] = None
|
||||
banner_image: Optional[str] = None
|
||||
banner_type: Optional[str] = None
|
||||
banner_images: Optional[str] = None
|
||||
theme: Optional[str] = None
|
||||
layout: Optional[str] = None
|
||||
|
||||
class SettingResponse(SettingBase):
|
||||
id: int
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
# ==================== 页面相关 ====================
|
||||
|
||||
class PageBase(BaseModel):
|
||||
title: str = Field(..., max_length=50)
|
||||
slug: str = Field(..., max_length=50)
|
||||
content: str
|
||||
is_nav: bool = True
|
||||
nav_order: int = 0
|
||||
|
||||
class PageCreate(PageBase):
|
||||
pass
|
||||
|
||||
class PageUpdate(BaseModel):
|
||||
title: Optional[str] = Field(None, max_length=50)
|
||||
slug: Optional[str] = Field(None, max_length=50)
|
||||
content: Optional[str] = None
|
||||
is_nav: Optional[bool] = None
|
||||
nav_order: Optional[int] = None
|
||||
|
||||
class PageResponse(PageBase):
|
||||
id: int
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
# ==================== 统计相关 ====================
|
||||
|
||||
class StatsResponse(BaseModel):
|
||||
total_posts: int
|
||||
total_views: int
|
||||
today_views: int
|
||||
category_counts: dict
|
||||
recent_posts: List[PostListItem]
|
||||
|
After Width: | Height: | Size: 63 KiB |
|
After Width: | Height: | Size: 404 KiB |
@@ -0,0 +1,16 @@
|
||||
<svg width="137" height="28" viewBox="0 0 137 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M17.5865 17.3955H17.5902L28.5163 8.77432L25.5528 6.39453L17.5902 12.6808H17.5865L17.5828 12.6845L9.62018 6.40201L6.6604 8.78181L17.5828 17.3992L17.5865 17.3955Z" fill="#1E80FF"/>
|
||||
<path d="M17.5872 6.77268L21.823 3.40505L17.5872 0.00748237L17.5835 0L13.3552 3.39757L17.5835 6.76894L17.5872 6.77268Z" fill="#1E80FF"/>
|
||||
<path d="M17.5865 23.2854L17.5828 23.2891L2.95977 11.7531L0 14.1291L0.284376 14.3574L17.5865 28L28.5238 19.3752L35.1768 14.1254L32.2133 11.7456L17.5865 23.2854Z" fill="#1E80FF"/>
|
||||
<path d="M133.287 18.4172H131.162L129.923 23.0758H126.825V16.7559H135.364V14.7315H126.825V11.1469H133.074V9.12256H118.454V11.1469H124.703V14.7315H116.164V16.7559H124.703V23.0758H121.601L120.363 18.4172H118.237L119.487 23.0758H115.543V25.1001H135.985V23.0758H132.041L133.287 18.4172Z" fill="#323232"/>
|
||||
<path d="M130.522 3.3151L130.2 2.94092H121.321L120.999 3.3151C119.298 5.2467 117.378 6.97337 115.278 8.46009V10.9522C116.206 10.3573 120.183 7.72295 122.327 4.98768H129.235C131.375 7.72295 135.356 10.3573 136.284 10.9522V8.46009C134.169 6.97586 132.235 5.2491 130.522 3.3151Z" fill="#323232"/>
|
||||
<path d="M94.9037 8.53127H96.494V6.50323H94.9037V2.88867H92.9056V6.50323H91.3303V8.53127H92.9094V14.7914L91.3303 15.3377V17.5828L92.9094 17.0365V20.7371C92.8414 22.2391 92.5579 23.7236 92.0674 25.145H94.1629C94.6112 23.7165 94.863 22.2335 94.9112 20.7371V16.3442L96.5053 15.7904V13.5229L94.9112 14.0767L94.9037 8.53127Z" fill="#323232"/>
|
||||
<path d="M99.1875 2.88867H97.6608V20.7446C97.6727 22.2359 97.4852 23.7221 97.1033 25.1637H99.1875C99.5206 23.7145 99.6851 22.2316 99.6776 20.7446V9.77357H112.321V2.88867H99.1875ZM110.308 7.75303H99.6851V4.91671H110.304L110.308 7.75303Z" fill="#323232"/>
|
||||
<path d="M110.305 23.405H107.566V17.6838H110.021H110.702H111.91V11.8166H110.021V15.9363H107.566V11.1431H105.676V15.9363H103.27V11.8166H101.381V17.6838H102.298H103.27H105.676V23.405H102.967V19.173H101.074V25.1524H102.286H102.967H110.305H110.683H112.195V19.173H110.305V23.405Z" fill="#323232"/>
|
||||
<path d="M53.0024 2.91846V4.83801L56.5908 6.11397L53.0024 7.38618V9.30573L59.2887 7.07187L65.5749 9.30573V7.38618L61.9865 6.11397L65.5749 4.83801V2.91846L59.2887 5.15232L53.0024 2.91846Z" fill="#323232"/>
|
||||
<path d="M79.9508 11.697H88.5944V9.47813H79.9508V2.80273H77.5299V9.47813H68.8863V11.697H77.5299V22.9823H67.76V25.2012H89.7207V22.9823H79.9508V11.697Z" fill="#323232"/>
|
||||
<path d="M48.9461 5.39227L52.2913 5.18272V3.24072L43.6813 3.78328V5.72529L47.0265 5.512V8.50545H43.5803V10.4213H47.0265V25.164H48.9461V10.4213H52.3923V8.50545H48.9461V5.39227Z" fill="#323232"/>
|
||||
<path d="M57.6539 9.01025H55.6595L55.1768 10.3648H52.9991V12.2357H54.5145L52.55 17.7662H53.8821V24.1534H55.7007V16.8457H58.6642V25.1787H60.5837V16.8457H63.4612V21.059C63.4534 22.1374 63.181 23.1974 62.6679 24.146H64.7147C65.1423 23.173 65.3627 22.1217 65.362 21.059V15.6932V15.1282H60.5837V13.2572H58.6642V15.1282H55.4836L56.5313 12.2245H65.594V10.3536H57.1749L57.6539 9.01025Z" fill="#323232"/>
|
||||
<path d="M43.562 24.6246H45.4591L46.2786 11.4272H44.3815L43.562 24.6246Z" fill="#323232"/>
|
||||
<path d="M49.7849 11.4272L50.3499 23.2963H52.247L51.682 11.4272H49.7849Z" fill="#323232"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 672 KiB |
|
After Width: | Height: | Size: 9.7 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 142 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 83 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 56 KiB |
@@ -0,0 +1,15 @@
|
||||
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="40" height="40" fill="#E4E6EB" fill-opacity="0.6"/>
|
||||
<mask id="mask0_1389_88363" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="40" height="40">
|
||||
<rect width="40" height="40" fill="#E4E6EB"/>
|
||||
</mask>
|
||||
<g mask="url(#mask0_1389_88363)">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M22.5809 24.2241C24.6029 22.9376 26 20.1863 26 17C26 12.5817 23.3137 9 20 9C16.6863 9 14 12.5817 14 17C14 20.1863 15.3971 22.9376 17.4191 24.2241C16.8885 25.3643 15.969 26.7758 14.5 28C13.565 28.7792 12.5815 29.2183 11.5796 29.6657C9.36694 30.6537 7.06502 31.6816 5 36.5V46H20H35V36.5C32.935 31.6816 30.6331 30.6537 28.4204 29.6657C27.4185 29.2183 26.435 28.7792 25.5 28C24.031 26.7758 23.1115 25.3643 22.5809 24.2241Z" fill="url(#paint0_linear_1389_88363)"/>
|
||||
</g>
|
||||
<defs>
|
||||
<linearGradient id="paint0_linear_1389_88363" x1="20" y1="9" x2="20" y2="46" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#C2C8D1"/>
|
||||
<stop offset="1" stop-color="#C2C8D1" stop-opacity="0"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 84 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 93 KiB |
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 9.5 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
@@ -0,0 +1,3 @@
|
||||
<svg width="36" height="28" viewBox="0 0 36 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M17.5875 6.77268L21.8232 3.40505L17.5875 0.00748237L17.5837 0L13.3555 3.39757L17.5837 6.76894L17.5875 6.77268ZM17.5863 17.3955H17.59L28.5161 8.77432L25.5526 6.39453L17.59 12.6808H17.5863L17.5825 12.6845L9.61993 6.40201L6.66016 8.78181L17.5825 17.3992L17.5863 17.3955ZM17.5828 23.2891L17.5865 23.2854L32.2133 11.7456L35.1768 14.1254L28.5238 19.3752L17.5865 28L0.284376 14.3574L0 14.1291L2.95977 11.7531L17.5828 23.2891Z" fill="#1E80FF"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 589 B |
|
After Width: | Height: | Size: 153 KiB |
|
After Width: | Height: | Size: 9.3 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 98 KiB |
|
After Width: | Height: | Size: 146 KiB |
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 141 KiB |
|
After Width: | Height: | Size: 225 KiB |
|
After Width: | Height: | Size: 9.5 KiB |
|
After Width: | Height: | Size: 106 KiB |
@@ -0,0 +1,3 @@
|
||||
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M8.64746 0.867452C8.87122 0.718082 9.16271 0.717453 9.38672 0.866475L17.0684 5.9778C17.2541 6.10137 17.3662 6.30943 17.3662 6.53249V16.7883C17.3662 17.1565 17.0674 17.4553 16.6992 17.4553H1.36621C0.998021 17.4553 0.699219 17.1565 0.699219 16.7883V6.53249C0.699336 6.31012 0.810315 6.10244 0.995117 5.97878L8.64746 0.867452Z" fill="#8A919F"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 454 B |
|
After Width: | Height: | Size: 217 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 43 KiB |
@@ -0,0 +1,16 @@
|
||||
<svg width="137" height="28" viewBox="0 0 137 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M17.5865 17.3955H17.5902L28.5163 8.77432L25.5528 6.39453L17.5902 12.6808H17.5865L17.5828 12.6845L9.62018 6.40201L6.6604 8.78181L17.5828 17.3992L17.5865 17.3955Z" fill="#1E80FF"/>
|
||||
<path d="M17.5872 6.77268L21.823 3.40505L17.5872 0.00748237L17.5835 0L13.3552 3.39757L17.5835 6.76894L17.5872 6.77268Z" fill="#1E80FF"/>
|
||||
<path d="M17.5865 23.2854L17.5828 23.2891L2.95977 11.7531L0 14.1291L0.284376 14.3574L17.5865 28L28.5238 19.3752L35.1768 14.1254L32.2133 11.7456L17.5865 23.2854Z" fill="#1E80FF"/>
|
||||
<path d="M133.287 18.4172H131.162L129.923 23.0758H126.825V16.7559H135.364V14.7315H126.825V11.1469H133.074V9.12256H118.454V11.1469H124.703V14.7315H116.164V16.7559H124.703V23.0758H121.601L120.363 18.4172H118.237L119.487 23.0758H115.543V25.1001H135.985V23.0758H132.041L133.287 18.4172Z" fill="#323232"/>
|
||||
<path d="M130.522 3.3151L130.2 2.94092H121.321L120.999 3.3151C119.298 5.2467 117.378 6.97337 115.278 8.46009V10.9522C116.206 10.3573 120.183 7.72295 122.327 4.98768H129.235C131.375 7.72295 135.356 10.3573 136.284 10.9522V8.46009C134.169 6.97586 132.235 5.2491 130.522 3.3151Z" fill="#323232"/>
|
||||
<path d="M94.9037 8.53127H96.494V6.50323H94.9037V2.88867H92.9056V6.50323H91.3303V8.53127H92.9094V14.7914L91.3303 15.3377V17.5828L92.9094 17.0365V20.7371C92.8414 22.2391 92.5579 23.7236 92.0674 25.145H94.1629C94.6112 23.7165 94.863 22.2335 94.9112 20.7371V16.3442L96.5053 15.7904V13.5229L94.9112 14.0767L94.9037 8.53127Z" fill="#323232"/>
|
||||
<path d="M99.1875 2.88867H97.6608V20.7446C97.6727 22.2359 97.4852 23.7221 97.1033 25.1637H99.1875C99.5206 23.7145 99.6851 22.2316 99.6776 20.7446V9.77357H112.321V2.88867H99.1875ZM110.308 7.75303H99.6851V4.91671H110.304L110.308 7.75303Z" fill="#323232"/>
|
||||
<path d="M110.305 23.405H107.566V17.6838H110.021H110.702H111.91V11.8166H110.021V15.9363H107.566V11.1431H105.676V15.9363H103.27V11.8166H101.381V17.6838H102.298H103.27H105.676V23.405H102.967V19.173H101.074V25.1524H102.286H102.967H110.305H110.683H112.195V19.173H110.305V23.405Z" fill="#323232"/>
|
||||
<path d="M53.0024 2.91846V4.83801L56.5908 6.11397L53.0024 7.38618V9.30573L59.2887 7.07187L65.5749 9.30573V7.38618L61.9865 6.11397L65.5749 4.83801V2.91846L59.2887 5.15232L53.0024 2.91846Z" fill="#323232"/>
|
||||
<path d="M79.9508 11.697H88.5944V9.47813H79.9508V2.80273H77.5299V9.47813H68.8863V11.697H77.5299V22.9823H67.76V25.2012H89.7207V22.9823H79.9508V11.697Z" fill="#323232"/>
|
||||
<path d="M48.9461 5.39227L52.2913 5.18272V3.24072L43.6813 3.78328V5.72529L47.0265 5.512V8.50545H43.5803V10.4213H47.0265V25.164H48.9461V10.4213H52.3923V8.50545H48.9461V5.39227Z" fill="#323232"/>
|
||||
<path d="M57.6539 9.01025H55.6595L55.1768 10.3648H52.9991V12.2357H54.5145L52.55 17.7662H53.8821V24.1534H55.7007V16.8457H58.6642V25.1787H60.5837V16.8457H63.4612V21.059C63.4534 22.1374 63.181 23.1974 62.6679 24.146H64.7147C65.1423 23.173 65.3627 22.1217 65.362 21.059V15.6932V15.1282H60.5837V13.2572H58.6642V15.1282H55.4836L56.5313 12.2245H65.594V10.3536H57.1749L57.6539 9.01025Z" fill="#323232"/>
|
||||
<path d="M43.562 24.6246H45.4591L46.2786 11.4272H44.3815L43.562 24.6246Z" fill="#323232"/>
|
||||
<path d="M49.7849 11.4272L50.3499 23.2963H52.247L51.682 11.4272H49.7849Z" fill="#323232"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 204 KiB |
|
After Width: | Height: | Size: 111 KiB |
|
After Width: | Height: | Size: 528 KiB |
@@ -0,0 +1,16 @@
|
||||
<svg width="137" height="28" viewBox="0 0 137 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M17.5865 17.3955H17.5902L28.5163 8.77432L25.5528 6.39453L17.5902 12.6808H17.5865L17.5828 12.6845L9.62018 6.40201L6.6604 8.78181L17.5828 17.3992L17.5865 17.3955Z" fill="#1E80FF"/>
|
||||
<path d="M17.5872 6.77268L21.823 3.40505L17.5872 0.00748237L17.5835 0L13.3552 3.39757L17.5835 6.76894L17.5872 6.77268Z" fill="#1E80FF"/>
|
||||
<path d="M17.5865 23.2854L17.5828 23.2891L2.95977 11.7531L0 14.1291L0.284376 14.3574L17.5865 28L28.5238 19.3752L35.1768 14.1254L32.2133 11.7456L17.5865 23.2854Z" fill="#1E80FF"/>
|
||||
<path d="M133.287 18.4172H131.162L129.923 23.0758H126.825V16.7559H135.364V14.7315H126.825V11.1469H133.074V9.12256H118.454V11.1469H124.703V14.7315H116.164V16.7559H124.703V23.0758H121.601L120.363 18.4172H118.237L119.487 23.0758H115.543V25.1001H135.985V23.0758H132.041L133.287 18.4172Z" fill="#323232"/>
|
||||
<path d="M130.522 3.3151L130.2 2.94092H121.321L120.999 3.3151C119.298 5.2467 117.378 6.97337 115.278 8.46009V10.9522C116.206 10.3573 120.183 7.72295 122.327 4.98768H129.235C131.375 7.72295 135.356 10.3573 136.284 10.9522V8.46009C134.169 6.97586 132.235 5.2491 130.522 3.3151Z" fill="#323232"/>
|
||||
<path d="M94.9037 8.53127H96.494V6.50323H94.9037V2.88867H92.9056V6.50323H91.3303V8.53127H92.9094V14.7914L91.3303 15.3377V17.5828L92.9094 17.0365V20.7371C92.8414 22.2391 92.5579 23.7236 92.0674 25.145H94.1629C94.6112 23.7165 94.863 22.2335 94.9112 20.7371V16.3442L96.5053 15.7904V13.5229L94.9112 14.0767L94.9037 8.53127Z" fill="#323232"/>
|
||||
<path d="M99.1875 2.88867H97.6608V20.7446C97.6727 22.2359 97.4852 23.7221 97.1033 25.1637H99.1875C99.5206 23.7145 99.6851 22.2316 99.6776 20.7446V9.77357H112.321V2.88867H99.1875ZM110.308 7.75303H99.6851V4.91671H110.304L110.308 7.75303Z" fill="#323232"/>
|
||||
<path d="M110.305 23.405H107.566V17.6838H110.021H110.702H111.91V11.8166H110.021V15.9363H107.566V11.1431H105.676V15.9363H103.27V11.8166H101.381V17.6838H102.298H103.27H105.676V23.405H102.967V19.173H101.074V25.1524H102.286H102.967H110.305H110.683H112.195V19.173H110.305V23.405Z" fill="#323232"/>
|
||||
<path d="M53.0024 2.91846V4.83801L56.5908 6.11397L53.0024 7.38618V9.30573L59.2887 7.07187L65.5749 9.30573V7.38618L61.9865 6.11397L65.5749 4.83801V2.91846L59.2887 5.15232L53.0024 2.91846Z" fill="#323232"/>
|
||||
<path d="M79.9508 11.697H88.5944V9.47813H79.9508V2.80273H77.5299V9.47813H68.8863V11.697H77.5299V22.9823H67.76V25.2012H89.7207V22.9823H79.9508V11.697Z" fill="#323232"/>
|
||||
<path d="M48.9461 5.39227L52.2913 5.18272V3.24072L43.6813 3.78328V5.72529L47.0265 5.512V8.50545H43.5803V10.4213H47.0265V25.164H48.9461V10.4213H52.3923V8.50545H48.9461V5.39227Z" fill="#323232"/>
|
||||
<path d="M57.6539 9.01025H55.6595L55.1768 10.3648H52.9991V12.2357H54.5145L52.55 17.7662H53.8821V24.1534H55.7007V16.8457H58.6642V25.1787H60.5837V16.8457H63.4612V21.059C63.4534 22.1374 63.181 23.1974 62.6679 24.146H64.7147C65.1423 23.173 65.3627 22.1217 65.362 21.059V15.6932V15.1282H60.5837V13.2572H58.6642V15.1282H55.4836L56.5313 12.2245H65.594V10.3536H57.1749L57.6539 9.01025Z" fill="#323232"/>
|
||||
<path d="M43.562 24.6246H45.4591L46.2786 11.4272H44.3815L43.562 24.6246Z" fill="#323232"/>
|
||||
<path d="M49.7849 11.4272L50.3499 23.2963H52.247L51.682 11.4272H49.7849Z" fill="#323232"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 98 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="19.414" height="19.414" viewBox="0 0 19.414 19.414"><g transform="translate(-330.793 -145.793)" opacity="0.498"><line x2="18" y2="18" transform="translate(331.5 146.5)" fill="none" stroke="#a2aaad" stroke-width="2"/><line x1="18" y2="18" transform="translate(331.5 146.5)" fill="none" stroke="#a2aaad" stroke-width="2"/></g></svg>
|
||||
|
After Width: | Height: | Size: 377 B |
|
After Width: | Height: | Size: 19 KiB |
@@ -0,0 +1,3 @@
|
||||
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M8.64746 0.867452C8.87122 0.718082 9.16271 0.717453 9.38672 0.866475L17.0684 5.9778C17.2541 6.10137 17.3662 6.30943 17.3662 6.53249V16.7883C17.3662 17.1565 17.0674 17.4553 16.6992 17.4553H1.36621C0.998021 17.4553 0.699219 17.1565 0.699219 16.7883V6.53249C0.699336 6.31012 0.810315 6.10244 0.995117 5.97878L8.64746 0.867452Z" fill="#8A919F"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 454 B |
|
After Width: | Height: | Size: 9.5 KiB |
@@ -0,0 +1,3 @@
|
||||
<svg width="36" height="28" viewBox="0 0 36 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M17.5875 6.77268L21.8232 3.40505L17.5875 0.00748237L17.5837 0L13.3555 3.39757L17.5837 6.76894L17.5875 6.77268ZM17.5863 17.3955H17.59L28.5161 8.77432L25.5526 6.39453L17.59 12.6808H17.5863L17.5825 12.6845L9.61993 6.40201L6.66016 8.78181L17.5825 17.3992L17.5863 17.3955ZM17.5828 23.2891L17.5865 23.2854L32.2133 11.7456L35.1768 14.1254L28.5238 19.3752L17.5865 28L0.284376 14.3574L0 14.1291L2.95977 11.7531L17.5828 23.2891Z" fill="#1E80FF"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 589 B |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,16 @@
|
||||
<svg width="137" height="28" viewBox="0 0 137 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M17.5865 17.3955H17.5902L28.5163 8.77432L25.5528 6.39453L17.5902 12.6808H17.5865L17.5828 12.6845L9.62018 6.40201L6.6604 8.78181L17.5828 17.3992L17.5865 17.3955Z" fill="#1E80FF"/>
|
||||
<path d="M17.5872 6.77268L21.823 3.40505L17.5872 0.00748237L17.5835 0L13.3552 3.39757L17.5835 6.76894L17.5872 6.77268Z" fill="#1E80FF"/>
|
||||
<path d="M17.5865 23.2854L17.5828 23.2891L2.95977 11.7531L0 14.1291L0.284376 14.3574L17.5865 28L28.5238 19.3752L35.1768 14.1254L32.2133 11.7456L17.5865 23.2854Z" fill="#1E80FF"/>
|
||||
<path d="M133.287 18.4172H131.162L129.923 23.0758H126.825V16.7559H135.364V14.7315H126.825V11.1469H133.074V9.12256H118.454V11.1469H124.703V14.7315H116.164V16.7559H124.703V23.0758H121.601L120.363 18.4172H118.237L119.487 23.0758H115.543V25.1001H135.985V23.0758H132.041L133.287 18.4172Z" fill="#323232"/>
|
||||
<path d="M130.522 3.3151L130.2 2.94092H121.321L120.999 3.3151C119.298 5.2467 117.378 6.97337 115.278 8.46009V10.9522C116.206 10.3573 120.183 7.72295 122.327 4.98768H129.235C131.375 7.72295 135.356 10.3573 136.284 10.9522V8.46009C134.169 6.97586 132.235 5.2491 130.522 3.3151Z" fill="#323232"/>
|
||||
<path d="M94.9037 8.53127H96.494V6.50323H94.9037V2.88867H92.9056V6.50323H91.3303V8.53127H92.9094V14.7914L91.3303 15.3377V17.5828L92.9094 17.0365V20.7371C92.8414 22.2391 92.5579 23.7236 92.0674 25.145H94.1629C94.6112 23.7165 94.863 22.2335 94.9112 20.7371V16.3442L96.5053 15.7904V13.5229L94.9112 14.0767L94.9037 8.53127Z" fill="#323232"/>
|
||||
<path d="M99.1875 2.88867H97.6608V20.7446C97.6727 22.2359 97.4852 23.7221 97.1033 25.1637H99.1875C99.5206 23.7145 99.6851 22.2316 99.6776 20.7446V9.77357H112.321V2.88867H99.1875ZM110.308 7.75303H99.6851V4.91671H110.304L110.308 7.75303Z" fill="#323232"/>
|
||||
<path d="M110.305 23.405H107.566V17.6838H110.021H110.702H111.91V11.8166H110.021V15.9363H107.566V11.1431H105.676V15.9363H103.27V11.8166H101.381V17.6838H102.298H103.27H105.676V23.405H102.967V19.173H101.074V25.1524H102.286H102.967H110.305H110.683H112.195V19.173H110.305V23.405Z" fill="#323232"/>
|
||||
<path d="M53.0024 2.91846V4.83801L56.5908 6.11397L53.0024 7.38618V9.30573L59.2887 7.07187L65.5749 9.30573V7.38618L61.9865 6.11397L65.5749 4.83801V2.91846L59.2887 5.15232L53.0024 2.91846Z" fill="#323232"/>
|
||||
<path d="M79.9508 11.697H88.5944V9.47813H79.9508V2.80273H77.5299V9.47813H68.8863V11.697H77.5299V22.9823H67.76V25.2012H89.7207V22.9823H79.9508V11.697Z" fill="#323232"/>
|
||||
<path d="M48.9461 5.39227L52.2913 5.18272V3.24072L43.6813 3.78328V5.72529L47.0265 5.512V8.50545H43.5803V10.4213H47.0265V25.164H48.9461V10.4213H52.3923V8.50545H48.9461V5.39227Z" fill="#323232"/>
|
||||
<path d="M57.6539 9.01025H55.6595L55.1768 10.3648H52.9991V12.2357H54.5145L52.55 17.7662H53.8821V24.1534H55.7007V16.8457H58.6642V25.1787H60.5837V16.8457H63.4612V21.059C63.4534 22.1374 63.181 23.1974 62.6679 24.146H64.7147C65.1423 23.173 65.3627 22.1217 65.362 21.059V15.6932V15.1282H60.5837V13.2572H58.6642V15.1282H55.4836L56.5313 12.2245H65.594V10.3536H57.1749L57.6539 9.01025Z" fill="#323232"/>
|
||||
<path d="M43.562 24.6246H45.4591L46.2786 11.4272H44.3815L43.562 24.6246Z" fill="#323232"/>
|
||||
<path d="M49.7849 11.4272L50.3499 23.2963H52.247L51.682 11.4272H49.7849Z" fill="#323232"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 9.5 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 65 KiB |
@@ -0,0 +1,16 @@
|
||||
<svg width="137" height="28" viewBox="0 0 137 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M17.5865 17.3955H17.5902L28.5163 8.77432L25.5528 6.39453L17.5902 12.6808H17.5865L17.5828 12.6845L9.62018 6.40201L6.6604 8.78181L17.5828 17.3992L17.5865 17.3955Z" fill="#1E80FF"/>
|
||||
<path d="M17.5872 6.77268L21.823 3.40505L17.5872 0.00748237L17.5835 0L13.3552 3.39757L17.5835 6.76894L17.5872 6.77268Z" fill="#1E80FF"/>
|
||||
<path d="M17.5865 23.2854L17.5828 23.2891L2.95977 11.7531L0 14.1291L0.284376 14.3574L17.5865 28L28.5238 19.3752L35.1768 14.1254L32.2133 11.7456L17.5865 23.2854Z" fill="#1E80FF"/>
|
||||
<path d="M133.287 18.4172H131.162L129.923 23.0758H126.825V16.7559H135.364V14.7315H126.825V11.1469H133.074V9.12256H118.454V11.1469H124.703V14.7315H116.164V16.7559H124.703V23.0758H121.601L120.363 18.4172H118.237L119.487 23.0758H115.543V25.1001H135.985V23.0758H132.041L133.287 18.4172Z" fill="#323232"/>
|
||||
<path d="M130.522 3.3151L130.2 2.94092H121.321L120.999 3.3151C119.298 5.2467 117.378 6.97337 115.278 8.46009V10.9522C116.206 10.3573 120.183 7.72295 122.327 4.98768H129.235C131.375 7.72295 135.356 10.3573 136.284 10.9522V8.46009C134.169 6.97586 132.235 5.2491 130.522 3.3151Z" fill="#323232"/>
|
||||
<path d="M94.9037 8.53127H96.494V6.50323H94.9037V2.88867H92.9056V6.50323H91.3303V8.53127H92.9094V14.7914L91.3303 15.3377V17.5828L92.9094 17.0365V20.7371C92.8414 22.2391 92.5579 23.7236 92.0674 25.145H94.1629C94.6112 23.7165 94.863 22.2335 94.9112 20.7371V16.3442L96.5053 15.7904V13.5229L94.9112 14.0767L94.9037 8.53127Z" fill="#323232"/>
|
||||
<path d="M99.1875 2.88867H97.6608V20.7446C97.6727 22.2359 97.4852 23.7221 97.1033 25.1637H99.1875C99.5206 23.7145 99.6851 22.2316 99.6776 20.7446V9.77357H112.321V2.88867H99.1875ZM110.308 7.75303H99.6851V4.91671H110.304L110.308 7.75303Z" fill="#323232"/>
|
||||
<path d="M110.305 23.405H107.566V17.6838H110.021H110.702H111.91V11.8166H110.021V15.9363H107.566V11.1431H105.676V15.9363H103.27V11.8166H101.381V17.6838H102.298H103.27H105.676V23.405H102.967V19.173H101.074V25.1524H102.286H102.967H110.305H110.683H112.195V19.173H110.305V23.405Z" fill="#323232"/>
|
||||
<path d="M53.0024 2.91846V4.83801L56.5908 6.11397L53.0024 7.38618V9.30573L59.2887 7.07187L65.5749 9.30573V7.38618L61.9865 6.11397L65.5749 4.83801V2.91846L59.2887 5.15232L53.0024 2.91846Z" fill="#323232"/>
|
||||
<path d="M79.9508 11.697H88.5944V9.47813H79.9508V2.80273H77.5299V9.47813H68.8863V11.697H77.5299V22.9823H67.76V25.2012H89.7207V22.9823H79.9508V11.697Z" fill="#323232"/>
|
||||
<path d="M48.9461 5.39227L52.2913 5.18272V3.24072L43.6813 3.78328V5.72529L47.0265 5.512V8.50545H43.5803V10.4213H47.0265V25.164H48.9461V10.4213H52.3923V8.50545H48.9461V5.39227Z" fill="#323232"/>
|
||||
<path d="M57.6539 9.01025H55.6595L55.1768 10.3648H52.9991V12.2357H54.5145L52.55 17.7662H53.8821V24.1534H55.7007V16.8457H58.6642V25.1787H60.5837V16.8457H63.4612V21.059C63.4534 22.1374 63.181 23.1974 62.6679 24.146H64.7147C65.1423 23.173 65.3627 22.1217 65.362 21.059V15.6932V15.1282H60.5837V13.2572H58.6642V15.1282H55.4836L56.5313 12.2245H65.594V10.3536H57.1749L57.6539 9.01025Z" fill="#323232"/>
|
||||
<path d="M43.562 24.6246H45.4591L46.2786 11.4272H44.3815L43.562 24.6246Z" fill="#323232"/>
|
||||
<path d="M49.7849 11.4272L50.3499 23.2963H52.247L51.682 11.4272H49.7849Z" fill="#323232"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 126 KiB |
@@ -0,0 +1,3 @@
|
||||
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M8.64746 0.867452C8.87122 0.718082 9.16271 0.717453 9.38672 0.866475L17.0684 5.9778C17.2541 6.10137 17.3662 6.30943 17.3662 6.53249V16.7883C17.3662 17.1565 17.0674 17.4553 16.6992 17.4553H1.36621C0.998021 17.4553 0.699219 17.1565 0.699219 16.7883V6.53249C0.699336 6.31012 0.810315 6.10244 0.995117 5.97878L8.64746 0.867452Z" fill="#8A919F"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 454 B |
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 927 B |
|
After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 204 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="19.414" height="19.414" viewBox="0 0 19.414 19.414"><g transform="translate(-330.793 -145.793)" opacity="0.498"><line x2="18" y2="18" transform="translate(331.5 146.5)" fill="none" stroke="#a2aaad" stroke-width="2"/><line x1="18" y2="18" transform="translate(331.5 146.5)" fill="none" stroke="#a2aaad" stroke-width="2"/></g></svg>
|
||||
|
After Width: | Height: | Size: 377 B |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 270 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 45 KiB |