Platform 短链接
短链接能力已合并到 FreeKit.Platform,代码位于 src/Services/Platform/FreeKit.Platform/ShortUrl。默认主宿主只需要启用 PlatformModuleStartup,不再单独注册 ShortModuleStartup。
功能范围
- 长链接生成短链接
- 批量生成短链接
- 按短链键查询目标链接
- 跳转时累计访问次数
- 支持过期时间
- 使用独立
ShortUrlConnectionStrings数据源和分表配置
API 入口
| 场景 | 路由 |
|---|---|
| 管理端分页查询 | GET api/plat/short_urls |
| 管理端详情 | GET api/plat/short_urls/{id} |
| 创建短链接 | POST api/plat/short_urls |
| 批量创建短链接 | POST api/plat/short_urls/batch |
| 按短链键查询 | GET api/plat/short_urls/{shortKey} |
| 跳转短链接 | GET api/plat/{shortKey} |
具体路由以 ShortUrlController 与 ShortUrlEndpoint 为准。
实体
ShortUrl
| 字段名 | 类型 | 描述 |
|---|---|---|
| Id | long | 主键,由雪花 ID 生成 |
| LongUrl | string | 原始长链接 |
| ShortKey | string | 短链接唯一键 |
| ViewHits | int | 访问次数 |
| ExpireTime | DateTime? | 过期时间,为空表示永不过期 |
| CreateTime | DateTime | 创建时间 |
| IsDeleted | bool | 是否已删除 |
配置
PlatformModuleStartup 会绑定 ShortUrlOption 并注册短链仓储:
{
"ShortUrlConnectionStrings": {
"MySql": "Data Source=localhost;Port=3306;User ID=root;Password=<password>;Initial Catalog=freekit_shorturl;Charset=utf8mb4;SslMode=none;"
},
"ShortUrlOption": {
"Salt": "ShortUrlApi",
"MinHashLength": 6,
"FileTableCount": 64
}
}
| 字段名 | 类型 | 描述 |
|---|---|---|
| Salt | string | Hashids 加盐值,生产环境应替换为随机字符串 |
| MinHashLength | int | 短链最小字符长度 |
| FileTableCount | int | 分表数量,默认 64 |