Skip to content

Commit

Permalink
Merge pull request #102 from GuoXiCheng/dev-c
Browse files Browse the repository at this point in the history
update docs
  • Loading branch information
GuoXiCheng authored Jun 3, 2024
2 parents fe7a095 + 09957ff commit cbad786
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 1 deletion.
17 changes: 16 additions & 1 deletion docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,28 @@ export default {
{ text: "首页", link: "/" },
{ text: "指南", link: "/guide/intro/what-is-tinycrud" }
],
outline: {
level: "deep",
},
sidebar: {
"/guide/": [
{
text: "简介",
items: [{
text: "什么是 TinyCRUD",
link: "/intro/what-is-tinycrud"
link: "/guide/intro/what-is-tinycrud"
}]
}, {
text: "安装配置",
items: [{
text: "准备工作",
link: "/guide/install/prepare"
}, {
text: "创建请求",
link: "/guide/install/create-request"
}, {
text: "应用加密",
link: "/guide/install/encryption"
}]
}
]
Expand Down
106 changes: 106 additions & 0 deletions docs/guide/install/create-request.md
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);
});
```
57 changes: 57 additions & 0 deletions docs/guide/install/encryption.md
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
);
},
});
```
32 changes: 32 additions & 0 deletions docs/guide/install/prepare.md
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>

0 comments on commit cbad786

Please sign in to comment.