Chhoto URL CLI完全指南:用命令行管理短链接的10个实用技巧
Chhoto URL CLI完全指南:用命令行管理短链接的10个实用技巧
【免费下载链接】chhoto-urlA simple, blazingly fast, selfhosted URL shortener with no unnecessary features; written in Rust.项目地址: https://gitcode.com/gh_mirrors/ch/chhoto-url
Chhoto URL是一款简单、极速且自托管的短链接工具,采用Rust编写,无冗余功能。本文将详细介绍如何通过命令行高效管理短链接,从基础安装到高级操作,助你轻松掌握10个实用技巧。
1. 快速获取项目与基础配置
首先,通过以下命令克隆项目仓库:
git clone https://gitcode.com/gh_mirrors/ch/chhoto-url进入项目目录后,可通过curl命令快速获取服务器版本和站点URL,无需认证:
# 查看版本 curl http://localhost:4567/api/version # 查看站点URL curl http://localhost:4567/api/siteurl2. 生成安全的API密钥
API密钥是CLI操作的核心凭证。在Linux系统中,可通过以下命令生成高强度密钥:
tr -dc A-Za-z0-9 < /dev/urandom | head -c 128将生成的密钥设置为环境变量CHHOTO_API_KEY,确保后续操作权限。
3. 一键创建短链接
使用/api/new接口创建短链接,支持自定义短码、过期时间和备注:
curl -X POST \ -H "X-API-Key: <YOUR_API_KEY>" \ -d '{ "shortlink": "my-link", "longlink": "https://example.com", "expiry_delay": 86400, "notes": "测试链接" }' \ http://localhost:4567/api/new若省略shortlink,系统将自动生成随机短码。
4. 批量创建短链接
通过发送JSON数组实现批量创建,一次请求可添加多个链接:
curl -X POST \ -H "X-API-Key: <YOUR_API_KEY>" \ -d '[ {"shortlink": "link1", "longlink": "https://url1.com"}, {"shortlink": "link2", "longlink": "https://url2.com"} ]' \ http://localhost:4567/api/new5. 查看短链接详情
使用/api/expand接口查询短链接的目标地址、访问量和过期时间:
curl -H "X-API-Key: <YOUR_API_KEY>" \ -d "my-link" http://localhost:4567/api/expand返回结果包含longurl(原始链接)、hits(访问次数)等关键信息。
6. 分页获取所有链接
通过/api/all接口配合分页参数,高效管理大量短链接:
# 获取第1页,每页10条 curl -H "X-API-Key: <YOUR_API_KEY>" \ http://localhost:4567/api/all?page_size=10&page_no=1 # 按短码过滤 curl -H "X-API-Key: <YOUR_API_KEY>" \ http://localhost:4567/api/all?filter=my-link7. 编辑现有短链接
使用/api/edit接口更新短链接的目标地址、过期时间或备注:
curl -X PUT \ -H "X-API-Key: <YOUR_API_KEY>" \ -d '{ "shortlink": "my-link", "longlink": "https://new-example.com", "reset_hits": true }' \ http://localhost:4567/api/edit8. 删除无用短链接
通过/api/del/{shortlink}接口删除指定短链接:
curl -X DELETE \ -H "X-API-Key: <YOUR_API_KEY>" \ http://localhost:4567/api/del/my-link9. 使用Cookie认证(替代API密钥)
若未设置API密钥,可通过Cookie进行认证:
# 登录并保存Cookie curl -X POST -d "your-password" -c cookie.txt http://localhost:4567/api/login # 使用Cookie执行操作 curl -b cookie.txt http://localhost:4567/api/all10. 获取服务器配置信息
通过/api/getconfig接口查看系统参数,如允许大写字母、短码长度等:
curl -H "X-API-Key: <YOUR_API_KEY>" \ http://localhost:4567/api/getconfig注意事项
- API响应中
shorturl与shortlink、longurl与longlink可能混用,需注意字段一致性。 - 公共模式下无需认证,但存在安全风险,建议生产环境启用密码保护。
- 所有CLI操作细节可参考官方文档:docs/CLI.md
通过以上10个技巧,你可以充分发挥Chhoto URL的CLI功能,高效管理短链接。无论是个人使用还是团队协作,命令行操作都能为你带来极速、灵活的体验! 🚀
【免费下载链接】chhoto-urlA simple, blazingly fast, selfhosted URL shortener with no unnecessary features; written in Rust.项目地址: https://gitcode.com/gh_mirrors/ch/chhoto-url
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
