` | string | 服务特定的配置参数 |
### 安装依赖
```bash
pip install opendal
```
### Google Cloud Storage 配置示例
```bash
file_storage=opendal
opendal_scheme=gcs
opendal_gcs_root=/filecodebox
opendal_gcs_bucket=your-bucket-name
opendal_gcs_credential=base64_encoded_credential
```
### Azure Blob Storage 配置示例
```bash
file_storage=opendal
opendal_scheme=azblob
opendal_azblob_root=/filecodebox
opendal_azblob_container=your-container
opendal_azblob_account_name=your_account
opendal_azblob_account_key=your_key
```
### 支持的服务
OpenDAL 支持众多存储服务,完整列表请参考 [OpenDAL 官方文档](https://opendal.apache.org/docs/rust/opendal/services/index.html)。
常用服务包括:
- `gcs` - Google Cloud Storage
- `azblob` - Azure Blob Storage
- `obs` - 华为云 OBS
- `oss` - 阿里云 OSS(通过 OpenDAL)
- `cos` - 腾讯云 COS(通过 OpenDAL)
- `hdfs` - Hadoop HDFS
- `ftp` - FTP 服务器
- `sftp` - SFTP 服务器
::: warning OpenDAL 注意事项
1. 通过 OpenDAL 集成的服务均通过服务器中转下载,会同时消耗存储服务和服务器的流量
2. 相比原生 S3/OneDrive 支持,OpenDAL 方式可能缺少一些调试信息
3. OpenDAL 采用 Rust 编写,性能较好
:::
## 存储选择建议
| 场景 | 推荐存储 | 原因 |
|------|----------|------|
| 个人/小型部署 | 本地存储 | 简单易用,无需额外配置 |
| 企业内网 | MinIO + S3 | 自建对象存储,数据可控 |
| 公有云部署 | 对应云厂商 S3 | 同区域访问快,成本低 |
| 已有 OneDrive | OneDrive | 利用现有资源 |
| 已有 WebDAV | WebDAV | 兼容性好 |
| 特殊存储需求 | OpenDAL | 支持更多存储服务 |
## 常见问题
### S3 上传失败
1. 检查 Access Key 和 Secret Key 是否正确
2. 确认存储桶名称和区域配置正确
3. 检查存储桶的访问权限设置
4. 确认签名版本(`s3v2` 或 `s3v4`)与服务商要求一致
### OneDrive 认证失败
1. 确认使用的是工作/学校账户,而非个人账户
2. 检查 Azure 应用是否已授予管理员同意
3. 确认 API 权限配置完整
4. 验证用户名和密码是否正确
### WebDAV 连接失败
1. 检查 WebDAV URL 格式是否正确
2. 确认用户名和密码(或应用密码)正确
3. 检查服务器是否支持 WebDAV 协议
4. 确认网络连接正常
================================================
FILE: docs/guide/upload.md
================================================
# 文件上传
FileCodeBox 提供了多种灵活的文件上传方式,支持普通上传和分片上传,满足不同场景的需求。
## 上传方式
FileCodeBox 支持以下几种上传方式:
### 拖拽上传
将文件直接拖拽到上传区域即可开始上传。这是最便捷的上传方式。
1. 打开 FileCodeBox 首页
2. 将文件从文件管理器拖拽到上传区域
3. 松开鼠标,文件开始上传
4. 上传完成后获取提取码
::: tip 提示
拖拽上传支持同时拖拽多个文件(取决于主题支持)。
:::
### 点击上传
点击上传区域,通过系统文件选择器选择文件。
1. 点击上传区域的「选择文件」按钮
2. 在弹出的文件选择器中选择要上传的文件
3. 确认选择后文件开始上传
4. 上传完成后获取提取码
### 粘贴上传
支持从剪贴板直接粘贴图片进行上传(部分主题支持)。
1. 复制图片到剪贴板(截图或复制图片)
2. 在上传区域使用 `Ctrl+V`(Windows/Linux)或 `Cmd+V`(macOS)粘贴
3. 图片自动开始上传
4. 上传完成后获取提取码
::: warning 注意
粘贴上传仅支持图片格式,不支持其他文件类型。具体支持情况取决于所使用的主题。
:::
## 文件大小限制
### 默认限制
| 配置项 | 默认值 | 说明 |
|--------|--------|------|
| `uploadSize` | 10MB | 单文件最大上传大小 |
### 修改上传限制
管理员可以通过管理面板或配置文件修改上传大小限制:
```python
# 设置最大上传大小为 100MB
uploadSize = 104857600 # 100 * 1024 * 1024
```
::: info 说明
`uploadSize` 的单位是字节。常用换算:
- 10MB = 10485760
- 50MB = 52428800
- 100MB = 104857600
- 500MB = 524288000
- 1GB = 1073741824
:::
### 超出限制的处理
当上传文件超过大小限制时,系统会返回 403 错误:
```json
{
"detail": "大小超过限制,最大为10.00 MB"
}
```
## 普通上传 API
### 文件上传接口
**POST** `/share/file/`
Content-Type: `multipart/form-data`
**请求参数:**
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| `file` | file | 是 | 要上传的文件 |
| `expire_value` | int | 否 | 过期数值,默认 1 |
| `expire_style` | string | 否 | 过期方式,默认 `day` |
**过期方式选项:**
| 值 | 说明 |
|----|------|
| `day` | 按天过期 |
| `hour` | 按小时过期 |
| `minute` | 按分钟过期 |
| `forever` | 永不过期 |
| `count` | 按下载次数过期 |
**响应示例:**
```json
{
"code": 200,
"detail": {
"code": "654321",
"name": "example.pdf"
}
}
```
**cURL 示例:**
```bash
# 上传文件(默认1天有效期)
curl -X POST "http://localhost:12345/share/file/" \
-F "file=@/path/to/file.pdf"
# 上传文件并指定有效期(7天)
curl -X POST "http://localhost:12345/share/file/" \
-F "file=@/path/to/file.pdf" \
-F "expire_value=7" \
-F "expire_style=day"
# 上传文件并指定有效期(可下载10次)
curl -X POST "http://localhost:12345/share/file/" \
-F "file=@/path/to/file.pdf" \
-F "expire_value=10" \
-F "expire_style=count"
# 分享文本
curl -X POST "http://localhost:12345/share/text/" \
-F "text=这是要分享的文本内容"
# 通过取件码下载文件
curl -L "http://localhost:12345/share/select/?code=取件码" -o downloaded_file
```
::: tip 需要认证时
如果管理面板关闭了游客上传(`openUpload=0`),需要先登录获取 token:
```bash
# 1. 登录获取 token
curl -X POST "http://localhost:12345/admin/login" \
-H "Content-Type: application/json" \
-d '{"password": "FileCodeBox2023"}'
# 返回: {"code":200,"msg":"success","detail":{"token":"xxx.xxx.xxx","token_type":"Bearer"}}
# 2. 使用 token 上传文件
curl -X POST "http://localhost:12345/share/file/" \
-H "Authorization: Bearer xxx.xxx.xxx" \
-F "file=@/path/to/file.pdf"
# 3. 使用 token 分享文本
curl -X POST "http://localhost:12345/share/text/" \
-H "Authorization: Bearer xxx.xxx.xxx" \
-F "text=这是要分享的文本内容"
```
:::
## 分片上传 API
对于大文件,FileCodeBox 支持分片上传功能。分片上传将大文件分割成多个小块分别上传,支持断点续传。
::: warning 前提条件
分片上传功能需要管理员启用:`enableChunk=1`
:::
### 分片上传流程
```
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ 初始化上传 │ ──▶ │ 上传分片 │ ──▶ │ 完成上传 │
│ /init/ │ │ /chunk/ │ │ /complete/ │
└─────────────┘ └─────────────┘ └─────────────┘
│
▼
┌───────────┐
│ 循环上传 │
│ 每个分片 │
└───────────┘
```
### 1. 初始化上传
**POST** `/chunk/upload/init/`
**请求参数:**
```json
{
"file_name": "large_file.zip",
"file_size": 104857600,
"chunk_size": 5242880,
"file_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
}
```
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|------|------|------|--------|------|
| `file_name` | string | 是 | - | 文件名 |
| `file_size` | int | 是 | - | 文件总大小(字节) |
| `chunk_size` | int | 否 | 5MB | 分片大小(字节) |
| `file_hash` | string | 是 | - | 文件的 SHA256 哈希值 |
**响应示例:**
```json
{
"code": 200,
"detail": {
"existed": false,
"upload_id": "abc123def456789",
"chunk_size": 5242880,
"total_chunks": 20,
"uploaded_chunks": []
}
}
```
| 字段 | 说明 |
|------|------|
| `existed` | 文件是否已存在(秒传) |
| `upload_id` | 上传会话 ID |
| `chunk_size` | 分片大小 |
| `total_chunks` | 总分片数 |
| `uploaded_chunks` | 已上传的分片索引列表 |
### 2. 上传分片
**POST** `/chunk/upload/chunk/{upload_id}/{chunk_index}`
**路径参数:**
| 参数 | 说明 |
|------|------|
| `upload_id` | 初始化时返回的上传会话 ID |
| `chunk_index` | 分片索引,从 0 开始 |
**请求体:**
Content-Type: `multipart/form-data`
| 参数 | 类型 | 说明 |
|------|------|------|
| `chunk` | file | 分片数据 |
**响应示例:**
```json
{
"code": 200,
"detail": {
"chunk_hash": "a1b2c3d4e5f6..."
}
}
```
**cURL 示例:**
```bash
# 上传第一个分片(索引为 0)
curl -X POST "http://localhost:12345/chunk/upload/chunk/abc123def456789/0" \
-F "chunk=@/path/to/chunk_0"
```
### 3. 完成上传
**POST** `/chunk/upload/complete/{upload_id}`
**路径参数:**
| 参数 | 说明 |
|------|------|
| `upload_id` | 上传会话 ID |
**请求参数:**
```json
{
"expire_value": 7,
"expire_style": "day"
}
```
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| `expire_value` | int | 是 | 过期数值 |
| `expire_style` | string | 是 | 过期方式 |
**响应示例:**
```json
{
"code": 200,
"detail": {
"code": "789012",
"name": "large_file.zip"
}
}
```
### 断点续传
分片上传支持断点续传。当上传中断后:
1. 使用相同的 `file_hash` 重新调用初始化接口
2. 服务器返回 `uploaded_chunks` 列表,包含已上传的分片索引
3. 客户端只需上传不在列表中的分片
4. 所有分片上传完成后调用完成接口
**示例流程:**
```javascript
// 1. 初始化上传
const initResponse = await fetch('/chunk/upload/init/', {
method: 'POST',
body: JSON.stringify({
file_name: 'large_file.zip',
file_size: fileSize,
chunk_size: 5 * 1024 * 1024,
file_hash: fileHash
})
});
const { upload_id, uploaded_chunks, total_chunks } = await initResponse.json();
// 2. 上传未完成的分片
for (let i = 0; i < total_chunks; i++) {
if (!uploaded_chunks.includes(i)) {
const chunk = file.slice(i * chunkSize, (i + 1) * chunkSize);
await fetch(`/chunk/upload/chunk/${upload_id}/${i}`, {
method: 'POST',
body: chunk
});
}
}
// 3. 完成上传
await fetch(`/chunk/upload/complete/${upload_id}`, {
method: 'POST',
body: JSON.stringify({
expire_value: 7,
expire_style: 'day'
})
});
```
## 错误处理
### 常见错误
| HTTP 状态码 | 错误信息 | 原因 | 解决方案 |
|-------------|----------|------|----------|
| 403 | 大小超过限制 | 文件超过 `uploadSize` 限制 | 减小文件大小或联系管理员调整限制 |
| 403 | 上传频率限制 | 超过 IP 上传频率限制 | 等待限制时间窗口后重试 |
| 400 | 过期时间类型错误 | `expire_style` 值不在允许列表中 | 使用有效的过期方式 |
| 404 | 上传会话不存在 | `upload_id` 无效或已过期 | 重新初始化上传 |
| 400 | 无效的分片索引 | `chunk_index` 超出范围 | 检查分片索引是否正确 |
| 400 | 分片不完整 | 完成上传时分片数量不足 | 确保所有分片都已上传 |
### 频率限制
系统对上传操作有频率限制,防止滥用:
| 配置项 | 默认值 | 说明 |
|--------|--------|------|
| `uploadMinute` | 1 | 限制时间窗口(分钟) |
| `uploadCount` | 10 | 时间窗口内最大上传次数 |
当超过频率限制时,需要等待时间窗口过后才能继续上传。
### 错误响应格式
```json
{
"detail": "错误信息描述"
}
```
## 上传配置
### 相关配置项
| 配置项 | 类型 | 默认值 | 说明 |
|--------|------|--------|------|
| `openUpload` | int | 1 | 是否开放上传(1=开放,0=关闭) |
| `uploadSize` | int | 10485760 | 最大上传大小(字节) |
| `enableChunk` | int | 0 | 是否启用分片上传(1=启用,0=禁用) |
| `uploadMinute` | int | 1 | 上传频率限制时间窗口(分钟) |
| `uploadCount` | int | 10 | 时间窗口内最大上传次数 |
| `expireStyle` | list | ["day","hour","minute","forever","count"] | 允许的过期方式 |
### 配置示例
```python
# 允许上传 100MB 文件,启用分片上传
uploadSize = 104857600
enableChunk = 1
# 放宽上传频率限制:每 5 分钟最多 50 次
uploadMinute = 5
uploadCount = 50
# 只允许按天和按次数过期
expireStyle = ["day", "count"]
```
## 下一步
- [文件分享](/guide/share) - 了解完整的分享流程
- [配置说明](/guide/configuration) - 了解所有配置选项
- [存储配置](/guide/storage) - 了解文件存储方式
- [安全设置](/guide/security) - 了解安全相关配置
================================================
FILE: docs/index.md
================================================
---
layout: home
hero:
name: "FileCodeBox"
text: "文件快递柜"
tagline: 匿名口令分享文本,文件,像拿快递一样取文件
image:
src: /logo_small.png
alt: FileCodeBox
actions:
- theme: brand
text: 快速开始
link: /guide/getting-started
- theme: alt
text: 在线体验
link: https://share.lanol.cn
- theme: alt
text: 在 GitHub 上查看
link: https://github.com/vastsa/FileCodeBox
features:
- icon: 🚀
title: 快速部署
details: 支持 Docker 一键部署,简单快捷,无需复杂配置
- icon: 🔒
title: 安全可靠
details: 文件访问需要提取码,支持设置有效期和下载次数限制
- icon: 💻
title: 简洁界面
details: 清爽的用户界面,支持拖拽上传,使用体验极佳
- icon: 🛠️
title: 功能丰富
details: 支持文件预览、在线播放、图片处理等多种功能
- icon: 📦
title: 存储扩展
details: 支持本地存储、对象存储等多种存储方式
- icon: 🔌
title: API 支持
details: 提供完整的 REST API,方便与其他系统集成
---
================================================
FILE: docs/package.json
================================================
{
"devDependencies": {
"vitepress": "^1.6.3"
},
"scripts": {
"docs:dev": "vitepress dev",
"docs:build": "vitepress build",
"docs:preview": "vitepress preview"
}
}
================================================
FILE: docs/showcase.md
================================================
# 优秀案例
这里收录了一些使用 FileCodeBox 搭建的优秀站点。如果你也部署了 FileCodeBox,欢迎提交 PR 将你的站点添加到这里!
## 官方演示站
### 🌟 FileCodeBox Demo
- **网址**:[share.lanol.cn](https://share.lanol.cn)
- **简介**:官方演示站点,体验最新功能
- **特点**:稳定运行,功能完整
## 社区站点
::: tip 提交你的站点
如果你使用 FileCodeBox 搭建了自己的文件分享服务,欢迎通过以下方式提交:
1. 在 [GitHub](https://github.com/vastsa/FileCodeBox) 提交 PR,编辑此页面
2. 在 [Issues](https://github.com/vastsa/FileCodeBox/issues) 中提交你的站点信息
3. 加入 QQ 群 739673698 联系管理员
:::
### 取文件
- **网址**:[www.quwenjian.cn/fby.html](https://www.quwenjian.cn/fby.html)
- **简介**:取文件 - 存储无界,便携无限
- **特点**:永久免费的文件中转站
- **运营者**:取文件&取文件网盘
### 潘多拉盒子
- **网址**:[pan.duo.la](https://pan.duo.la)
- **简介**:潘多拉盒子
- **特点**:经典1.6版本
- **运营者**:五行缺心眼
## 提交要求
为了保证收录站点的质量,请确保你的站点满足以下条件:
1. **稳定运行**:站点需要稳定运行,能够正常访问
2. **合法合规**:站点内容需要合法合规,不得包含违法违规内容
3. **保留版权**:建议保留 FileCodeBox 的版权信息
4. **HTTPS 支持**:建议启用 HTTPS 加密访问
## 案例展示模板
如果你想提交站点,请按照以下格式:
```markdown
### 站点名称
- **网址**:[域名](https://域名)
- **简介**:一句话描述站点用途
- **特点**:站点的特色功能或亮点
- **运营者**:可选,你的名字或组织
```
================================================
FILE: main.py
================================================
# @Time : 2023/8/9 23:23
# @Author : Lan
# @File : main.py
# @Software: PyCharm
import asyncio
import time
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from tortoise import Tortoise
from tortoise.contrib.fastapi import register_tortoise
from apps.admin.views import admin_api
from apps.base.models import KeyValue
from apps.base.utils import ip_limit
from apps.base.views import share_api, chunk_api, presign_api
from core.config import ensure_settings_row, refresh_settings
from core.database import db_startup_lock, get_db_config, init_db
from core.logger import logger
from core.response import APIResponse
from core.settings import settings, BASE_DIR, DEFAULT_CONFIG
from core.tasks import delete_expire_files, clean_incomplete_uploads
from core.utils import hash_password, is_password_hashed
@asynccontextmanager
async def lifespan(app: FastAPI):
logger.info("正在初始化应用...")
# 初始化数据库
await init_db()
# 加载配置(多进程下串行化启动写操作)
async with db_startup_lock():
await load_config()
app.mount(
"/assets",
StaticFiles(directory=f"./{settings.themesSelect}/assets"),
name="assets",
)
# 启动后台任务
task = asyncio.create_task(delete_expire_files())
chunk_cleanup_task = asyncio.create_task(clean_incomplete_uploads())
logger.info("应用初始化完成")
try:
yield
finally:
# 清理操作
logger.info("正在关闭应用...")
task.cancel()
chunk_cleanup_task.cancel()
await asyncio.gather(task, chunk_cleanup_task, return_exceptions=True)
await Tortoise.close_connections()
logger.info("应用已关闭")
async def load_config():
await ensure_settings_row()
await KeyValue.update_or_create(
key="sys_start", defaults={"value": int(time.time() * 1000)}
)
await refresh_settings()
await migrate_password_to_hash()
ip_limit["error"].minutes = settings.errorMinute
ip_limit["error"].count = settings.errorCount
ip_limit["upload"].minutes = settings.uploadMinute
ip_limit["upload"].count = settings.uploadCount
async def migrate_password_to_hash():
if not is_password_hashed(settings.admin_token):
hashed = hash_password(settings.admin_token)
settings.admin_token = hashed
config_record = await KeyValue.filter(key="settings").first()
if config_record and config_record.value:
config_record.value["admin_token"] = hashed
await config_record.save()
logger.info("已将管理员密码迁移为哈希存储")
app = FastAPI(lifespan=lifespan)
@app.middleware("http")
async def refresh_settings_middleware(request, call_next):
await refresh_settings()
return await call_next(request)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# 使用 register_tortoise 来添加异常处理器
register_tortoise(
app,
config=get_db_config(),
generate_schemas=False,
add_exception_handlers=True,
)
app.include_router(share_api)
app.include_router(chunk_api)
app.include_router(presign_api)
app.include_router(admin_api)
@app.exception_handler(404)
@app.get("/")
async def index(request=None, exc=None):
return HTMLResponse(
content=open(
BASE_DIR / f"{settings.themesSelect}/index.html", "r", encoding="utf-8"
)
.read()
.replace("{{title}}", str(settings.name))
.replace("{{description}}", str(settings.description))
.replace("{{keywords}}", str(settings.keywords))
.replace("{{opacity}}", str(settings.opacity))
.replace('"/assets/', '"assets/')
.replace("{{background}}", str(settings.background)),
media_type="text/html",
headers={"Cache-Control": "no-cache"},
)
@app.get("/robots.txt")
async def robots():
return HTMLResponse(content=settings.robotsText, media_type="text/plain")
@app.post("/")
async def get_config():
return APIResponse(
detail={
"name": settings.name,
"description": settings.description,
"explain": settings.page_explain,
"uploadSize": settings.uploadSize,
"expireStyle": settings.expireStyle,
"enableChunk": settings.enableChunk,
"openUpload": settings.openUpload,
"notify_title": settings.notify_title,
"notify_content": settings.notify_content,
"show_admin_address": settings.showAdminAddr,
"max_save_seconds": settings.max_save_seconds,
}
)
if __name__ == "__main__":
import uvicorn
uvicorn.run(
app="main:app",
host=settings.serverHost,
port=settings.serverPort,
reload=False,
workers=settings.serverWorkers,
)
================================================
FILE: readme.md
================================================
# FileCodeBox
### 文件快递柜 - 匿名口令分享文本和文件

像拿快递一样取文件,无需注册,输入口令即可获取
[](https://github.com/vastsa/FileCodeBox/stargazers)
[](https://github.com/vastsa/FileCodeBox/network)
[](https://github.com/vastsa/FileCodeBox/issues)
[](https://github.com/vastsa/FileCodeBox/blob/master/LICENSE)
[](https://hub.docker.com/r/lanol/filecodebox)
[](https://www.python.org)
[](https://fastapi.tiangolo.com)
[](https://vuejs.org)
[English](./readme_en.md) | [在线演示](https://share.lanol.cn) | [部署教程](https://github.com/vastsa/FileCodeBox/wiki/部署教程) | [常见问题](https://github.com/vastsa/FileCodeBox/wiki/常见问题) | [QQ群: 739673698](https://qm.qq.com/q/PemPzhdEIM)
```bash
# 🚀 一键部署
docker run -d -p 12345:12345 -v /opt/FileCodeBox:/app/data --name filecodebox lanol/filecodebox:latest
# 国内镜像(如果上面拉取缓慢): docker.cnb.cool/aixk/filecodebox
```
---
## 目录
- [项目简介](#-项目简介)
- [功能特性](#-功能特性)
- [界面预览](#-界面预览)
- [快速开始](#-快速开始)
- [使用指南](#-使用指南)
- [开发指南](#-开发指南)
- [常见问题](#-常见问题)
- [贡献指南](#-贡献指南)
- [项目统计](#-项目统计)
- [免责声明](#-免责声明)
---
## 📝 项目简介
FileCodeBox 是一个轻量级的文件分享工具,基于 **FastAPI + Vue3** 开发。用户可以通过简单的方式匿名分享文本和文件,接收者只需输入提取码即可获取内容——就像从快递柜取出快递一样简单。
### 应用场景
| 场景 | 描述 |
|------|------|
| 📁 **临时文件分享** | 快速分享文件,无需注册登录 |
| 📝 **代码片段分享** | 分享代码、配置文件等文本内容 |
| 🕶️ **匿名文件传输** | 保护隐私的点对点传输 |
| 🔄 **跨设备传输** | 在不同设备间快速同步文件 |
| 💾 **临时存储** | 支持自定义过期时间的云存储 |
| 🌐 **私有服务** | 搭建企业或个人专属分享服务 |
---
## ✨ 功能特性
|
### 🚀 轻量高效
- FastAPI + SQLite3 后端
- Vue3 + Element Plus 前端
- Docker 一键部署
- 资源占用极低
|
### 🔒 安全可靠
- IP 上传频率限制
- 提取码错误次数限制
- 文件自动过期清理
- 支持管理员认证
|
### 📤 便捷上传
- 拖拽上传
- 复制粘贴上传
- 命令行 curl 上传
- 批量文件上传
|
|
### 🎫 灵活分享
- 随机/自定义提取码
- 可设置有效期(时间/次数)
- 支持永久有效
- 文本和文件统一管理
|
### 💾 多存储支持
- 本地文件系统
- S3 兼容存储
- [OneDrive](./docs/guide/storage-onedrive.md)
- [OpenDAL](./docs/guide/storage-opendal.md)
|
### 🌍 国际化
- 简体中文
- 繁体中文
- English
- 响应式设计 / 深色模式
|
---
## 🖼️ 界面预览
> 前端源码仓库:[2024主题](https://github.com/vastsa/FileCodeBoxFronted) | [2023主题](https://github.com/vastsa/FileCodeBoxFronted2023)
🎨 新版界面 (2024)
📦 经典界面 (2023)
---
## 🚀 快速开始
### Docker 部署(推荐)
**方式一:Docker CLI**
```bash
# Docker Hub(推荐)
docker run -d --restart always -p 12345:12345 -v /opt/FileCodeBox:/app/data --name filecodebox lanol/filecodebox:latest
# 国内镜像(如果 Docker Hub 拉取缓慢)
docker run -d --restart always -p 12345:12345 -v /opt/FileCodeBox:/app/data --name filecodebox docker.cnb.cool/aixk/filecodebox
```
**方式二:Docker Compose**
```yaml
services:
filecodebox:
image: lanol/filecodebox:latest
container_name: filecodebox
restart: unless-stopped
ports:
- "12345:12345"
volumes:
- ./data:/app/data
environment:
- WORKERS=4
- LOG_LEVEL=info
```
```bash
docker compose up -d
```
**环境变量说明**
| 变量 | 默认值 | 说明 |
|------|--------|------|
| `HOST` | `::` | 监听地址(支持 IPv4/IPv6 双栈) |
| `PORT` | `12345` | 服务端口 |
| `WORKERS` | `4` | 工作进程数(建议设为 CPU 核心数) |
| `LOG_LEVEL` | `info` | 日志级别:`debug` / `info` / `warning` / `error` |
### 反向代理配置
使用 Nginx 时,请添加以下配置以正确获取客户端 IP:
```nginx
location / {
proxy_pass http://127.0.0.1:12345;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 100m; # 根据需要调整上传大小限制
}
```
### 手动部署
```bash
# 1. 克隆项目
git clone https://github.com/vastsa/FileCodeBox.git
cd FileCodeBox
# 2. 安装依赖
pip install -r requirements.txt
# 3. 启动服务
python main.py
```
---
## 📖 使用指南
### 基础操作
| 操作 | 步骤 |
|------|------|
| **分享文件** | 打开网页 → 选择/拖拽文件 → 设置有效期 → 获取提取码 |
| **获取文件** | 打开网页 → 输入提取码 → 下载文件或查看文本 |
| **管理后台** | 访问 `/#/admin` → 输入密码 `FileCodeBox2023` |
### 命令行使用(curl)
点击展开 curl 使用示例
**上传文件**
```bash
# 基础上传(默认 1 天有效期)
curl -X POST "http://localhost:12345/share/file/" \
-F "file=@/path/to/file.txt"
# 指定 1 小时有效期
curl -X POST "http://localhost:12345/share/file/" \
-F "file=@/path/to/file.txt" \
-F "expire_value=1" \
-F "expire_style=hour"
# 指定下载 10 次后过期
curl -X POST "http://localhost:12345/share/file/" \
-F "file=@/path/to/file.txt" \
-F "expire_value=10" \
-F "expire_style=count"
```
**分享文本**
```bash
curl -X POST "http://localhost:12345/share/text/" \
-F "text=要分享的文本内容"
```
**下载文件**
```bash
curl -L "http://localhost:12345/share/select/?code=提取码" -o filename
```
**有效期参数**
| `expire_style` | 说明 |
|----------------|------|
| `day` | 天数 |
| `hour` | 小时 |
| `minute` | 分钟 |
| `count` | 下载次数 |
| `forever` | 永久有效 |
**返回示例**
```json
{
"code": 200,
"msg": "success",
"detail": {
"code": "abcd1234",
"name": "file.txt"
}
}
```
**需要认证时**(管理员关闭游客上传后)
```bash
# 1. 获取 token
curl -X POST "http://localhost:12345/admin/login" \
-H "Content-Type: application/json" \
-d '{"password": "FileCodeBox2023"}'
# 2. 携带 token 上传
curl -X POST "http://localhost:12345/share/file/" \
-H "Authorization: Bearer " \
-F "file=@/path/to/file.txt"
```
---
## 🛠 开发指南
### 项目结构
```
FileCodeBox/
├── apps/ # 应用模块
│ ├── admin/ # 管理后台
│ └── base/ # 基础功能
├── core/ # 核心模块
├── data/ # 数据目录(运行时生成)
├── docs/ # 文档
└── main.py # 入口文件
```
### 本地开发
**后端**
```bash
pip install -r requirements.txt
python main.py
```
**前端**
```bash
# 前端仓库: https://github.com/vastsa/FileCodeBoxFronted
cd fcb-fronted
npm install
npm run dev
```
### 技术栈
| 类别 | 技术 |
|------|------|
| **后端框架** | FastAPI 0.128+ / Uvicorn |
| **数据库** | SQLite + Tortoise ORM |
| **数据验证** | Pydantic 2.x |
| **异步支持** | aiofiles / aiohttp / aioboto3 |
| **对象存储** | S3 协议 / OneDrive / OpenDAL |
| **前端框架** | Vue 3 + Element Plus + Vite |
| **运行环境** | Python 3.8+ / Node.js 18+ |
| **容器化** | Docker / Docker Compose |
---
## ❓ 常见问题
如何修改上传大小限制?
在管理面板中修改 `uploadSize` 配置项。如果使用 Nginx 反向代理,还需修改 `client_max_body_size`。
如何配置存储引擎?
在管理面板中选择存储引擎类型并配置相应参数。支持本地存储、S3、OneDrive、OpenDAL 等。
如何备份数据?
备份 `data` 目录即可,包含数据库和上传的文件。
如何修改管理员密码?
登录管理面板后,在系统设置中修改 `adminPassword` 配置项。
更多问题请访问 [Wiki](https://github.com/vastsa/FileCodeBox/wiki/常见问题) 或加入 [QQ群: 739673698](https://qm.qq.com/q/PemPzhdEIM)
---
## 🤝 贡献指南
欢迎提交 Issue 和 Pull Request!
```bash
# 1. Fork 并克隆
git clone https://github.com/your-username/FileCodeBox.git
# 2. 创建分支
git checkout -b feature/your-feature
# 3. 提交更改
git commit -m "feat: add your feature"
# 4. 推送并创建 PR
git push origin feature/your-feature
```
---
## 📊 项目统计

[](https://star-history.com/#vastsa/FileCodeBox&Date)
---
## 🗓 更新计划
- [ ] 2025 年新皮肤
- [ ] 文件收集功能
---
## 📜 免责声明
本项目开源仅供学习交流使用,不得用于任何违法用途,否则后果自负,与作者无关。使用本项目时请保留项目地址和版权信息。
---
**如果觉得项目不错,欢迎 ⭐ Star 支持!**
Made with ❤️ by [vastsa](https://github.com/vastsa)
================================================
FILE: readme_en.md
================================================
# FileCodeBox
### Anonymous File & Text Sharing with Passcode

Share files like picking up a package — no registration required, just enter the passcode
[](https://github.com/vastsa/FileCodeBox/stargazers)
[](https://github.com/vastsa/FileCodeBox/network)
[](https://github.com/vastsa/FileCodeBox/issues)
[](https://github.com/vastsa/FileCodeBox/blob/master/LICENSE)
[](https://hub.docker.com/r/lanol/filecodebox)
[](https://www.python.org)
[](https://fastapi.tiangolo.com)
[](https://vuejs.org)
[简体中文](./README.md) | [Live Demo](https://share.lanol.cn) | [Documentation](https://github.com/vastsa/FileCodeBox/wiki/Deployment-Guide) | [FAQ](https://github.com/vastsa/FileCodeBox/wiki/FAQ)
```bash
# 🚀 Quick Deploy
docker run -d -p 12345:12345 -v /opt/FileCodeBox:/app/data --name filecodebox lanol/filecodebox:latest
# China Mirror (if slow): docker.cnb.cool/aixk/filecodebox
```
---
## Table of Contents
- [Introduction](#-introduction)
- [Features](#-features)
- [Screenshots](#-screenshots)
- [Quick Start](#-quick-start)
- [Usage Guide](#-usage-guide)
- [Development](#-development)
- [FAQ](#-faq)
- [Contributing](#-contributing)
- [Statistics](#-statistics)
- [Disclaimer](#-disclaimer)
---
## 📝 Introduction
FileCodeBox is a lightweight file sharing tool built with **FastAPI + Vue3**. Users can anonymously share text and files, and recipients only need to enter a passcode to retrieve the content — just like picking up a package from a locker.
### Use Cases
| Scenario | Description |
|----------|-------------|
| 📁 **Temporary File Sharing** | Quick file sharing without registration |
| 📝 **Code Snippet Sharing** | Share code, config files, and text content |
| 🕶️ **Anonymous Transfer** | Privacy-protected peer-to-peer transfer |
| 🔄 **Cross-Device Transfer** | Quickly sync files between devices |
| 💾 **Temporary Storage** | Cloud storage with custom expiration |
| 🌐 **Private Service** | Build your own enterprise or personal sharing service |
---
## ✨ Features
|
### 🚀 Lightweight & Fast
- FastAPI + SQLite3 backend
- Vue3 + Element Plus frontend
- One-click Docker deployment
- Minimal resource usage
|
### 🔒 Secure & Reliable
- IP upload rate limiting
- Passcode attempt limiting
- Auto file expiration cleanup
- Admin authentication support
|
### 📤 Easy Upload
- Drag & drop upload
- Copy & paste upload
- Command line curl upload
- Batch file upload
|
|
### 🎫 Flexible Sharing
- Random / custom passcodes
- Set expiration (time/count)
- Permanent validity support
- Unified text & file management
|
### 💾 Multiple Storage
- Local file system
- S3-compatible storage
- [OneDrive](./docs/guide/storage-onedrive.md)
- [OpenDAL](./docs/guide/storage-opendal.md)
|
### 🌍 Internationalization
- Simplified Chinese
- Traditional Chinese
- English
- Responsive design / Dark mode
|
---
## 🖼️ Screenshots
> Frontend repositories: [2024 Theme](https://github.com/vastsa/FileCodeBoxFronted) | [2023 Theme](https://github.com/vastsa/FileCodeBoxFronted2023)
🎨 New Interface (2024)
📦 Classic Interface (2023)
---
## 🚀 Quick Start
### Docker Deployment (Recommended)
**Option 1: Docker CLI**
```bash
# Docker Hub (Recommended)
docker run -d --restart always -p 12345:12345 -v /opt/FileCodeBox:/app/data --name filecodebox lanol/filecodebox:latest
# China Mirror (if Docker Hub is slow)
docker run -d --restart always -p 12345:12345 -v /opt/FileCodeBox:/app/data --name filecodebox docker.cnb.cool/aixk/filecodebox
```
**Option 2: Docker Compose**
```yaml
services:
filecodebox:
image: lanol/filecodebox:latest
container_name: filecodebox
restart: unless-stopped
ports:
- "12345:12345"
volumes:
- ./data:/app/data
environment:
- WORKERS=4
- LOG_LEVEL=info
```
```bash
docker compose up -d
```
**Environment Variables**
| Variable | Default | Description |
|----------|---------|-------------|
| `HOST` | `::` | Listen address (supports IPv4/IPv6 dual-stack) |
| `PORT` | `12345` | Service port |
| `WORKERS` | `4` | Worker processes (recommended: CPU cores) |
| `LOG_LEVEL` | `info` | Log level: `debug` / `info` / `warning` / `error` |
### Reverse Proxy Configuration
When using Nginx, add the following configuration to properly obtain client IP:
```nginx
location / {
proxy_pass http://127.0.0.1:12345;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 100m; # Adjust upload size limit as needed
}
```
### Manual Deployment
```bash
# 1. Clone the repository
git clone https://github.com/vastsa/FileCodeBox.git
cd FileCodeBox
# 2. Install dependencies
pip install -r requirements.txt
# 3. Start the service
python main.py
```
---
## 📖 Usage Guide
### Basic Operations
| Operation | Steps |
|-----------|-------|
| **Share File** | Open website → Select/drag files → Set expiration → Get passcode |
| **Retrieve File** | Open website → Enter passcode → Download file or view text |
| **Admin Panel** | Visit `/#/admin` → Enter password `FileCodeBox2023` |
### Command Line Usage (curl)
Click to expand curl examples
**Upload File**
```bash
# Basic upload (default 1 day expiration)
curl -X POST "http://localhost:12345/share/file/" \
-F "file=@/path/to/file.txt"
# Set 1 hour expiration
curl -X POST "http://localhost:12345/share/file/" \
-F "file=@/path/to/file.txt" \
-F "expire_value=1" \
-F "expire_style=hour"
# Set expiration after 10 downloads
curl -X POST "http://localhost:12345/share/file/" \
-F "file=@/path/to/file.txt" \
-F "expire_value=10" \
-F "expire_style=count"
```
**Share Text**
```bash
curl -X POST "http://localhost:12345/share/text/" \
-F "text=Text content to share"
```
**Download File**
```bash
curl -L "http://localhost:12345/share/select/?code=PASSCODE" -o filename
```
**Expiration Parameters**
| `expire_style` | Description |
|----------------|-------------|
| `day` | Days |
| `hour` | Hours |
| `minute` | Minutes |
| `count` | Download count |
| `forever` | Never expire |
**Response Example**
```json
{
"code": 200,
"msg": "success",
"detail": {
"code": "abcd1234",
"name": "file.txt"
}
}
```
**When Authentication Required** (after admin disables guest upload)
```bash
# 1. Get token
curl -X POST "http://localhost:12345/admin/login" \
-H "Content-Type: application/json" \
-d '{"password": "FileCodeBox2023"}'
# 2. Upload with token
curl -X POST "http://localhost:12345/share/file/" \
-H "Authorization: Bearer " \
-F "file=@/path/to/file.txt"
```
---
## 🛠 Development
### Project Structure
```
FileCodeBox/
├── apps/ # Application modules
│ ├── admin/ # Admin backend
│ └── base/ # Base functionality
├── core/ # Core modules
├── data/ # Data directory (generated at runtime)
├── docs/ # Documentation
└── main.py # Entry point
```
### Local Development
**Backend**
```bash
pip install -r requirements.txt
python main.py
```
**Frontend**
```bash
# Frontend repo: https://github.com/vastsa/FileCodeBoxFronted
cd fcb-fronted
npm install
npm run dev
```
### Tech Stack
| Category | Technology |
|----------|------------|
| **Backend Framework** | FastAPI 0.128+ / Uvicorn |
| **Database** | SQLite + Tortoise ORM |
| **Data Validation** | Pydantic 2.x |
| **Async Support** | aiofiles / aiohttp / aioboto3 |
| **Object Storage** | S3 Protocol / OneDrive / OpenDAL |
| **Frontend Framework** | Vue 3 + Element Plus + Vite |
| **Runtime** | Python 3.8+ / Node.js 18+ |
| **Containerization** | Docker / Docker Compose |
---
## ❓ FAQ
How to modify upload size limit?
Modify the `uploadSize` configuration in the admin panel. If using Nginx reverse proxy, also modify `client_max_body_size`.
How to configure storage engine?
Select the storage engine type and configure parameters in the admin panel. Supports local storage, S3, OneDrive, OpenDAL, etc.
How to backup data?
Backup the `data` directory, which contains the database and uploaded files.
How to change admin password?
After logging into the admin panel, modify the `adminPassword` configuration in system settings.
For more questions, visit [Wiki](https://github.com/vastsa/FileCodeBox/wiki/FAQ)
---
## 🤝 Contributing
Issues and Pull Requests are welcome!
```bash
# 1. Fork and clone
git clone https://github.com/your-username/FileCodeBox.git
# 2. Create branch
git checkout -b feature/your-feature
# 3. Commit changes
git commit -m "feat: add your feature"
# 4. Push and create PR
git push origin feature/your-feature
```
---
## 📊 Statistics

[](https://star-history.com/#vastsa/FileCodeBox&Date)
---
## 🗓 Roadmap
- [ ] 2025 New Theme
- [ ] File Collection Feature
---
## 📜 Disclaimer
This project is open-source for learning and communication purposes only. It should not be used for any illegal purposes. The author is not responsible for any consequences. Please retain the project address and copyright information when using it.
---
**If you find this project helpful, please give it a ⭐ Star!**
Made with ❤️ by [vastsa](https://github.com/vastsa)
================================================
FILE: requirements.txt
================================================
aioboto3==15.5.0
aiohttp==3.13.3
aiofiles==25.1.0
fastapi==0.128.0
pydantic==2.12.5
uvicorn==0.40.0
tortoise-orm==0.25.3
python-multipart==0.0.21