{"id":28508005,"url":"https://github.com/2ue/jia-file","last_synced_at":"2025-10-10T21:39:42.814Z","repository":{"id":296515203,"uuid":"993604515","full_name":"2ue/jia-file","owner":"2ue","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-31T08:52:27.000Z","size":7773,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-17T19:26:51.477Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2ue.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-31T05:38:43.000Z","updated_at":"2025-05-31T08:52:30.000Z","dependencies_parsed_at":"2025-05-31T19:45:45.389Z","dependency_job_id":"44b8256e-74ea-4374-9cae-c39a576db4eb","html_url":"https://github.com/2ue/jia-file","commit_stats":null,"previous_names":["2ue/jia-file"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/2ue/jia-file","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fjia-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fjia-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fjia-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fjia-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2ue","download_url":"https://codeload.github.com/2ue/jia-file/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fjia-file/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005417,"owners_count":26083883,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-08T21:07:38.090Z","updated_at":"2025-10-10T21:39:42.798Z","avatar_url":"https://github.com/2ue.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Jia-File\n\n一个基于 Go 语言开发的简单文件管理系统，提供文件操作 API。\n\n## 功能特性\n\n- 文件列表查看\n- 创建文件和目录\n- 删除文件和目录\n- 移动和复制文件\n- 获取文件信息\n- 创建文档（支持多种格式）\n- 支持配置根目录限制\n\n## 项目结构\n\n```\n.\n├── api/            # API 类型定义\n├── cmd/            # 主程序入口\n├── internal/       # 内部包\n│   ├── file/      # 文件操作\n│   ├── handler/   # HTTP 处理器\n│   ├── logger/    # 日志模块\n│   ├── middleware/# 中间件\n│   └── errors/    # 错误处理\n├── scripts/       # 脚本文件\n└── docs/          # 文档\n```\n\n## 快速开始\n\n### 环境要求\n\n- Go 1.16 或更高版本\n- Air (用于热更新，可选)\n- Docker (可选，用于容器化部署)\n\n### 安装依赖\n\n```bash\n# 安装 Air (用于热更新)\ngo install github.com/cosmtrek/air@latest\n```\n\n### 配置说明\n\n可以通过环境变量或 .env 文件配置以下参数：\n\n- `PORT`: 服务器端口号（默认：8190）\n- `LOG_LEVEL`: 日志级别（默认：info）\n- `LOG_DIR`: 日志目录（默认：logs）\n- `ROOT_PATH`: 文件操作的根目录（可选）\n  - 如果设置，所有文件操作都将限制在此目录下\n  - 支持相对路径和绝对路径\n  - 如果未设置，则不限制文件操作范围\n\n### 运行项目\n\n#### 方式一：直接运行\n\n```bash\n# 编译项目\ngo build -o jia-file.exe ./cmd/server\n\n# 运行服务器\n./jia-file.exe\n```\n\n#### 方式二：使用 Air 热更新（推荐开发时使用）\n\n```bash\n# 在项目根目录运行\nair\n```\n\n#### 方式三：使用 Docker（推荐生产环境使用）\n\n```bash\n# 构建 Docker 镜像\ndocker build -t jia-file .\n\n# 运行容器\ndocker run -d \\\n  --name jia-file \\\n  -p 8190:8190 \\\n  -v /path/to/your/files:/app/files \\\n  -e ROOT_PATH=/app/files \\\n  jia-file\n```\n\n服务器将在 http://localhost:8190 启动。\n\n### API 端点\n\n- `GET /list?path=\u003cpath\u003e` - 列出目录内容\n- `POST /mkdir?path=\u003cpath\u003e` - 创建目录\n- `POST /touch?path=\u003cpath\u003e` - 创建文件\n- `DELETE /delete?path=\u003cpath\u003e` - 删除文件或目录\n- `POST /move?src=\u003csrc\u003e\u0026dst=\u003cdst\u003e` - 移动文件或目录\n- `POST /copy?src=\u003csrc\u003e\u0026dst=\u003cdst\u003e` - 复制文件或目录\n- `GET /info?path=\u003cpath\u003e` - 获取文件信息\n- `POST /document` - 创建文档\n\n### 路径处理说明\n\n当配置了 `ROOT_PATH` 时：\n- 相对路径会自动与 `ROOT_PATH` 拼接\n- 绝对路径会被验证是否在 `ROOT_PATH` 下\n- 如果尝试访问 `ROOT_PATH` 外的文件，将返回错误\n\n当未配置 `ROOT_PATH` 时：\n- 直接使用传入的路径，不进行任何修改\n- 支持相对路径和绝对路径\n\n### Docker 部署说明\n\n#### 构建镜像\n\n```bash\ndocker build -t jia-file .\n```\n\n#### 运行容器\n\n基本运行：\n```bash\ndocker run -d --name jia-file -p 8190:8190 jia-file\n```\n\n使用数据卷和环境变量：\n```bash\ndocker run -d \\\n  --name jia-file \\\n  -p 8190:8190 \\\n  -v /path/to/your/files:/app/files \\\n  -e ROOT_PATH=/app/files \\\n  -e LOG_LEVEL=info \\\n  jia-file\n```\n\n#### 环境变量\n\n可以在运行容器时通过 `-e` 参数设置以下环境变量：\n\n- `PORT`: 服务器端口号（默认：8190）\n- `LOG_LEVEL`: 日志级别（默认：info）\n- `LOG_DIR`: 日志目录（默认：/app/logs）\n- `ROOT_PATH`: 文件操作的根目录\n\n#### 数据卷\n\n建议使用数据卷来持久化存储文件：\n\n```bash\ndocker run -d \\\n  --name jia-file \\\n  -p 8190:8190 \\\n  -v /host/path/to/files:/app/files \\\n  -e ROOT_PATH=/app/files \\\n  jia-file\n```\n\n### 示例请求\n\n```bash\n# 列出目录内容\ncurl \"http://localhost:8190/list?path=./\"\n\n# 创建目录\ncurl -X POST \"http://localhost:8190/mkdir?path=./test\"\n\n# 创建文件\ncurl -X POST \"http://localhost:8190/touch?path=./test/file.txt\"\n\n# 获取文件信息\ncurl \"http://localhost:8190/info?path=./test/file.txt\"\n\n# 创建文档\ncurl -X POST \"http://localhost:8190/document\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"path\":\"./test/doc.md\",\"type\":\"md\",\"content\":\"# Hello World\"}'\n```\n\n## 开发说明\n\n### 热更新配置\n\n项目使用 Air 进行热更新，配置文件为 `.air.toml`。主要配置包括：\n\n```toml\nroot = \".\"\ntmp_dir = \"tmp\"\n\n[build]\ncmd = \"go build -o ./tmp/main.exe ./cmd/server\"\nbin = \"tmp/main.exe\"\ninclude_ext = [\"go\", \"tpl\", \"tmpl\", \"html\"]\nexclude_dir = [\"assets\", \"tmp\", \"vendor\"]\ndelay = 1000\nkill_delay = \"0s\"\nlog = \"build-errors.log\"\nsend_interrupt = false\nstop_on_error = true\n\n[log]\ntime = false\n\n[color]\nmain = \"magenta\"\nwatcher = \"cyan\"\nbuild = \"yellow\"\nrunner = \"green\"\n```\n\n### 日志\n\n日志文件位于 `logs` 目录下，按日期命名。包含以下级别的日志：\n- INFO: 普通信息\n- ERROR: 错误信息\n- DEBUG: 调试信息\n\n### 错误处理\n\n项目使用统一的错误处理机制，所有错误都会被记录到日志中，并返回统一的错误响应格式：\n\n```json\n{\n  \"code\": 1004,\n  \"message\": \"错误信息\",\n  \"data\": null\n}\n```\n\n## 贡献指南\n\n1. Fork 项目\n2. 创建特性分支\n3. 提交更改\n4. 推送到分支\n5. 创建 Pull Request\n\n## 许可证\n\nMIT License ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2ue%2Fjia-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2ue%2Fjia-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2ue%2Fjia-file/lists"}