This repository has been archived on 2026-08-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
RequestCounter/docs/README.md
T

178 lines
3.7 KiB
Markdown
Raw Normal View History

2022-02-08 19:46:11 +08:00
# 这里是Request Counter的文档
2022-04-09 10:36:36 +08:00
2022-02-08 19:46:11 +08:00
> 虽然说项目很小根本不需要文档
# 灵感来源
2022-04-09 10:36:36 +08:00
2022-02-11 18:25:34 +08:00
[Moe-Counter](https://github.com/journey-ad/Moe-counter)
2022-02-08 19:46:11 +08:00
# 工作原理
2022-04-09 10:36:36 +08:00
2022-02-08 19:46:11 +08:00
使用Flask建立服务器接收请求分析获取到的数据写入数据库
# 部署
2022-04-09 10:36:36 +08:00
2022-02-19 11:48:24 +08:00
> 在部署之前你需要先安装`python3.10.x`以上的版本
2022-04-09 10:36:36 +08:00
2022-02-08 19:46:11 +08:00
## 部署到本地服务器
2022-04-09 10:36:36 +08:00
2022-02-08 19:46:11 +08:00
```shell
$ git clone https://github.com/MarkusJoe/RequestCounter.git
$ cd RequestCounter
$ pip3 install -r requirements.txt
$ python3 app.py
```
# 基本信息
2022-04-09 10:36:36 +08:00
2022-02-09 23:43:58 +08:00
- Python版本: `3.10.x`
2022-02-08 19:46:11 +08:00
- 请求方法: `GET` `POST`
2022-04-09 11:11:41 +08:00
- 请求地址: `/count/<string:name>`
2022-03-26 08:02:25 +08:00
- 你需要在 请求地址末尾加入你需要使用的名称来进行计数
2022-02-28 21:20:02 +08:00
- 可选参数: `theme` `length`
2022-04-09 10:36:36 +08:00
# API
2022-04-10 14:31:24 +08:00
* 注意事项
1. `/api/v1/`内的所有接口都是需要`key`来访问
2. `key`是从环境变量中获取或自动生成, 这取决与你部署到`Heroku`时是否设置了`ACCESS_KEY`环境变量
3. `key`的长度为`32`位的随机英文字母大小写字符串
2022-04-09 10:36:36 +08:00
2022-04-09 21:09:07 +08:00
> 地址前缀: `/api/v1/`
2022-04-09 10:36:36 +08:00
- 接口地址: `/overall/`, `/query/`, `/theme/`
- 请求方法: `GET` `POST`
## `/overall/` 接口
2022-04-10 14:31:24 +08:00
> 使用此接口获取数据库中所有的数据
2022-04-09 10:36:36 +08:00
> 必选参数: `limit: int` > 自定义查询数量, 输入的数字大于等于最大值时, 将返回最大值
### 调用示例
```shell
2022-04-10 14:31:24 +08:00
$ curl -L -X GET https://requestcounter.herokuapp.com/api/v1/overall/?limit=20&key=<key>
2022-04-09 10:36:36 +08:00
```
```json
{
"code": 200,
"msg": "Success. Total: 7 row(s)",
"data": [
{
"name": "sda",
"times": 72
},
{
"name": "main",
"times": 59
}
]
}
```
## `/query/` 接口
2022-02-19 11:48:24 +08:00
2022-04-09 10:36:36 +08:00
> 使用此接口获取数据库中指定的数据
2022-02-19 11:48:24 +08:00
2022-04-09 10:36:36 +08:00
***使用此接口查询的名称计数数值会加一***
2022-02-09 16:43:55 +08:00
2022-04-10 14:31:24 +08:00
> 必选参数: `name: str` > 查询指定名称的计数数据
2022-04-09 10:36:36 +08:00
> 可选参数: `nochange: Any`
2022-04-10 14:31:24 +08:00
2022-04-09 10:36:36 +08:00
> `nochange`: 'Any` > 将参数值设置为任意值则仅查询不增加
### 调用示例
```shell
2022-04-10 14:31:24 +08:00
$ curl -L -X GET https://requestcounter.herokuapp.com/api/v1/query/?name=main&nochange=1&key=<key>
2022-04-09 10:36:36 +08:00
```
```json
{
"code": 200,
"msg": "Success",
"data": [
"main",
59
]
}
```
## `/theme/` 接口
> 使用此接口获取数据库内原始的base64编码的主题图片
2022-04-10 14:31:24 +08:00
2022-04-09 10:36:36 +08:00
> 必选参数: `theme: str`
### 调用示例
```shell
2022-04-10 14:31:24 +08:00
$ curl -L -X GET https://requestcounter.herokuapp.com/api/v1/theme/?name=lewd&key=<key>
2022-04-09 10:36:36 +08:00
```
```json
{
"code": 200,
"msg": "Success",
"data": [
{
"index": "0",
"base64": "...",
"width": 45,
"height": 100
},
...
]
}
```
## `/alltables/` 接口
2022-04-10 14:31:24 +08:00
> 此接口可以获取数据库内所有的表名 > 返回的数据中不包含`ReqCount`
2022-04-09 10:36:36 +08:00
> 无参数
```shell
2022-04-10 14:31:24 +08:00
$ curl -L -X GET https://requestcounter.herokuapp.com/api/v1/alltables/&key=<key>
2022-04-09 10:36:36 +08:00
```
```json
{
"code": 200,
"msg": "Success",
"data": [
...
]
}
```
2022-02-08 19:46:11 +08:00
2022-04-10 14:31:24 +08:00
## `/export/` 接口
> 此接口可以导出应用的数据库文件
> 无参数
```shell
$ curl -L -X GET https://requestcounter.herokuapp.com/api/v1/export/&key=<key>
```
> 该接口请求成功后返回文件
2022-02-08 19:46:11 +08:00
# 关于
2022-04-09 10:36:36 +08:00
2022-02-08 19:46:11 +08:00
## 开源
2022-04-09 10:36:36 +08:00
2022-02-08 19:46:11 +08:00
- 本项目以Apache-2.0许可开源, 即:
2022-04-09 10:36:36 +08:00
- 你可以直接使用该项目提供的功能, 无需任何授权
- 你可以在**注明来源版权信息**的情况下对源代码进行任意分发和修改以及衍生
2022-02-08 19:46:11 +08:00
## 关于此页面
2022-04-09 10:36:36 +08:00
此文档由 [docsify](https://github.com/docsifyjs/docsify) 生成. docsify 是一个动态生成文档网站的工具。不同于 GitBook、Hexo 的地方是它不会生成将 .md 转成 .html
文件,所有转换工作都是在运行时进行。
2022-02-08 19:46:11 +08:00