-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Xicheng Guo
committed
Jun 3, 2024
1 parent
0103e8f
commit 09957ff
Showing
4 changed files
with
211 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# 创建请求 | ||
|
||
## 创建请求对象 | ||
|
||
### Node/Web 环境 | ||
|
||
::: code-group | ||
|
||
```js [github] | ||
import axios from "axios"; | ||
import { createRequest } from "tiny-crud"; | ||
|
||
const GithubRequest = createRequest({ | ||
httpLib: "axios", | ||
httpClient: axios, | ||
accessToken: "Your Personal Access Token", | ||
|
||
platform: "github", | ||
owner: "Your Owner", | ||
repo: "Your Repo", | ||
}); | ||
``` | ||
|
||
```js [gitlab] | ||
import axios from "axios"; | ||
import { createRequest } from "tiny-crud"; | ||
|
||
const gitlabRequest = createRequest({ | ||
httpLib: "axios", | ||
httpClient: axios, | ||
accessToken: "Your Personal Access Token", | ||
|
||
platform: "gitlab", | ||
projectId: "Your Project ID", | ||
}); | ||
``` | ||
|
||
```js [gitee] | ||
import axios from "axios"; | ||
import { createRequest } from "tiny-crud"; | ||
|
||
const giteeRequest = createRequest({ | ||
httpLib: "axios", | ||
httpClient: axios, | ||
accessToken: "Your Personal Access Token", | ||
|
||
platform: "gitee", | ||
owner: "Your Owner", | ||
repo: "Your Repo", | ||
}); | ||
``` | ||
|
||
::: | ||
|
||
### 微信小程序环境 | ||
|
||
```javascript | ||
import { createRequest } from "tiny-crud"; | ||
|
||
const githubRequest = createRequest({ | ||
httpLib: "wx", | ||
httpClient: wx, | ||
accessToken: "Your Personal Access Token", | ||
|
||
platform: "github", | ||
owner: "Your Owner", | ||
repo: "Your Repo", | ||
}); | ||
``` | ||
|
||
## 设定 API 地址 | ||
|
||
默认情况下会使用官方的 API 地址,如果你需要将数据存储在私有的代码托管服务器上,可以使用 baseURL 字段指定 URL 地址: | ||
|
||
::: details TinyCRUD 中使用的官方 API 地址 | ||
|
||
| 平台 | API 地址 | | ||
| ------ | ------------------------ | | ||
| Github | `https://api.github.com` | | ||
| Gitlab | `https://gitlab.com` | | ||
| Gitee | `https://gitee.com` | | ||
|
||
::: | ||
|
||
```javascript{9} | ||
const githubRequest = createRequest({ | ||
httpLib: "axios", | ||
httpClient: axios, | ||
accessToken: "Your Personal Access Token", | ||
platform: "github", | ||
owner: "Your Owner", | ||
repo: "Your Repo", | ||
baseURL: "https://your-github-api.com", | ||
}); | ||
``` | ||
|
||
## 验证授权 | ||
|
||
通过 `authenticate` 方法验证个人访问令牌授权是否成功。 | ||
|
||
```javascript | ||
this.githubRequest.authenticate().then((res) => { | ||
console.log(res); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# 应用加密 | ||
|
||
当 useEncrypt 字段为 true 时,TinyCRUD 将会对数据进行加密,然后再存储到 Issue 中,当从 Issue 中读取数据时,TinyCRUD 将会对数据进行解密。 | ||
|
||
因此,当 useEncrypt 字段为 true 时,你必须实现加密函数 encryptFn 和解密函数 decryptFn,TinyCRUD 将会使用这两个函数对数据进行加解密。 | ||
|
||
例如使用 crypto-js 进行加解密,可以使用如下代码: | ||
|
||
```javascript{12} | ||
import CryptoJS from "crypto-js"; | ||
const githubRequest = createRequest({ | ||
httpLib: "axios", | ||
httpClient: axios, | ||
accessToken: "Your Personal Access Token", | ||
platform: "github", | ||
owner: "Your Owner", | ||
repo: "Your Repo", | ||
useEncrypt: true, | ||
encryptFn: (data: string) => { | ||
return CryptoJS.AES.encrypt(data, "Your Secret Key").toString(); | ||
}, | ||
decryptFn: (data: string) => { | ||
return CryptoJS.AES.decrypt(data, "Your Secret Key").toString( | ||
CryptoJS.enc.Utf8 | ||
); | ||
}, | ||
}); | ||
``` | ||
|
||
当 useEncrypt 字段为 false 时,加解密函数 encryptFn 和 decryptFn 将会被忽略。 | ||
|
||
因此,你可以根据不同的环境,选择使用加密或者不使用,例如: | ||
|
||
```javascript{10} | ||
const githubRequest = createRequest({ | ||
httpLib: "axios", | ||
httpClient: axios, | ||
accessToken: "Your Personal Access Token", | ||
platform: "github", | ||
owner: "Your Owner", | ||
repo: "Your Repo", | ||
useEncrypt: process.env.NODE_ENV === "production", | ||
encryptFn: (data: string) => { | ||
return CryptoJS.AES.encrypt(data, "Your Secret Key").toString(); | ||
}, | ||
decryptFn: (data: string) => { | ||
return CryptoJS.AES.decrypt(data, "Your Secret Key").toString( | ||
CryptoJS.enc.Utf8 | ||
); | ||
}, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# 准备工作 | ||
|
||
## 安装 TinyCRUD | ||
|
||
```bash | ||
npm install tiny-crud | ||
``` | ||
|
||
## 创建 Issue | ||
|
||
登入你的 Gitee/Github/Gitlab,选择一个合适的项目,创建一个 Issue,用于存放数据。 | ||
|
||
## 获取个人访问令牌 | ||
|
||
<table> | ||
<tr> | ||
<th>平台</th> | ||
<th></th> | ||
</tr> | ||
<tr> | ||
<td>Github</td> | ||
<td><a href="http://www.baidu.com/s?wd=Gitee个人访问令牌">如何取得个人访问令牌</a></td> | ||
</tr> | ||
<tr> | ||
<td>Gitlab</td> | ||
<td><a href="http://www.baidu.com/s?wd=Gitee个人访问令牌">如何取得个人访问令牌</a></td> | ||
</tr> | ||
<tr> | ||
<td>Gitee</td> | ||
<td><a href="http://www.baidu.com/s?wd=Gitee个人访问令牌">如何取得个人访问令牌</a></td> | ||
</tr> | ||
</table> |