# filebox **Repository Path**: aax/filebox ## Basic Information - **Project Name**: filebox - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-09-12 - **Last Updated**: 2026-09-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # FileBox · 个人文件快传站 一个只给自己用的文件中转站:手机 ↔ 电脑互传、拖拽上传、识别码登录、自动生成二维码和直链、过期自动清理。 Node.js + Express,只有一个进程,几十秒就能跑起来。 ## 功能 - 🔐 **识别码登录**,会话最长 30 天,连续输错 5 次锁 30 秒 - 📤 **拖拽 / 点击 / Ctrl+V 粘贴**上传,多文件 + 实时进度条 - 📝 **文本快传**:粘贴一段文字即存成 txt,另一端一键查看复制 - 📱 **手机电脑都好用**:响应式布局,深色/浅色主题,每个文件可生成二维码扫码下载 - 🔗 **复制直链**,支持 `?t=令牌` 给 curl / wget / 微信内打开(浏览器下载走 Cookie) - ⏱ **断点续传下载**(HTTP Range),大文件下载中断可续 - 🧹 **自动清理**:默认 7 天前文件自动删除,也可手动清理 / 清空 - 🗂 搜索、按时间/大小/名称排序、多选删除、批量复制链接、重命名接口 - 目录穿越与非法文件名已过滤 ## 快速开始 ```bash # 1. 安装依赖(国内服务器建议先切镜像源) npm config set registry https://registry.npmmirror.com npm install # 2. 启动 node server.js ``` 启动后会打印: ``` FileBox 已启动 本机访问: http://localhost:3000 局域网访问: http://192.168.1.23:3000 (手机连同一 WiFi 可直接打开) 登录识别码: file2026 ``` > 手机传文件最简单的方式:手机和电脑连同一个 WiFi,用手机浏览器打开「局域网访问」地址, > 或者点右上角 🔗 扫二维码。 ## 配置(环境变量,都可不设) | 变量 | 默认值 | 说明 | |---|---|---| | `PORT` | `3000` | 监听端口 | | `PASSCODE` | `file2026` | **登录识别码,务必改掉** | | `DATA_DIR` | `./data` | 存储目录(识别码/令牌也在里面) | | `RETENTION_DAYS` | `7` | 自动清理天数,`0` 表示永不清理 | | `MAX_UPLOAD_MB` | `10240` | 单文件大小上限(MB) | | `SESSION_DAYS` | `30` | 勾选「记住」时的登录有效期 | | `PUBLIC_URL` | 自动 | 反向代理后的外网地址,如 `https://box.example.com`,影响生成的二维码和链接 | 示例: ```bash PORT=8080 PASSCODE=My$ecret99 RETENTION_DAYS=3 node server.js ``` 首次启动会在 `data/` 下生成三个隐藏文件:`.secret`(会话密钥)、`.passcode`(识别码)、`.accesstoken`(直链令牌),权限 600。 ## 部署到服务器 ### 方式零:一键脚本(已有 Nginx + 其它网站的服务器,最省事) 脚本会:拉代码 → 装依赖 → PM2 起服务(默认 3001 端口,**不动你现有的 3000 和其它站点**)→ 生成独立 Nginx 配置 → 校验并 reload。 ```bash curl -O https://gitee.com/aax/filebox/raw/master/deploy.sh chmod +x deploy.sh # 复用现有证书(证书需覆盖你的域名) sudo ./deploy.sh --domain box.xmin.site # 或者让脚本自动申请 Let's Encrypt 证书(域名需已解析到本机) sudo ./deploy.sh --domain box.xmin.site --ssl-mode certbot --email you@example.com ``` 常用参数: | 参数 | 默认 | 说明 | |---|---|---| | `--domain` | `box.xmin.site` | 访问域名 | | `--port` | `3001` | 本机监听端口,被占用会直接报错 | | `--dir` | `/opt/filebox` | 安装目录 | | `--passcode` | 随机 6 位数字 | 登录识别码,留空则自动生成并保存 | | `--retention` | `7` | 过期自动清理天数 | | `--max-upload` | `10240` | 单文件上限(MB) | | `--ssl-mode` | `reuse` | `reuse` 复用证书 / `certbot` 自动申请 / `selfsign` 自签 | | `--ssl-cert` `--ssl-key` | xmin.site 现有证书路径 | 指定其它证书 | 脚本幂等,**再次执行即更新代码并重启**。生成的 Nginx 配置含 `client_max_body_size 0`、`proxy_request_buffering off`、`proxy_buffering off`,大文件上传下载和断点续传都已处理。 ### 方式一:PM2(推荐) ```bash npm i -g pm2 PORT=8080 PASSCODE=你的识别码 pm2 start server.js --name filebox pm2 save && pm2 startup # 开机自启 pm2 logs filebox ``` ### 方式二:systemd ```ini # /etc/systemd/system/filebox.service [Unit] Description=FileBox After=network.target [Service] Type=simple WorkingDirectory=/opt/filebox Environment=PORT=8080 Environment=PASSCODE=你的识别码 Environment=RETENTION_DAYS=7 ExecStart=/usr/bin/node server.js Restart=always [Install] WantedBy=multi-user.target ``` ```bash systemctl daemon-reload && systemctl enable --now filebox ``` ### 方式三:Docker ```bash docker build -t filebox . docker run -d --name filebox \ -p 8080:3000 \ -e PASSCODE=你的识别码 \ -v /opt/filebox-data:/app/data \ --restart unless-stopped filebox ``` ### Nginx 反向代理(上 HTTPS + 大文件) ```nginx server { listen 443 ssl; server_name box.example.com; ssl_certificate /etc/letsencrypt/live/box.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/box.example.com/privkey.pem; client_max_body_size 0; # 不限制上传体积 proxy_read_timeout 3600s; proxy_send_timeout 3600s; proxy_buffering off; # 大文件不要缓冲 location / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $remote_addr; proxy_request_buffering off; } } ``` 同时设置 `PUBLIC_URL=https://box.example.com`,二维码和复制的链接才会是外网地址。 > 注意:HTTP(非 HTTPS)下 `navigator.clipboard` 在部分浏览器不可用,代码已带 `execCommand` 兜底; > 但建议还是套个 HTTPS(上面 Nginx + Let's Encrypt 即可)。 ## 接口一览 | 方法 | 路径 | 说明 | |---|---|---| | POST | `/api/login` | 传入 `{passcode, remember}` 登录 | | GET | `/api/state` | 文件列表 + 容量 + 令牌 | | POST | `/api/upload` | `multipart/form-data`,字段名 `files`,可多文件 | | POST | `/api/text` | `{content, name}` 保存文本 | | GET | `/api/text/:name` | 读取文本内容(<2MB) | | POST | `/api/delete` | `{names: [...]}` 批量删除 | | POST | `/api/rename` | `{name, newName}` | | POST | `/api/cleanup` | 清理过期文件 | | POST | `/api/clear` | 清空全部 | | GET | `/api/qr?u=` | 返回二维码 SVG | | GET | `/d/:name` | 下载(attachment) | | GET | `/v/:name` | 预览(inline,图片/视频/PDF) | 未登录时下载可用 `?t=<直链令牌>`,例如: ```bash curl -o file.zip "https://box.example.com/d/file.zip?t=你的令牌" ``` ## 常见问题 - **忘记识别码**:看 `data/.passcode`,或删掉该文件后重启(会回到默认 `file2026`)。 - **想换识别码**:`echo -n "新识别码" > data/.passcode` 后重启。 - **重置直链令牌**:`rm data/.accesstoken` 后重启,会自动生成新的。 - **上传中途失败**:会残留不完整文件,手动在页面删除即可。 - **磁盘占满**:调小 `RETENTION_DAYS`,或页面上点「清理过期 / 清空全部」。