短连接生成系统开源 NestJS + React

短连接生成系统开源

https://github.com/ygweric/short-url

Powered by NestJS + React

后端 short-url-server

技术栈

NestJs + TypeScript + TypeORM + Sqlite

Run it

npm i
npm start

will run server in open http://localhost:3000/

Test

npm run test
npm run test:cov

测试覆盖率

--------------------|---------|----------|---------|---------|-------------------
File                | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
--------------------|---------|----------|---------|---------|-------------------
All files           |   96.25 |    78.57 |     100 |   95.52 |                   
 common             |     100 |      100 |     100 |     100 |                   
  config.ts         |     100 |      100 |     100 |     100 |                   
  errorCode.ts      |     100 |      100 |     100 |     100 |                   
  stringUtil.ts     |     100 |      100 |     100 |     100 |                   
 controllers        |      96 |    83.33 |     100 |   94.74 |                   
  app.controller.ts |      96 |    83.33 |     100 |   94.74 | 16                
 entities           |     100 |      100 |     100 |     100 |                   
  url.ts            |     100 |      100 |     100 |     100 |                   
 services           |    93.1 |    66.67 |     100 |   91.67 |                   
  app.service.ts    |    93.1 |    66.67 |     100 |   91.67 | 14,32             
--------------------|---------|----------|---------|---------|-------------------

短连接生成机制

采用数据库sum自增的方式, 将sum总数转变为62进制的字符串

对于不超过8位的短链接,最多可以存放 62^8 ≈ 218,340,105,584,896 个链接

数据库

export class Url {
	@PrimaryColumn('varchar', { nullable: false })
	public shortUrl: string;

	@Column("text", { nullable: false})
	public longUrl: string;
}

结构框架

── src
│   ├── app.module.ts
│   ├── common 通用模块
│   │   ├── __tests__
│   │   │   └── stringUtil.spec.ts
│   │   ├── config.ts
│   │   ├── errorCode.ts
│   │   └── stringUtil.ts
│   ├── controllers 路由
│   │   ├── __tests__
│   │   │   └── app.controller.spec.ts
│   │   └── app.controller.ts
│   ├── entities ORM实例
│   │   └── url.ts
│   ├── index.ts
│   ├── main.ts
│   ├── middlewares
│   ├── migration
│   └── services 服务层,负责entity和controller的通信
│       ├── __tests__
│       │   └── app.service.spec.ts
│       └── app.service.ts

TODO

  • 在10进制到62进制的转换中, 对于32位的系统, js会出现溢出,需用BigNumber来操作
  • 增加输入合法性的验证

前端 short-url-web

技术栈

React + TypeScript + Axios + AntD

TODO

  • 本来想配置less的,报错了, 先发一版再说,回头改

Run it

npm i
npm start

open http://localhost:8080/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值