Files
tradingview/README.md
2026-03-08 19:18:59 +07:00

179 lines
3.3 KiB
Markdown
Raw Permalink 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.
# 📁 文件托管服务
基于 Bun 的高性能文件托管服务,用于快速部署和访问静态文件。
## ✨ 功能特点
- 🚀 基于 Bun性能极佳
- 📂 支持目录浏览,美观的 Web 界面
- 🔍 自动识别文件 MIME 类型
- 🛡️ 防路径遍历攻击
- ⚙️ 简单配置,开箱即用
## 🚀 快速开始
### 安装依赖
```bash
bun install
```
### 启动服务
```bash
# 开发模式(自动重启)
bun run dev
# 生产模式
bun run start
```
### 访问服务
打开浏览器访问:`http://localhost:3000`
## 📦 使用说明
1. 将需要托管的文件放入 `files/` 目录
2. 启动服务
3. 通过浏览器访问文件:
- 访问根路径:`http://localhost:3000/` 查看所有文件
- 访问具体文件:`http://localhost:3000/your-file.pdf`
- 访问子目录:`http://localhost:3000/subfolder/`
## ⚙️ 配置
编辑 `.env` 文件修改配置:
```env
# 服务器端口
PORT=3000
# 文件存储目录
FILES_DIR=./files
```
## 🌐 部署到服务器
### 1. 安装 Bun
```bash
curl -fsSL https://bun.sh/install | bash
```
### 2. 上传代码到服务器
```bash
# 使用 git
git clone <your-repo>
# 或使用 scp
scp -r . user@server:/path/to/app
```
### 3. 启动服务
```bash
# 直接运行
bun run start
# 使用 PM2 管理(推荐)
pm2 start "bun run start" --name file-hosting
# 使用 systemd推荐
sudo nano /etc/systemd/system/file-hosting.service
```
### systemd 服务配置示例
```ini
[Unit]
Description=File Hosting Service
After=network.target
[Service]
Type=simple
User=your-user
WorkingDirectory=/path/to/app
ExecStart=/root/.bun/bin/bun run src/server.ts
Restart=always
Environment=PORT=3000
[Install]
WantedBy=multi-user.target
```
启用服务:
```bash
sudo systemctl enable file-hosting
sudo systemctl start file-hosting
sudo systemctl status file-hosting
```
### 4. 配置反向代理(可选)
使用 Nginx 反向代理:
```nginx
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
```
## 📝 项目结构
```
.
├── src/
│ └── server.ts # 服务器主文件
├── files/ # 文件存储目录
│ ├── .gitkeep
│ └── README.md # 示例文件
├── package.json
├── tsconfig.json
├── .env # 环境配置
├── .gitignore
└── README.md
```
## 🔒 安全建议
1. **不要暴露敏感文件**:确保 `files/` 目录中不包含敏感信息
2. **使用 HTTPS**:生产环境建议配置 SSL 证书
3. **添加认证**:如需限制访问,可添加 HTTP 基础认证或 JWT
4. **设置防火墙**:限制只允许特定 IP 访问
## 📄 支持的文件类型
- 文档PDF, TXT, MD
- 图片PNG, JPG, GIF, SVG
- 视频MP4
- 音频MP3
- 压缩包ZIP
- 网页HTML, CSS, JS
- 数据JSON
## 📈 性能
- 基于 Bun 原生文件 API性能是 Node.js 的 2-4 倍
- 低内存占用,适合小型服务器
- 支持高并发访问
## 🤝 贡献
欢迎提交 Issue 和 Pull Request
## 📜 许可
MIT License