# mobile-document-editor **Repository Path**: rxbook/mobile-document-editor ## Basic Information - **Project Name**: mobile-document-editor - **Description**: 手机端文档编辑器(图床上传+文档编辑) - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-10-29 - **Last Updated**: 2026-10-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Mobile Document Editor 手机端的**图床上传 + 纯文本文档编辑器**。部署在个人服务器上,通过手机浏览器即可完成:相册图片一键上传到 Git 图床并生成可访问链接,以及服务器上纯文本文档的在线阅读、编辑与插图。 无需安装 App,一个 Go 二进制 + 内嵌前端页面,开箱即用。 --- ## 功能特性 ### 图床上传 - 手机相册直接选图(支持一次多选),**原图上传,不压缩、不做任何处理**。 - 自动按「年/月」归档,文件名精确到秒 + 毫秒,例如: `2026/10/image-20261028-161835-964.png` - 自动完成图床仓库的 `git add / commit / push`。 - 上传后展示两种可粘贴格式,一键复制: - 纯链接:`https://raw.giteeusercontent.com///raw/main/2026/10/image-...png` - Markdown:`![image-...png](https://...)` ### 文档编辑 - 输入服务器上的文档绝对路径,校验存在性与格式后打开。 - 仅支持纯文本格式:`md / txt / html / css / js / json / go / py / xml / yaml` 等,不支持 `docx / xlsx / pptx / pdf` 等二进制格式。 - 「编辑 / 预览」双模式,Markdown 实时渲染。 - 编辑中可直接上传图片,链接自动插入到光标位置(类似 Typora)。 - 工具栏:插图、加粗、斜体、标题、列表、引用、行内代码、链接。 - 路径白名单保护,只能读写配置允许的根目录,防止越权。 ### 安全 - 对外访问必须设置口令,登录后下发令牌,所有写接口均需令牌。 - 文档路径白名单 + 软链解析,防止路径穿越与任意文件读写。 - 推荐以 `127.0.0.1` 监听 + Nginx 反向代理对外暴露。 --- ## 在线访问 部署完成后,通过浏览器访问: ``` http://<服务器IP>/editor/ ``` 输入配置的口令即可使用。 --- ## 快速开始 ### 1. 编译 ```bash cd mobile-document-editor export PATH=$PATH:/usr/local/go/bin go build -o mobile-document-editor . ``` ### 2. 配置 首次运行会在可执行文件同级生成 `data/config.json`,按需修改: ```json { "imageBoxRepo": "/root/code/rx/my-image-box", "imageBoxBranch": "main", "imageBoxRemote": "origin", "rawBaseUrl": "https://raw.giteeusercontent.com/your-name/my-image-box/raw/main", "docRoots": ["/root/code"], "maxImageSizeMb": 20, "listenAddr": "127.0.0.1:8780", "port": 8780, "password": "请修改为你的口令" } ``` > 配置项与启动校验详见 [docs/DESIGN.md](docs/DESIGN.md)。 > **注意**:以上均为示例,请替换为你自己的信息——`rawBaseUrl` 中的 `your-name`(代码托管平台用户名)、`password`(访问口令);文档中出现的 `192.0.2.10` 是 RFC 5737 规定的文档示例 IP,请替换为你的服务器地址。 ### 3. 运行 ```bash # 前台运行(测试) ./mobile-document-editor # 或使用 systemd(推荐,开机自启) systemctl enable --now mobile-document-editor ``` ### 4. 配置 Nginx 反向代理 ```nginx location /editor/ { proxy_pass http://127.0.0.1:8780/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; client_max_body_size 25m; } ``` 完整部署步骤见 [docs/DEPLOY.md](docs/DEPLOY.md)。 --- ## 目录结构 ``` mobile-document-editor/ ├── main.go # 入口、路由、启动校验 ├── config.go # 配置结构、默认值、加载与校验 ├── auth.go # 登录/登出、令牌、认证中间件 ├── git.go # Git 命令封装 ├── image.go # 图床上传逻辑 ├── document.go # 文档读写与路径安全 ├── web/ │ ├── index.html # 单页前端 │ └── assets/ # 内嵌的 Vue / Bootstrap / marked ├── docs/ │ ├── DESIGN.md # 架构与详细设计 │ └── DEPLOY.md # 部署与运维文档 └── data/ # 运行时(配置、日志,不入库) ``` --- ## 服务管理 ```bash systemctl status mobile-document-editor # 查看状态 systemctl restart mobile-document-editor # 重启(改配置后执行) systemctl stop mobile-document-editor # 停止 journalctl -u mobile-document-editor -f # 实时日志 ``` --- ## 文档索引 - [docs/DESIGN.md](docs/DESIGN.md):架构设计、功能细节、API 清单、安全设计。 - [docs/DEPLOY.md](docs/DEPLOY.md):编译、systemd、Nginx、验证与运维。