EasyScan Server - A FastAPI-based server for EasyScan
Project description
EasyScan Server
一个基于FastAPI的URL短链接服务,支持实时二维码生成和Server-Sent Events (SSE) 推送更新。
🚀 功能特性
- URL短链接服务: 生成短链接并支持重定向
- 实时二维码: 动态生成二维码,支持实时更新
- Server-Sent Events: 实时推送URL和名称变更
- Redis存储: 支持Redis和FakeRedis(开发/测试)
- RESTful API: 完整的REST API接口
- Docker支持: 容器化部署
- 可选名称: 为URL添加自定义名称
📦 安装
使用 pip 安装
pip install easyscan-server
从源码安装
git clone https://github.com/LiYulin-s/easyscan-server.git
cd easyscan-server
pip install -e .
🏃 快速开始
启动服务器
# 使用默认配置启动
python -m easyscan_server
# 自定义主机和端口
python -m easyscan_server --host 0.0.0.0 --port 8080
使用Docker
从GitHub Container Registry拉取(推荐)
# 拉取最新版本
docker pull ghcr.io/liyulin-s/easyscan-server:latest
# 运行容器
docker run -p 8000:8000 ghcr.io/liyulin-s/easyscan-server:latest
# 或者拉取指定版本
docker pull ghcr.io/liyulin-s/easyscan-server:v0.1.2
docker run -p 8000:8000 ghcr.io/liyulin-s/easyscan-server:v0.1.2
本地构建
# 构建镜像
docker build -t easyscan-server .
# 运行容器
docker run -p 8000:8000 easyscan-server
🔧 配置
环境变量
USE_REAL_REDIS: 设置此变量以使用真实的Redis(否则使用FakeRedis)REDIS_URL: Redis连接URL(默认:redis://localhost:6379)
示例配置
# 使用真实Redis
export USE_REAL_REDIS=1
export REDIS_URL=redis://localhost:6379
# 启动服务
python -m easyscan_server
🚀 CI/CD 自动化
本项目包含完整的 CI/CD 流程:
自动发布
- PyPI发布: 当推送符合
v*.*.*格式的标签时,自动构建并发布Python包到PyPI - Docker镜像: 自动构建多架构Docker镜像并推送到GitHub Container Registry
发布流程
- 更新
pyproject.toml中的版本号 - 创建并推送版本标签:
git tag v0.1.3 git push origin v0.1.3
- GitHub Actions将自动:
- 构建Python包并发布到PyPI
- 构建Docker镜像(支持 amd64 和 arm64)并推送到GHCR
手动触发
也可以在GitHub Actions页面手动触发Docker镜像构建。
📚 API 文档
创建短链接
POST /
Content-Type: application/json
{
"url": "https://example.com",
"name": "示例网站"
}
响应:
{
"key": "abc123def456",
"url": "https://example.com",
"name": "示例网站",
"success": true
}
获取URL信息
GET /{key}
响应:
{
"key": "abc123def456",
"url": "https://example.com",
"name": "示例网站"
}
更新现有链接
POST /{key}
Content-Type: application/json
{
"url": "https://newexample.com",
"name": "新示例网站"
}
重定向到目标URL
GET /{key}/redirect
查看二维码页面
GET /{key}/qrcode
Server-Sent Events
GET /sse/{key}
🏗️ 项目结构
easyscan-server/
├── __init__.py
├── __main__.py # 程序入口点
├── main.py # FastAPI应用主文件
├── domain.py # 数据层和业务逻辑
├── type.py # Pydantic模型定义
└── templates/
└── qrcode.html # 二维码页面模板
🧪 开发
设置开发环境
# 克隆仓库
git clone https://github.com/LiYulin-s/easyscan-server.git
cd easyscan-server
# 安装依赖
pip install -e .
# 运行开发服务器
python -m easyscan_server --host 0.0.0.0 --port 8000
依赖项
- FastAPI: Web框架
- Uvicorn: ASGI服务器
- Redis: 数据存储
- FakeRedis: 测试用Redis模拟器
- Pydantic: 数据验证
- Jinja2: 模板引擎
- Typer: CLI工具
🐳 Docker 部署
快速开始
从GitHub Container Registry部署(推荐)
# 基本部署 - 使用最新版本
docker run -p 8000:8000 ghcr.io/liyulin-s/easyscan-server:latest
# 使用指定版本
docker run -p 8000:8000 ghcr.io/liyulin-s/easyscan-server:v0.1.2
本地构建部署
# 克隆并构建
git clone https://github.com/LiYulin-s/easyscan-server.git
cd easyscan-server
docker build -t easyscan-server .
docker run -p 8000:8000 easyscan-server
生产环境部署
使用真实Redis部署
# 启动Redis容器
docker run -d --name redis redis:alpine
# 启动EasyScan Server并连接Redis
docker run -p 8000:8000 \
-e USE_REAL_REDIS=1 \
-e REDIS_URL=redis://redis:6379 \
--link redis:redis \
ghcr.io/liyulin/easyscan-server:latest
Docker Compose部署
创建 docker-compose.yml 文件:
version: '3.8'
services:
redis:
image: redis:alpine
restart: unless-stopped
ports:
- "6379:6379"
volumes:
- redis_data:/data
easyscan-server:
image: ghcr.io/liyulin-s/easyscan-server:latest
restart: unless-stopped
ports:
- "8000:8000"
environment:
- USE_REAL_REDIS=1
- REDIS_URL=redis://redis:6379
depends_on:
- redis
volumes:
redis_data:
启动服务:
docker-compose up -d
多架构支持
Docker 镜像支持多种架构:
linux/amd64(x86_64)linux/arm64(ARM64/Apple Silicon)
Docker 会自动选择适合您系统的架构版本。
镜像标签说明
latest: 最新稳定版本vX.Y.Z: 具体版本号(如v0.1.2)vX.Y: 主要版本号(如v0.1)vX: 大版本号(如v0)
📝 许可证
本项目采用 GNU Affero General Public License v3.0 许可证。详见 LICENSE 文件。
🤝 贡献
欢迎贡献!请阅读我们的贡献指南并提交Pull Request。
📞 支持
如果您遇到问题或有功能建议,请创建一个 Issue。
🙏 鸣谢
感谢以下开源项目和技术为EasyScan Server提供支持:
核心技术
开发工具
前端技术
- QRCode.js - JavaScript二维码生成库
- Server-Sent Events - 实时数据推送技术
部署和打包
- Docker - 容器化平台
- GitHub Container Registry - Docker镜像托管服务
- uv - 现代Python包管理器
- GitHub Actions - CI/CD自动化
特别感谢所有开源社区的贡献者们,是你们让这个项目成为可能! 🚀
EasyScan Server - 让URL分享变得简单快捷! 🚀
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easyscan_server-0.1.6.tar.gz.
File metadata
- Download URL: easyscan_server-0.1.6.tar.gz
- Upload date:
- Size: 42.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86d1bfb58c3fb2a0b50da1a8ad97834b4a7eddf8cccffcb15770669c705dba7f
|
|
| MD5 |
72203f9d9a3f6677b71f89744c315887
|
|
| BLAKE2b-256 |
d6f558a2b365995a0e47c74fff5605d96e2e736df4e704b862ba9b4da107ae13
|
Provenance
The following attestation bundles were made for easyscan_server-0.1.6.tar.gz:
Publisher:
publish.yml on LiYulin-s/easyscan-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
easyscan_server-0.1.6.tar.gz -
Subject digest:
86d1bfb58c3fb2a0b50da1a8ad97834b4a7eddf8cccffcb15770669c705dba7f - Sigstore transparency entry: 253483332
- Sigstore integration time:
-
Permalink:
LiYulin-s/easyscan-server@6f0f56172ac196a3cc87fac4c70d9b5fb592cab7 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/LiYulin-s
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6f0f56172ac196a3cc87fac4c70d9b5fb592cab7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file easyscan_server-0.1.6-py3-none-any.whl.
File metadata
- Download URL: easyscan_server-0.1.6-py3-none-any.whl
- Upload date:
- Size: 23.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9f06e470c1549a0c0f0120990637686d127000355dc422c0e2094b33c90ea2e
|
|
| MD5 |
69c9114677c8c2ca1e12570eb3782a06
|
|
| BLAKE2b-256 |
5d0599e68458e7f1feb40b72a14f00f0709e2cef5f0560476f29adb811da9a78
|
Provenance
The following attestation bundles were made for easyscan_server-0.1.6-py3-none-any.whl:
Publisher:
publish.yml on LiYulin-s/easyscan-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
easyscan_server-0.1.6-py3-none-any.whl -
Subject digest:
a9f06e470c1549a0c0f0120990637686d127000355dc422c0e2094b33c90ea2e - Sigstore transparency entry: 253483341
- Sigstore integration time:
-
Permalink:
LiYulin-s/easyscan-server@6f0f56172ac196a3cc87fac4c70d9b5fb592cab7 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/LiYulin-s
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6f0f56172ac196a3cc87fac4c70d9b5fb592cab7 -
Trigger Event:
push
-
Statement type: