Files
InfoGenie/README.md
2026-03-28 20:59:52 +08:00

249 lines
10 KiB
Markdown
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# InfoGenie 万象口袋
> 跨平台多功能聚合 Web 应用资讯榜单、工具箱、小游戏、AI 工具等。
## 项目概述
InfoGenie 采用**前后端分离**架构:
- **前端**React 18CRA+ React Router + Styled ComponentsPWA核心导航在 SPA 内,大量能力以 `public/` 下**静态 HTML** 嵌入(`FullscreenEmbed`)。
- **后端****Go + Gin + GORM + MySQL**提供健康检查、AI 代理等 REST 接口;用户登录与资料以**萌芽账户统一认证中心Sprout Gate**为准,详见仓库根目录 `SPROUT_GATE_API_DOCS.md`
- **个人中心**:仅**只读展示**认证中心同步的资料与统计;**每日签到、改资料、领萌芽币**请在认证中心完成,本站不提供签到按钮。
### 部署环境(示例)
| 环境 | 地址 |
|------|------|
| 前端 | https://infogenie.shumengya.top |
| 后端 API | https://infogenie.api.shumengya.top |
| 认证中心 | 见前端 `REACT_APP_AUTH_URL` 配置 |
---
## 技术架构
### 前端
| 技术 | 用途 |
|------|------|
| React 18、React Router 6 | UI 与路由 |
| Styled Components | 组件样式 |
| Axios | 请求封装(业务 API + 认证中心 API |
| react-hot-toast | 提示 |
| Service Worker | PWA 离线缓存 |
### 后端(`InfoGenie-go-backend/`
| 技术 | 用途 |
|------|------|
| Go、Gin | HTTP 服务 |
| GORM | MySQL ORM |
| JWT与 Sprout Gate 颁发令牌配合) | 鉴权相关逻辑以实际代码为准 |
| godotenv | 环境变量 |
### 数据库
- **MySQL**:业务数据(如 AI 使用记录等),具体表结构见 Go 迁移/模型。
### 架构特点
- **混合前端**:列表页在 React`Api60sPage``ToolboxPage`),详情以 iframe 全屏嵌入静态页,统一走 `FullscreenEmbed`
- **60s API 静态页**`public/60sapi/**.html`;路由 **`/60sapi/:itemId`**`Api60sItemPage`)通过 `Api60sConfig.js`**`API_ITEM_STATIC_HTML`** 映射到对应 HTML。内嵌时加载 **`public/60sapi/ig-embed.js`**,在 iframe 内隐藏静态页自带顶栏,避免与外层重复。
- **模块化**:前端 `components/``pages/``config/`;后端 `internal/handler``internal/service` 等分层。
---
## 功能模块(摘要)
- **60s API**:周期资讯、热门榜单、实用功能、娱乐消遣等;配置见 `infogenie-frontend/src/config/Api60sConfig.js`
- **工具箱**`public/toolbox/` 下分 **`图片处理` / `实用工具` / `网页小玩具` / `学习工具`** 四类,入口 `ToolboxPage`(分类标签 + 卡片),点击嵌入;配置项 `offlineOk` 为真的工具在卡片上标 **「可离线」**PWA 缓存后页面可本地加载,调用外网 API 或网络流仍要联网)。**`个人主页模板` 目录仅作临时资源,不参与工具箱配置与展示**,上线前可整体从 `public/` 剔除以减小体积。
- **AI 应用**:入口 `AiModelPage`,静态页在 `public/aimodelapp/`;提示词集中在 **`public/aimodelapp/shared/ai-prompts.js`**,统一请求 **`/api/aimodelapp/chat`**。上游 **API Base / Key / 默认模型** 可由管理员在 `/admin` 写入 MySQL 表 **`site_ai_runtime`**`GET/PUT /api/admin/site/ai-runtime`),优先于 `ai_config.json`
- **休闲游戏**`public/smallgame/`
- **AI 工具**`public/aimodelapp/` 等,消耗萌芽币策略以后端与认证中心对接为准。
- **管理入口**:连续点击 Header **Logo 5 次** 输入管理员令牌进入 `/admin`(详见前端实现)。
- **60s 功能展示开关**:条目定义仍在前端 `Api60sConfig.js`**是否展示**由后端 MySQL 表 `site_60s_disabled` 控制。公开接口 `GET /api/site/60s-disabled` 返回 `{ "disabled": ["itemId", ...] }`;管理保存 `PUT /api/admin/site/60s-disabled`(请求头 `X-Site-Admin-Token`)需与后端环境变量 **`INFOGENIE_SITE_ADMIN_TOKEN`** 一致(开发环境可与管理员口令相同,见 `InfoGenie-go-backend/.env.development`)。
- **60s 上游节点**:由表 **`site_60s_upstream`**`source_id`: `self` | `official`)决定;`GET /api/site/60s-source` 供前端静默拉取(**不在** `/60sapi` 列表页展示域名);管理员 `PUT /api/admin/site/60s-source`。静态页用 `sixty-runtime.js` + URL 参数 `sixty_base`,由 `Api60sItemPage` 注入 iframe。
---
## 项目结构(当前)
```
InfoGenie/
├── InfoGenie-go-backend/ # Go + Gin 后端
│ ├── cmd/server/ # 入口 main
│ ├── internal/ # handler / service / model / router 等
│ └── go.mod
├── infogenie-frontend/
│ ├── public/
│ │ ├── 60sapi/ # 60s 类静态页 + ig-embed.js
│ │ ├── toolbox/
│ │ ├── smallgame/
│ │ ├── aimodelapp/
│ │ ├── index.html # 入口与 PWA 启动屏
│ │ └── manifest.json
│ ├── scripts/
│ │ └── inject-ig-embed.js # 批量为 60s 静态页注入 ig-embed可选
│ ├── src/
│ │ ├── App.js # 路由
│ │ ├── components/ # Header、FullscreenEmbed、…
│ │ ├── pages/ # 含 Api60sPage、Api60sItemPage、UserProfilePage、AdminPage…
│ │ ├── contexts/UserContext.js
│ │ ├── config/ # env.js、Api60sConfig.js、StaticPageConfig.js
│ │ └── utils/api.js
│ └── package.json
├── SPROUT_GATE_API_DOCS.md # 萌芽统一认证接入说明(若在本仓库)
└── README.md # 本文件
```
---
## API 端点Go 后端,常见前缀 `/api`
具体以 `InfoGenie-go-backend/internal/router` 为准,常见包括:
| 方法 | 路径 | 说明 |
|------|------|------|
| GET | `/` | 服务信息 |
| GET | `/api/health` | 健康检查 |
| GET | `/api/auth/check` 等 | 与历史兼容的鉴权检查(若仍保留) |
| POST | `/api/aimodelapp/*` | 各类 AI 能力代理 |
| GET | `/api/aimodelapp/coins` | 与 AI 消耗相关的查询 |
用户资料、签到等以 **认证中心 OpenAPI** 为准(前端通过 `REACT_APP_AUTH_API_URL` 访问)。
---
## 快速开始
### 环境要求
- **Go** 1.21+(以后端 `go.mod` 为准)
- **Node.js** 16+、npm
- **MySQL**(开发/测试库连接串见后端 `.env` 或文档)
### 后端
```bash
cd InfoGenie-go-backend
# 配置 .env 中数据库、密钥、认证中心等
go run ./cmd/server
# 默认示例端口见 main 或配置,常见为 :5002
```
### 后端 Docker 部署(可选)
`InfoGenie-go-backend/` 目录:
1. 准备 **`.env.production`**(数据库、邮件、`INFOGENIE_SITE_ADMIN_TOKEN` 等),**不要**将其提交到仓库;镜像内不包含该文件。
2. 构建并启动(**宿主机端口 `12364` → 容器内 `5002`**,容器名 **`infogenie-backend-go`**
```bash
docker compose up -d --build
```
3. 健康检查:`http://<服务器IP>:12364/api/health`(或经反向代理后的域名)。
4. 前端 `REACT_APP_API_URL` 应指向对外的 API 地址(例如经 Nginx 反代到 `127.0.0.1:12364` 的 `https://infogenie.api.shumengya.top`)。
详见该目录下 `Dockerfile`、`docker-compose.yml`。
### 前端
```bash
cd infogenie-frontend
npm install
npm start
# http://localhost:3000
```
生产构建:
```bash
npm run build
```
### 前端环境变量(示例)
| 变量 | 说明 |
|------|------|
| `REACT_APP_API_URL` | 万象口袋 Go 后端根地址 |
| `REACT_APP_AUTH_URL` | 认证中心前端地址 |
| `REACT_APP_AUTH_API_URL` | 认证中心 API 根地址 |
以上变量在 **构建时** 写入前端包Create React App。修改后需重新执行 `npm run build`。
---
## 生产部署(前端)
1. **安装与构建**(在 `infogenie-frontend/` 目录)
```bash
npm ci
npm run build
```
产物为 `build/`:静态资源 + 单页 `index.html`。
2. **构建前设置环境变量**(按线上域名填写,勿提交含密钥的 `.env` 到仓库):
- Linux/macOS`REACT_APP_API_URL=https://你的后端域名 npm run build`
- 或复制 `infogenie-frontend/.env.production.example` 为 `.env.production` 后执行 `npm run build`。
3. **Web 服务器**
- 将 `build/` 内全部文件部署到站点根目录(或子路径;若子路径需设置 CRA 的 `homepage` 并确认 `PUBLIC_URL`)。
- **必须配置 SPA 回退**:所有未命中静态文件的路径应返回 `index.html`,否则刷新 `/toolbox`、`/60sapi/xxx` 等会 404。
- **Nginx 示例**(站点根部署):
```nginx
server {
listen 443 ssl;
server_name infogenie.example.com;
root /var/www/infogenie/build;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ {
expires 7d;
add_header Cache-Control "public, immutable";
}
}
```
4. **HTTPS**
- 全站建议 HTTPSOAuth 回调域名须与认证中心登记一致。
5. **PWA**
- 生产环境会注册 Service Worker见 `src/index.js`)。更新前端后用户可能需刷新或等待 SW 更新;大版本升级可 bump `public/manifest.json` 的 `version` / `name` 便于识别。
6. **后端**
- 单独部署 `InfoGenie-go-backend`(示例:`https://infogenie.api.shumengya.top`),与前端站点(示例:`https://infogenie.shumengya.top`)分域时,前端构建需设置 `REACT_APP_API_URL` 为后端根地址。
- **CORS**:后端中间件 `internal/middleware/cors.go` 为**宽松策略**(放行任意 Origin 并回显),便于跨域;若需收紧可改为白名单。
---
## 前端路由
| 路径 | 说明 |
|------|------|
| `/` | 首页 |
| `/login` | 跳转统一登录 |
| `/auth/callback` | OAuth 回调 |
| `/60sapi` | 60s API 分类列表 |
| `/60sapi/:itemId` | 嵌入对应静态 HTML |
| `/toolbox` | 工具箱列表 |
| `/smallgame` | 小游戏 |
| `/aimodel` | AI 应用 |
| `/profile` | 个人中心(只读) |
| `/admin` | 管理员后台(令牌) |
| `*` | 未匹配 → 首页 |
---
## 联系方式与许可
- **演示**https://infogenie.shumengya.top
- **ICP**蜀ICP备2025151694号以实际页脚为准
- **许可证**Apache License 2.0 — 见 [LICENSE](LICENSE)
---
<div align="center"><strong>万象口袋</strong> · 多功能聚合应用</div>