Reupload
This commit is contained in:
1 parent
f0e83d2484
commit
7c2b303b02
10 files changed
+6492
No files matched your search
@@ -0,0 +1,121 @@
|
||||
|
||||
|
||||
# Forumlify Express Edition 🌊
|
||||
|
||||
> 一个简洁、优雅的现代社区系统。5 分钟 Docker 一键部署。
|
||||
|
||||
## ✨ 特性
|
||||
|
||||
- 🎨 精致简约的界面设计,支持亮色/暗色模式
|
||||
- ⚡️ 轻量快速,无需复杂配置
|
||||
- 🔐 自带用户认证(JWT)
|
||||
- 📝 发帖、回复、举报、管理后台
|
||||
- 🐳 Docker 一键部署
|
||||
- 🌓 暗色/亮色模式切换
|
||||
|
||||
## 🚀 快速开始
|
||||
|
||||
### Docker 部署(推荐)
|
||||
|
||||
```
|
||||
git clone https://github.com/furrium/forumlify-express.git
|
||||
cd forumlify-express
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
应用默认运行在 `http://localhost:3000`。
|
||||
|
||||
---
|
||||
|
||||
> 如需部署 Next.js 版本,请前往 [forumlify/tree/next](https://github.com/furrium/forumlify/tree/next)。
|
||||
|
||||
---
|
||||
|
||||
### 从源码构建
|
||||
|
||||
> 适合二次开发、自定义部署或不想用 Docker 的场景。
|
||||
|
||||
#### 环境要求
|
||||
|
||||
- Node.js 18+
|
||||
- PostgreSQL 13+
|
||||
|
||||
#### 步骤
|
||||
|
||||
1. **克隆并安装依赖**
|
||||
|
||||
```bash
|
||||
git clone https://github.com/furrium/forumlify-express.git
|
||||
cd forumlify-express
|
||||
npm install
|
||||
```
|
||||
|
||||
2. **准备数据库**
|
||||
|
||||
```bash
|
||||
psql -U postgres -c "CREATE USER forumlify WITH PASSWORD '123456';"
|
||||
psql -U postgres -c "CREATE DATABASE forumlify OWNER forumlify;"
|
||||
psql -U forumlify -d forumlify -f schema.sql
|
||||
```
|
||||
|
||||
3. **配置环境变量**(可选)
|
||||
|
||||
| 变量 | 默认值 | 说明 |
|
||||
|------|--------|------|
|
||||
| `DATABASE_URL` | `postgresql://forumlify:123456@localhost:5432/forumlify` | PostgreSQL 连接串 |
|
||||
| `PORT` | `3000` | HTTP 监听端口 |
|
||||
| `JWT_SECRET` | `forumlify-secret-key-change-me-in-production` | JWT 签名密钥,**生产环境务必修改** |
|
||||
|
||||
4. **启动**
|
||||
|
||||
```bash
|
||||
npm start
|
||||
```
|
||||
|
||||
应用运行在 `http://localhost:3000`,API 在 `http://localhost:3000/api`。
|
||||
|
||||
#### 前端配置
|
||||
|
||||
前端页面为 `index.html`,相关行为可在 `config.js` 中调整:
|
||||
|
||||
| 配置项 | 默认值 | 说明 |
|
||||
|--------|--------|------|
|
||||
| `FORUM_NAME` | `Forumlify` | 论坛名称(左上角显示) |
|
||||
| `ENABLE_CAPTCHA` | `true` | 发帖/注册的人机验证(10 以内加减法) |
|
||||
| `SERVER_PORT` | `null` | 可选:服务端监听端口。优先级:环境变量 `PORT` > `SERVER_PORT` > 默认 `3000` |
|
||||
|
||||
#### 上传目录
|
||||
|
||||
帖子图片默认保存在 `uploads/` 目录,请确保该目录有写入权限:
|
||||
|
||||
```bash
|
||||
mkdir -p uploads && chmod 755 uploads
|
||||
```
|
||||
|
||||
## 📁 项目结构
|
||||
|
||||
```
|
||||
forumlify-express/
|
||||
├── index.html # 前端页面
|
||||
├── style.css # 全局样式
|
||||
├── Dockerfile # Docker 镜像构建文件
|
||||
├── package-lock.json # 依赖锁定文件
|
||||
├── server.js # 后端服务(Express)
|
||||
├── js/ # 前端 JS 模块
|
||||
│ ├── app.js
|
||||
│ ├── admin.js
|
||||
│ ├── api.js
|
||||
│ ├── auth.js
|
||||
│ ├── feed.js
|
||||
│ ├── post.js
|
||||
│ └── user.js
|
||||
├── schema.sql # 数据库表结构
|
||||
├── config.js # 配置文件
|
||||
└── docker-compose.yml # Docker 编排
|
||||
```
|
||||
|
||||
## 📝 License
|
||||
|
||||
MIT
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// ============================================================
|
||||
// ⚙️ Forumlify 配置文件
|
||||
// 自托管版本 —— 修改下面 API 地址即可
|
||||
// ============================================================
|
||||
|
||||
const CONFIG = {
|
||||
|
||||
API_BASE_URL: '/api',
|
||||
|
||||
// 论坛名称(显示在界面左上角和网站title)
|
||||
FORUM_NAME: 'Forumlify',
|
||||
|
||||
// 是否开启发帖/注册的人机验证(简单的加减法)
|
||||
ENABLE_CAPTCHA: true,
|
||||
|
||||
// 服务端监听端口(仅服务端读取,浏览器端忽略)
|
||||
// 优先级:环境变量 PORT > SERVER_PORT > 默认 3000
|
||||
SERVER_PORT: null,
|
||||
};
|
||||
|
||||
// ===== 不要修改下面 =====
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = CONFIG;
|
||||
@@ -0,0 +1,27 @@
|
||||
version: '3'
|
||||
services:
|
||||
db:
|
||||
image: postgres:15
|
||||
environment:
|
||||
POSTGRES_USER: forumlify
|
||||
POSTGRES_PASSWORD: 123456
|
||||
POSTGRES_DB: forumlify
|
||||
volumes:
|
||||
- ./schema.sql:/docker-entrypoint-initdb.d/schema.sql
|
||||
- db_data:/var/lib/postgresql/data
|
||||
ports:
|
||||
- "5432:5432"
|
||||
|
||||
app:
|
||||
build: .
|
||||
ports:
|
||||
- "3003:3000"
|
||||
depends_on:
|
||||
- db
|
||||
environment:
|
||||
DATABASE_URL: postgresql://forumlify:123456@db:5432/forumlify
|
||||
volumes:
|
||||
- ./uploads:/app/uploads
|
||||
|
||||
volumes:
|
||||
db_data:
|
||||
@@ -0,0 +1,7 @@
|
||||
FROM node:18-alpine
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
COPY . .
|
||||
EXPOSE 3000
|
||||
CMD ["npm", "start"]
|
||||
+444
@@ -0,0 +1,444 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title id="pageTitle">Forumlify</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||
<link rel="stylesheet" href="style.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- ===== 导航栏 ===== -->
|
||||
<nav id="navbar">
|
||||
<div class="nav-left">
|
||||
<span id="forumName" class="forum-name">Forumlify</span>
|
||||
<span id="customNavLinks" style="display:inline-flex;align-items:center;gap:6px;margin-left:16px;"></span>
|
||||
</div>
|
||||
<div class="nav-right">
|
||||
<div id="userMenu">
|
||||
<div id="authButtons">
|
||||
<button id="loginBtn" class="btn-ghost">登录</button>
|
||||
<button id="registerBtn" class="btn-primary">注册</button>
|
||||
</div>
|
||||
<div id="userDropdown" style="display:none">
|
||||
<button id="messageBtn" class="nav-icon-btn" title="私信" style="position:relative;padding:6px 8px;background:none;border:none;cursor:pointer;color:var(--text-secondary);border-radius:4px;display:inline-flex;align-items:center;justify-content:center;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>
|
||||
<span id="messageBadge" style="display:none;position:absolute;top:-2px;right:-2px;background:#ef4444;color:#fff;border-radius:50%;padding:2px 6px;font-size:10px;font-weight:600;min-width:18px;text-align:center;line-height:1.4;"></span>
|
||||
</button>
|
||||
<img id="avatarImg" class="avatar" src="" alt="avatar" />
|
||||
<div class="dropdown-menu" id="dropdownMenu">
|
||||
<a href="#" data-page="messages">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>
|
||||
消息
|
||||
</a>
|
||||
<a href="#" data-page="settings">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></svg>
|
||||
设置
|
||||
</a>
|
||||
<a href="#" data-page="admin" id="adminEntry" style="display:none">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/><path d="M12 8v4"/><path d="M12 16h.01"/></svg>
|
||||
管理后台
|
||||
</a>
|
||||
<hr />
|
||||
<a href="#" id="themeToggle" style="display:flex;align-items:center;gap:8px;">
|
||||
<svg id="themeIcon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
|
||||
</svg>
|
||||
<span id="themeLabel">暗色模式</span>
|
||||
</a>
|
||||
<hr />
|
||||
<a href="#" id="logoutBtn">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>
|
||||
退出
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- ===== 主内容区 ===== -->
|
||||
<div id="app">
|
||||
<aside id="sidebar">
|
||||
<div class="stats-box">
|
||||
<h4>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12V7H5a2 2 0 0 1 0-4h14v4"/><path d="M3 5v14a2 2 0 0 0 2 2h16v-5"/><line x1="18" y1="12" x2="18" y2="12"/></svg>
|
||||
社区统计
|
||||
</h4>
|
||||
<div class="stat-item"><span>主题</span><span id="statTopics">0</span></div>
|
||||
<div class="stat-item"><span>帖子</span><span id="statPosts">0</span></div>
|
||||
<div class="stat-item"><span>用户</span><span id="statUsers">0</span></div>
|
||||
</div>
|
||||
<div class="links-box">
|
||||
<h4>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>
|
||||
友情链接
|
||||
</h4>
|
||||
<ul id="friendlyLinks">
|
||||
<li style="color:#94a3b8;font-size:13px;">暂无链接</li>
|
||||
</ul>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<main id="feed">
|
||||
<div class="feed-header">
|
||||
<div class="feed-header-left">
|
||||
<button class="tab active" data-sort="latest">最新发布</button>
|
||||
<button class="tab" data-sort="hot">最新回复</button>
|
||||
</div>
|
||||
<button id="fab" class="btn-primary fab-btn">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
|
||||
发布新帖
|
||||
</button>
|
||||
</div>
|
||||
<div id="postList">
|
||||
<div style="text-align:center;color:#94a3b8;padding:40px 0;">加载中...</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<!-- ===== 独立页面 ===== -->
|
||||
<!-- 消息页面 -->
|
||||
<div id="pageMessages" class="page-slide">
|
||||
<div class="page-header" style="max-width:700px;margin:0 auto;width:100%;">
|
||||
<h2>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>
|
||||
消息
|
||||
</h2>
|
||||
</div>
|
||||
<div id="messagesContent" style="max-width:700px;margin:0 auto;width:100%;">
|
||||
<div style="text-align:center;color:#94a3b8;padding:40px 0;">加载中...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 设置页面 -->
|
||||
<div id="pageSettings" class="page-slide">
|
||||
<div class="page-header" style="max-width:1200px;margin:0 auto;width:100%;">
|
||||
<button class="back-btn" onclick="switchPage('feed')">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>
|
||||
返回
|
||||
</button>
|
||||
<h2>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></svg>
|
||||
设置
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<!-- 侧边栏布局 -->
|
||||
<div class="settings-layout" style="max-width:1200px;margin:0 auto;width:100%;display:flex;gap:28px;align-items:flex-start;">
|
||||
<!-- 左侧:侧边栏 -->
|
||||
<aside class="settings-sidebar" style="width:200px;flex-shrink:0;background:var(--glass-bg);backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px);border:1px solid var(--glass-border);border-radius:var(--radius);padding:8px 0;box-shadow:var(--glass-shadow);position:sticky;top:84px;">
|
||||
<nav class="settings-nav">
|
||||
<a href="#" class="settings-nav-item active" data-settings-tab="profile">
|
||||
<span class="nav-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
|
||||
</span>
|
||||
个人资料
|
||||
</a>
|
||||
<a href="#" class="settings-nav-item" data-settings-tab="security">
|
||||
<span class="nav-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/><path d="M12 8v4"/><path d="M12 16h.01"/></svg>
|
||||
</span>
|
||||
安全设置
|
||||
</a>
|
||||
<a href="#" class="settings-nav-item" data-settings-tab="recovery">
|
||||
<span class="nav-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>
|
||||
</span>
|
||||
恢复码
|
||||
</a>
|
||||
</nav>
|
||||
</aside>
|
||||
|
||||
<!-- 右侧:内容区 -->
|
||||
<main class="settings-content" style="flex:1;min-width:0;background:var(--glass-bg);backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px);border:1px solid var(--glass-border);border-radius:var(--radius);padding:20px 24px;box-shadow:var(--glass-shadow);">
|
||||
<div id="settingsContent">
|
||||
<div style="text-align:center;color:#94a3b8;padding:40px 0;">加载中...</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 管理后台 -->
|
||||
<div id="pageAdmin" class="page-slide">
|
||||
<div class="page-header" style="max-width:1200px;margin:0 auto;width:100%;">
|
||||
<button class="back-btn" onclick="switchPage('feed')">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>
|
||||
返回
|
||||
</button>
|
||||
<h2>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/><path d="M12 8v4"/><path d="M12 16h.01"/></svg>
|
||||
管理后台
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<!-- 侧边栏布局 -->
|
||||
<div class="admin-layout" style="max-width:1200px;margin:0 auto;width:100%;">
|
||||
<aside class="admin-sidebar">
|
||||
<nav class="admin-nav">
|
||||
<a href="#" class="admin-nav-item active" data-tab="reports">
|
||||
<span class="nav-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/><path d="M12 8v4"/><path d="M12 16h.01"/></svg>
|
||||
</span>
|
||||
举报
|
||||
</a>
|
||||
<a href="#" class="admin-nav-item" data-tab="users">
|
||||
<span class="nav-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
|
||||
</span>
|
||||
用户
|
||||
</a>
|
||||
<a href="#" class="admin-nav-item" data-tab="logs">
|
||||
<span class="nav-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10 9 9 9 8 9"/></svg>
|
||||
</span>
|
||||
日志
|
||||
</a>
|
||||
<a href="#" class="admin-nav-item" data-tab="links">
|
||||
<span class="nav-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>
|
||||
</span>
|
||||
友链
|
||||
</a>
|
||||
<a href="#" class="admin-nav-item" data-tab="custom-css">
|
||||
<span class="nav-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>
|
||||
</span>
|
||||
自定义 CSS
|
||||
</a>
|
||||
<a href="#" class="admin-nav-item" data-tab="settings">
|
||||
<span class="nav-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></svg>
|
||||
</span>
|
||||
论坛设置
|
||||
</a>
|
||||
<a href="#" class="admin-nav-item" data-tab="custom">
|
||||
<span class="nav-icon">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10 9 9 9 8 9"/></svg>
|
||||
</span>
|
||||
自定义页面
|
||||
</a>
|
||||
</nav>
|
||||
</aside>
|
||||
<main class="admin-content" id="adminContent">
|
||||
<div style="text-align:center;color:#94a3b8;padding:40px 0;">加载中...</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 发布新帖 -->
|
||||
<div id="pageNew" class="page-slide">
|
||||
<div class="page-header" style="max-width:600px;margin:0 auto;width:100%;">
|
||||
<h2>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14"/><path d="M5 12h14"/></svg>
|
||||
发布新帖
|
||||
</h2>
|
||||
</div>
|
||||
<div style="max-width:600px;margin:0 auto;width:100%;">
|
||||
<input type="text" id="postTitle" placeholder="标题" style="width:100%;padding:10px 14px;border:1.5px solid #e2e8f0;border-radius:6px;font-size:15px;font-weight:600;margin-bottom:12px;font-family:inherit;" />
|
||||
<textarea id="postContent" rows="6" placeholder="说点什么..." style="width:100%;padding:12px;border:1.5px solid #e2e8f0;border-radius:6px;font-size:15px;font-family:inherit;resize:vertical;"></textarea>
|
||||
<div id="dropZone" style="border:2px dashed var(--border);border-radius:8px;padding:24px;text-align:center;cursor:pointer;transition:all 0.3s;margin:8px 0 12px;background:var(--bg);">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:block;margin:0 auto 8px;color:var(--text-secondary);"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>
|
||||
<p style="color:var(--text-secondary);font-size:14px;margin:0;">
|
||||
<span id="dropZoneText">点击或拖拽上传图片</span>
|
||||
</p>
|
||||
<p style="color:var(--text-light);font-size:12px;margin:4px 0 0;">支持 JPG、PNG、GIF、WebP,单张最大 5MB</p>
|
||||
<input type="file" id="fileInput" accept="image/*" multiple style="display:none;" />
|
||||
</div>
|
||||
<div id="imagePreview" style="display:flex;flex-wrap:wrap;gap:8px;margin:8px 0;"></div>
|
||||
<div class="captcha-row" style="margin:12px 0;">
|
||||
<span id="postCaptchaQuestion">3 + 5 = ?</span>
|
||||
<input type="text" id="postCaptchaInput" placeholder="答案" style="width:80px;padding:8px 12px;border:1px solid #e2e8f0;border-radius:4px;" />
|
||||
</div>
|
||||
<button id="postSubmit" class="btn-primary" style="padding:10px 32px;font-size:15px;">发布帖子</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 帖子详情页 -->
|
||||
<div id="pagePost" class="page-slide">
|
||||
<div class="page-header" style="max-width:1200px;margin:0 auto;width:100%;">
|
||||
<button class="back-btn" onclick="switchPage('feed')">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>
|
||||
返回
|
||||
</button>
|
||||
<h2 id="postDetailTitle">帖子详情</h2>
|
||||
</div>
|
||||
|
||||
<div class="post-detail-layout" style="max-width:1200px;margin:0 auto;width:100%;display:flex;gap:28px;align-items:flex-start;">
|
||||
<aside id="postSidebar" style="width:240px;flex-shrink:0;">
|
||||
<div class="stats-box">
|
||||
<h4>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12V7H5a2 2 0 0 1 0-4h14v4"/><path d="M3 5v14a2 2 0 0 0 2 2h16v-5"/><line x1="18" y1="12" x2="18" y2="12"/></svg>
|
||||
社区统计
|
||||
</h4>
|
||||
<div class="stat-item"><span>主题</span><span id="statTopics2">0</span></div>
|
||||
<div class="stat-item"><span>帖子</span><span id="statPosts2">0</span></div>
|
||||
<div class="stat-item"><span>用户</span><span id="statUsers2">0</span></div>
|
||||
</div>
|
||||
<div class="links-box">
|
||||
<h4>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>
|
||||
友情链接
|
||||
</h4>
|
||||
<ul id="friendlyLinks2">
|
||||
<li style="color:#94a3b8;font-size:13px;">暂无链接</li>
|
||||
</ul>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<main style="flex:1;min-width:0;">
|
||||
<div id="postDetailContent">
|
||||
<div style="text-align:center;color:#94a3b8;padding:40px 0;">加载中...</div>
|
||||
</div>
|
||||
<div id="replyArea" style="margin-top:24px;border-top:1px solid var(--glass-border);padding-top:20px;display:none;">
|
||||
<h3 style="font-size:16px;font-weight:600;margin-bottom:14px;color:var(--glass-text);">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline;vertical-align:middle;"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>
|
||||
发表回复
|
||||
</h3>
|
||||
<textarea id="replyContent" rows="3" placeholder="写下你的回复..." style="width:100%;padding:12px 16px;background:rgba(255,255,255,0.1);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);border:1px solid var(--glass-border);border-radius:var(--radius-sm);font-size:14px;font-family:inherit;resize:vertical;color:var(--glass-text);transition:all var(--transition);"></textarea>
|
||||
<div class="captcha-row" style="margin:10px 0;">
|
||||
<span id="replyCaptchaQuestion">3 + 5 = ?</span>
|
||||
<input type="text" id="replyCaptchaInput" placeholder="答案" style="width:80px;padding:8px 12px;background:rgba(255,255,255,0.12);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);border:1px solid var(--glass-border);border-radius:var(--radius-sm);color:var(--glass-text);" />
|
||||
</div>
|
||||
<button id="replySubmit" class="btn-primary" style="padding:8px 24px;">提交回复</button>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 用户主页 -->
|
||||
<div id="pageUser" class="page-slide">
|
||||
<div class="page-header" style="max-width:700px;margin:0 auto;width:100%;">
|
||||
<button class="back-btn" onclick="switchPage('feed')">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>
|
||||
返回
|
||||
</button>
|
||||
<h2 id="userPageTitle">用户主页</h2>
|
||||
</div>
|
||||
<div id="userProfileContent" style="max-width:700px;margin:0 auto;width:100%;">
|
||||
<div style="text-align:center;color:#94a3b8;padding:40px 0;">加载中...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ===== 模态框 ===== -->
|
||||
<!-- 登录 -->
|
||||
<div id="loginModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<span class="close" data-modal="loginModal">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
||||
</span>
|
||||
<h2 style="margin-bottom:16px;">登录</h2>
|
||||
<input type="email" id="loginEmail" placeholder="邮箱" />
|
||||
<input type="password" id="loginPassword" placeholder="密码" />
|
||||
<div style="text-align:center;margin-top:8px;">
|
||||
<a href="#" id="forgotPasswordLink" style="color:var(--primary);font-size:13px;text-decoration:none;">忘记密码?</a>
|
||||
</div>
|
||||
<button id="loginSubmit" class="btn-primary" style="width:100%;margin-top:8px;">登录</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 注册 -->
|
||||
<div id="registerModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<span class="close" data-modal="registerModal">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
||||
</span>
|
||||
<h2 style="margin-bottom:16px;">注册</h2>
|
||||
<input type="text" id="regUsername" placeholder="用户名" />
|
||||
<input type="email" id="regEmail" placeholder="邮箱" />
|
||||
<input type="password" id="regPassword" placeholder="密码(至少6位)" />
|
||||
<div class="captcha-row">
|
||||
<span id="regCaptchaQuestion">3 + 5 = ?</span>
|
||||
<input type="text" id="regCaptchaInput" placeholder="答案" style="width:80px;" />
|
||||
</div>
|
||||
<button id="registerSubmit" class="btn-primary" style="width:100%;">注册</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 举报 -->
|
||||
<div id="reportModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<span class="close" data-modal="reportModal">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
||||
</span>
|
||||
<h2 style="margin-bottom:16px;">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline;vertical-align:middle;"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/><path d="M12 8v4"/><path d="M12 16h.01"/></svg>
|
||||
举报帖子
|
||||
</h2>
|
||||
<p style="font-size:14px;color:#64748b;margin-bottom:12px;">请选择举报原因:</p>
|
||||
<select id="reportReason" style="width:100%;padding:8px 12px;border:1px solid #e2e8f0;border-radius:4px;margin-bottom:16px;">
|
||||
<option value="spam">垃圾广告</option>
|
||||
<option value="abuse">人身攻击</option>
|
||||
<option value="illegal">违法内容</option>
|
||||
<option value="nsfw">不适当内容</option>
|
||||
<option value="other">其他</option>
|
||||
</select>
|
||||
<button id="reportSubmit" class="btn-primary" style="width:100%;">提交举报</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 忘记密码 -->
|
||||
<div id="forgotPasswordModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<span class="close" data-modal="forgotPasswordModal">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
||||
</span>
|
||||
<h2 style="margin-bottom:16px;">🔑 重置密码</h2>
|
||||
<p style="font-size:14px;color:var(--text-secondary);margin-bottom:16px;">输入你的邮箱和一个未使用的恢复码</p>
|
||||
<input type="email" id="resetEmail" placeholder="邮箱" />
|
||||
<input type="text" id="resetRecoveryCode" placeholder="恢复码(格式:ABCD-1234-EFGH-5678)" style="font-family:monospace;letter-spacing:0.5px;" />
|
||||
<input type="password" id="resetNewPassword" placeholder="新密码(至少6位)" />
|
||||
<button id="resetPasswordSubmit" class="btn-primary" style="width:100%;">重置密码</button>
|
||||
<div id="resetStatus" style="font-size:14px;margin-top:8px;text-align:center;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ===== 私信列表模态框 ===== -->
|
||||
<div id="messageListModal" class="modal">
|
||||
<div class="modal-content" style="max-width:480px;max-height:80vh;padding:0;overflow:hidden;display:flex;flex-direction:column;border-radius:8px;">
|
||||
<div style="display:flex;justify-content:space-between;align-items:center;padding:16px 20px;border-bottom:1px solid var(--border);flex-shrink:0;">
|
||||
<h2 style="font-size:18px;margin:0;">✉️ 私信</h2>
|
||||
<span class="close" data-modal="messageListModal" style="font-size:24px;cursor:pointer;color:var(--text-light);line-height:1;">×</span>
|
||||
</div>
|
||||
<div id="messageListContent" style="flex:1;overflow-y:auto;padding:0;">
|
||||
<div style="text-align:center;color:#94a3b8;padding:40px 0;">加载中...</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ===== 聊天模态框 ===== -->
|
||||
<div id="chatModal" class="modal">
|
||||
<div class="modal-content" style="max-width:480px;max-height:80vh;padding:0;overflow:hidden;display:flex;flex-direction:column;border-radius:8px;">
|
||||
<div style="display:flex;justify-content:space-between;align-items:center;padding:12px 16px;border-bottom:1px solid var(--border);flex-shrink:0;">
|
||||
<div style="display:flex;align-items:center;gap:10px;">
|
||||
<button onclick="closeChat()" style="background:none;border:none;cursor:pointer;color:var(--text-secondary);font-size:18px;">←</button>
|
||||
<span id="chatTitle" style="font-weight:600;font-size:16px;">用户</span>
|
||||
</div>
|
||||
<span class="close" data-modal="chatModal" style="font-size:24px;cursor:pointer;color:var(--text-light);line-height:1;">×</span>
|
||||
</div>
|
||||
<div id="chatMessages" style="flex:1;overflow-y:auto;padding:16px;min-height:300px;max-height:400px;">
|
||||
<div style="text-align:center;color:#94a3b8;padding:40px 0;">加载中...</div>
|
||||
</div>
|
||||
<div style="display:flex;gap:8px;padding:12px 16px;border-top:1px solid var(--border);flex-shrink:0;">
|
||||
<input type="text" id="chatInput" placeholder="输入消息..." style="flex:1;padding:8px 12px;border:1px solid var(--border);border-radius:6px;font-size:14px;background:var(--bg);color:var(--text);outline:none;" />
|
||||
<button onclick="sendMessage()" class="btn-primary" style="padding:8px 16px;">发送</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ========================================================== -->
|
||||
<!-- ⚙️ 引用 JS -->
|
||||
<!-- ========================================================== -->
|
||||
<script src="config.js"></script>
|
||||
<script src="js/api.js"></script>
|
||||
<script src="js/theme.js"></script>
|
||||
<script src="js/captcha.js"></script>
|
||||
<script src="js/auth.js"></script>
|
||||
<script src="js/feed.js"></script>
|
||||
<script src="js/post.js"></script>
|
||||
<script src="js/admin.js"></script>
|
||||
<script src="js/user.js"></script>
|
||||
<script src="js/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+1863
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "forumlify",
|
||||
"version": "1.0.0",
|
||||
"description": "Forumlify - 简洁优雅的现代社区系统",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js",
|
||||
"dev": "node server.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"bcrypt": "^5.1.1",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.2",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"pg": "^8.11.3"
|
||||
}
|
||||
}
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
-- ============================================================
|
||||
-- Forumlify 数据库表结构
|
||||
-- ============================================================
|
||||
|
||||
-- 用户表
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
password_hash VARCHAR(255) NOT NULL,
|
||||
username VARCHAR(20) UNIQUE NOT NULL,
|
||||
avatar_url TEXT,
|
||||
bio TEXT DEFAULT '',
|
||||
role VARCHAR(10) DEFAULT 'user' CHECK (role IN ('user', 'admin')),
|
||||
created_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- 帖子表
|
||||
CREATE TABLE IF NOT EXISTS posts (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
title VARCHAR(200) NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
images TEXT[] DEFAULT '{}',
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- 回复表
|
||||
CREATE TABLE IF NOT EXISTS replies (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
post_id UUID NOT NULL REFERENCES posts(id) ON DELETE CASCADE,
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
content TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- 友情链接表
|
||||
CREATE TABLE IF NOT EXISTS friendly_links (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
title VARCHAR(100) NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
sort_order INT DEFAULT 0
|
||||
);
|
||||
|
||||
-- 举报表
|
||||
CREATE TABLE IF NOT EXISTS reports (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
post_id UUID NOT NULL REFERENCES posts(id) ON DELETE CASCADE,
|
||||
reporter_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
reason VARCHAR(100) NOT NULL,
|
||||
status VARCHAR(20) DEFAULT 'pending' CHECK (status IN ('pending', 'approved', 'rejected')),
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
handled_at TIMESTAMPTZ,
|
||||
handler_id UUID REFERENCES users(id) ON DELETE SET NULL,
|
||||
handler_note TEXT
|
||||
);
|
||||
|
||||
-- 事件日志表
|
||||
CREATE TABLE IF NOT EXISTS event_logs (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id UUID REFERENCES users(id) ON DELETE SET NULL,
|
||||
action VARCHAR(50) NOT NULL,
|
||||
ip VARCHAR(45),
|
||||
created_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- ============================================================
|
||||
-- 论坛设置表
|
||||
-- ============================================================
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
key VARCHAR(50) PRIMARY KEY,
|
||||
value TEXT NOT NULL,
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
INSERT INTO settings (key, value) VALUES ('forum_name', 'Forumlify')
|
||||
ON CONFLICT (key) DO NOTHING;
|
||||
|
||||
-- ============================================================
|
||||
-- 私信系统
|
||||
-- ============================================================
|
||||
|
||||
-- 私信会话表
|
||||
CREATE TABLE IF NOT EXISTS conversations (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user1_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
user2_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
last_message_at TIMESTAMPTZ DEFAULT now(),
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
UNIQUE(user1_id, user2_id)
|
||||
);
|
||||
|
||||
-- 私信消息表
|
||||
CREATE TABLE IF NOT EXISTS messages (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
conversation_id UUID NOT NULL REFERENCES conversations(id) ON DELETE CASCADE,
|
||||
sender_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
content TEXT NOT NULL,
|
||||
is_read BOOLEAN DEFAULT false,
|
||||
created_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_messages_conversation_id ON messages(conversation_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_messages_sender_id ON messages(sender_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_conversations_user1_id ON conversations(user1_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_conversations_user2_id ON conversations(user2_id);
|
||||
|
||||
-- ============================================================
|
||||
-- 自定义页面表
|
||||
-- ============================================================
|
||||
CREATE TABLE IF NOT EXISTS custom_pages (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name VARCHAR(50) NOT NULL UNIQUE,
|
||||
title VARCHAR(100) NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
enabled BOOLEAN DEFAULT true,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_custom_pages_name ON custom_pages(name);
|
||||
|
||||
-- ============================================================
|
||||
-- 通知系统
|
||||
-- ============================================================
|
||||
CREATE TABLE IF NOT EXISTS notifications (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
type VARCHAR(30) NOT NULL,
|
||||
title VARCHAR(100) NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
link TEXT,
|
||||
is_read BOOLEAN DEFAULT false,
|
||||
created_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_notifications_user_id ON notifications(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_notifications_is_read ON notifications(is_read);
|
||||
|
||||
-- ============================================================
|
||||
-- 自动更新 updated_at 的触发器
|
||||
-- ============================================================
|
||||
CREATE OR REPLACE FUNCTION update_updated_at()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = now();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DROP TRIGGER IF EXISTS update_posts_updated_at ON posts;
|
||||
CREATE TRIGGER update_posts_updated_at
|
||||
BEFORE UPDATE ON posts
|
||||
FOR EACH ROW EXECUTE FUNCTION update_updated_at();
|
||||
|
||||
ALTER TABLE posts ADD COLUMN IF NOT EXISTS edited_at TIMESTAMPTZ;
|
||||
|
||||
-- ============================================================
|
||||
-- 恢复码表(密码重置用)
|
||||
-- ============================================================
|
||||
CREATE TABLE IF NOT EXISTS recovery_codes (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
code_hash VARCHAR(255) NOT NULL,
|
||||
is_used BOOLEAN DEFAULT false,
|
||||
created_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_recovery_codes_user_id ON recovery_codes(user_id);
|
||||
|
||||
-- 帖子表添加置顶字段
|
||||
ALTER TABLE posts ADD COLUMN IF NOT EXISTS is_pinned BOOLEAN DEFAULT false;
|
||||
ALTER TABLE posts ADD COLUMN IF NOT EXISTS pinned_at TIMESTAMPTZ;
|
||||
|
||||
-- 创建索引
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_is_pinned ON posts(is_pinned);
|
||||
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS signature TEXT DEFAULT '';
|
||||
|
||||
-- ============================================================
|
||||
-- 论坛默认设置
|
||||
-- ============================================================
|
||||
INSERT INTO settings (key, value) VALUES ('forum_name', 'Forumlify')
|
||||
ON CONFLICT (key) DO NOTHING;
|
||||
Reference in new issue
Block a user