doc: add README and README_CN

This commit is contained in:
gazedreamily 2023-04-17 15:28:37 +08:00
parent abb638a54f
commit a06b071bf2
2 changed files with 196 additions and 1 deletions

View File

@ -1,2 +1,99 @@
# short_url # short_url
url shortten server with python and mysql ![maven](https://img.shields.io/badge/python-3.8%2B-blue)
![maven](https://img.shields.io/badge/tornado-6.2-green)
![maven](https://img.shields.io/badge/aiomysql-0.1.1-orange)
An asynchronous short link backend written in Python based on Tornado and aiomysql
[简体中文](./README_CN.md) | English
## Run
### Clone code and enter the dir
```shell
git clone https://github.com/gazedreamily/short_url.git
cd short_url
```
### Connect to your mysql database
```shell
mysql -u [your mysql username] -p
```
### Create table
```sql
use [database name]
source [project dir]/surl.sql;
```
### Change configuration file
default content of configuration file
```yaml
database: # configuration of database
host: # servername of database server
port: # port of database server
user: # username of database server
password: # password of database server
database: # name of database on database server
sign: # configuration of authentication
secret: # secret when adding new url
server: # configuration of web server
host: # servername of web server
port: # port of web server
protocol: # protocol of web serverhttp、https
ssl: # https(TODO)
cert:
key:
```
fill in the configuration file according to your own situation before running
### Install the operating environment
Linux
```shell
pip3 install -r requirements.txt
```
Windows
```shell
pip install -r requirements.txt
```
### just run it!
Linux
```shell
python3 main.py
```
Windows
```shell
python main.py
```
## Usage
### Visit
Use this server configuration like this
```yaml
server:
host: a.com
port: 80
protocol: http
```
The domain name in the database is recorded as
| id | source | target | createTime | expireTime |
|-----|---------|---------------------|--------------| -----------|
| 1 | AbcdEfg | https://google.com/ | | |
When accessing `http://a.com/AbcdEfg` , the target will be redirected to `https://google.com/`.
The server will return `404` if there is no source record in the database.
### ExpireTime
When accessing a link, the backend will judge whether the current link has expired. If the link expires, it will delete the link from the database and return `404`
### Insert a link
You can use `client.py` to do it.
When inserting a link, the post carries target_url, current timestamp, signature based on timestamp and secret key, and expiration time (optional).

98
README_CN.md Normal file
View File

@ -0,0 +1,98 @@
# short_url
![maven](https://img.shields.io/badge/python-3.8%2B-blue)
![maven](https://img.shields.io/badge/tornado-6.2-green)
![maven](https://img.shields.io/badge/aiomysql-0.1.1-orange)
基于Tornado与aiomysql使用Python语言编写的异步短链接后端
简体中文 | [English](./README.md)
## 运行
### 拉取代码进入目录
```shell
git clone https://github.com/gazedreamily/short_url.git
cd short_url
```
### 连入数据库
```shell
mysql -u 你的mysql用户 -p
```
### 创建数据表
```sql
use 数据库名
source 项目路径/surl.sql;
```
### 更改配置文件
默认配置文件内容
```yaml
database: # 此部分为数据库相关配置
host: # 数据库主机名(域名)
port: # 数据库端口号
user: # 数据库用户名
password: # 数据库密码
database: # 数据库名
sign: # 验证相关
secret: # 新增短链接时的验证秘钥
server: # 服务器相关
host: # 服务器主机名(域名)
port: # 服务端口号
protocol: # 服务器链接协议http、https
ssl: # https证书相关TODO
cert:
key:
```
运行前请将以上信息根据个人情况填写
### 安装相关库
Linux
```shell
pip3 install -r requirements.txt
```
Windows
```shell
pip install -r requirements.txt
```
### 运行项目
Linux
```shell
python3 main.py
```
Windows
```shell
python main.py
```
## 使用
### 访问
以此server配置为模板
```yaml
server:
host: a.com
port: 80
protocol: http
```
数据库中域名记录为
| id | source | target | createTime | expireTime |
|-----|---------|---------------------|--------------| -----------|
| 1 | AbcdEfg | https://google.com/ | | |
访问 `http://a.com/AbcdEfg` 时,浏览器会被重定向到 `https://google.com/`
若访问的路径没有对应的目标网址则会返回404
### 有效时间
当访问链接时后端会判断当前链接是否过期若链接过期则会从数据库中删除该链接并返回404
### 插入链接
可以使用 `client.py` 插入链接
在插入链接时post中携带target_url当前时间戳基于时间戳和秘钥的签名以及过期时间可选