跳到主要内容

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}

具体路由以 ShortUrlControllerShortUrlEndpoint 为准。

实体

ShortUrl

字段名类型描述
Idlong主键,由雪花 ID 生成
LongUrlstring原始长链接
ShortKeystring短链接唯一键
ViewHitsint访问次数
ExpireTimeDateTime?过期时间,为空表示永不过期
CreateTimeDateTime创建时间
IsDeletedbool是否已删除

配置

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
}
}
字段名类型描述
SaltstringHashids 加盐值,生产环境应替换为随机字符串
MinHashLengthint短链最小字符长度
FileTableCountint分表数量,默认 64