Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update docs #103

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 63 additions & 29 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,84 @@
// .vitepress/config.js
export default {
// 站点级选项
title: 'TinyCRUD Docs',
title: 'TinyCRUD',
description: 'Just playing around.',
base: "/",
locales: {
root: {
label: '简体中文',
lang: '/'
lang: '/',
themeConfig: {
nav: [
{ text: "首页", link: "/" },
{ text: "指南", link: "/guide/intro/what-is-tinycrud" }
],
sidebar: {
"/guide/": [
{
text: "简介",
items: [{
text: "什么是 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"
}]
}
]
}
}
},
en: {
label: 'English',
lang: 'en',
themeConfig: {
nav: [
{ text: "Home", link: "/en/" },
{ text: "Guide", link: "/en/guide/intro/what-is-tinycrud" }
],
sidebar: {
"/en/guide/": [
{
text: "Introduction",
items: [{
text: "What is TinyCRUD",
link: "/en/guide/intro/what-is-tinycrud"
}]
}, {
text: "Installation",
items: [{
text: "Prepare",
link: "/en/guide/install/prepare"
}, {
text: "Create Request",
link: "/en/guide/install/create-request"
}, {
text: "Encryption",
link: "/en/guide/install/encryption"
}]
}
]
}

}
}
},

themeConfig: {
nav: [
{ text: "首页", link: "/" },
{ text: "指南", link: "/guide/intro/what-is-tinycrud" }
],

outline: {
level: "deep",
},
sidebar: {
"/guide/": [
{
text: "简介",
items: [{
text: "什么是 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"
}]
}
]
}

}
}
106 changes: 106 additions & 0 deletions docs/en/guide/install/create-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Creating Requests

## Create Request Object

### For Node/Web Environments

::: 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",
});
```

:::

### For WeChat Mini Program Environment

```js
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",
});
```

## Set API URL

By default, the official API URLs are used. If you need to store data on a private code hosting server, you can specify the URL using the baseURL field:

::: details Official API URLs used in TinyCRUD

| Platform | API URL |
| -------- | ------------------------ |
| 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

Verify if the personal access token authorization is successful using the authenticate method.

```js
this.GithubRequest.authenticate().then((res) => {
console.log(res);
});
```
57 changes: 57 additions & 0 deletions docs/en/guide/install/encryption.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Applying Encryption

When the `useEncrypt` field is set to `true`, TinyCRUD will encrypt the data before storing it in an Issue and decrypt it when reading from the Issue.

Therefore, when `useEncrypt` is `true`, you must implement the encryption function `encryptFn` and the decryption function `decryptFn`. TinyCRUD will use these two functions to encrypt and decrypt the data.

For example, to encrypt and decrypt using `crypto-js`, you can use the following code:

```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
);
},
});
```

When useEncrypt is set to false, the encryption and decryption functions encryptFn and decryptFn will be ignored.

Therefore, you can choose to use encryption or not based on the environment, for example:

```js
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/en/guide/install/prepare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Preparation

## Install TinyCRUD

```bash
npm install tiny-crud
```

## Create Issue

Log into your Gitee/Github/Gitlab account, select an appropriate project, and create an issue to store data.

## Obtain a Personal Access Token

<table>
<tr>
<th>Platform</th>
<th></th>
</tr>
<tr>
<td>Github</td>
<td><a href="https://www.google.com/search?q=Gitlab+Person+Access+Token">How to Get Personal Access Token</a></td>
</tr>
<tr>
<td>Gitlab</td>
<td><a href="https://www.google.com/search?q=Github+Person+Access+Token">How to Get Personal Access Token</a></td>
</tr>
<tr>
<td>Gitee</td>
<td><a href="https://www.google.com/search?q=Gitee+Person+Access+Token">How to Get Personal Access Token</a></td>
</tr>
</table>
14 changes: 14 additions & 0 deletions docs/en/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
layout: home

hero:
name: TinyCRUD
text: Lightweight Data Repository Based on Git Issue API
actions:
- theme: brand
text: Get Started
link: /en/guide/intro/what-is-tinycrud
- theme: alt
text: View on GitHub
link: https://github.com/GuoXiCheng/TinyCRUD
---
14 changes: 14 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
layout: home

hero:
name: TinyCRUD
text: 基于 Issue API 的轻量级数据存储库
actions:
- theme: brand
text: Get Started
link: /guide/intro/what-is-tinycrud
- theme: alt
text: View on GitHub
link: https://github.com/GuoXiCheng/TinyCRUD
---
Loading