Skip to content

Commit 5ffdc55

Browse files
committed
添加github actions
1 parent 6566bd7 commit 5ffdc55

File tree

6 files changed

+51
-22
lines changed

6 files changed

+51
-22
lines changed

.github/workflows/40code.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Use Node.js 20.x
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 20.x
21+
cache: 'npm'
22+
- name: Install dependencies
23+
run: npm ci
24+
- name: Run 40code
25+
run: npm run 40code
26+
env:
27+
ZEROCAT_TOKEN_40CODE: ${{ secrets.ZEROCAT_TOKEN_40CODE }}
28+
ZEROCAT_BACKEND: ${{ vars.ZEROCAT_BACKEND }}

mirror.js renamed to 40code-mirror.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ dotenv.config();
2626

2727
// 配置
2828
const config = {
29-
token: process.env.token,
30-
apiHost: process.env.apihost,
29+
ZEROCAT_TOKEN_40CODE: process.env.ZEROCAT_TOKEN_40CODE,
30+
apiHost: process.env.ZEROCAT_BACKEND,
3131
username: '40code',
3232
targetExtensions: [
3333
],
@@ -42,7 +42,7 @@ const config = {
4242
const api = axios.create({
4343
baseURL: config.apiHost,
4444
headers: {
45-
'Authorization': `Bearer ${config.token}`,
45+
'Authorization': `Bearer ${config.ZEROCAT_TOKEN_40CODE}`,
4646
'Content-Type': 'application/json'
4747
}
4848
});
@@ -309,8 +309,8 @@ async function syncExtension(extId, name,ext) {
309309
async function main() {
310310
try {
311311
// 验证配置
312-
if (!config.token || !config.apiHost) {
313-
log('错误: 请设置环境变量 tokenapihost', 'error');
312+
if (!config.ZEROCAT_TOKEN_40CODE || !config.apiHost) {
313+
log('错误: 请设置环境变量 ZEROCAT_TOKEN_40CODEZEROCAT_BACKEND', 'error');
314314
process.exit(1);
315315
}
316316

CONFIG.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
## 环境变量
44

5-
### token
5+
### ZEROCAT_TOKEN_40CODE
66
- **类型**: 字符串
77
- **必需**: 是
88
- **说明**: API访问令牌,用于认证API请求
9-
- **示例**: `your_api_token_here`
9+
- **示例**: `your_api_ZEROCAT_TOKEN_40CODE_here`
1010

11-
### apihost
11+
### ZEROCAT_BACKEND
1212
- **类型**: 字符串
1313
- **必需**: 是
1414
- **说明**: API服务器的基础URL
@@ -19,8 +19,8 @@
1919
创建 `.env` 文件:
2020
```env
2121
# API配置
22-
token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
23-
apihost=https://api.zerocat.com
22+
ZEROCAT_TOKEN_40CODE=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
23+
ZEROCAT_BACKEND=https://api.zerocat.com
2424
```
2525

2626
## API接口说明
@@ -31,13 +31,13 @@ apihost=https://api.zerocat.com
3131
- **返回**: 扩展列表数组
3232

3333
### 检查项目是否存在
34-
- **URL**: `{apihost}/namespace/{username}/{extId}`
34+
- **URL**: `{ZEROCAT_BACKEND}/namespace/{username}/{extId}`
3535
- **方法**: GET
3636
- **认证**: Bearer Token
3737
- **返回**: 项目信息或404
3838

3939
### 创建项目
40-
- **URL**: `{apihost}/project`
40+
- **URL**: `{ZEROCAT_BACKEND}/project`
4141
- **方法**: POST
4242
- **认证**: Bearer Token
4343
- **参数**:
@@ -48,27 +48,27 @@ apihost=https://api.zerocat.com
4848
- `state`: 项目状态(public/private)
4949

5050
### 初始化项目
51-
- **URL**: `{apihost}/project/initlize?projectid={projectId}&type=text`
51+
- **URL**: `{ZEROCAT_BACKEND}/project/initlize?projectid={projectId}&type=text`
5252
- **方法**: POST
5353
- **认证**: Bearer Token
5454
- **说明**: 初始化项目,创建默认分支和初始提交
5555

5656
### 保存文件
57-
- **URL**: `{apihost}/project/savefile?json=true`
57+
- **URL**: `{ZEROCAT_BACKEND}/project/savefile?json=true`
5858
- **方法**: POST
5959
- **认证**: Bearer Token
6060
- **参数**:
6161
- `source`: 文件内容
6262
- **返回**: `{ sha256, accessFileToken }`
6363

6464
### 获取项目提交
65-
- **URL**: `{apihost}/project/{projectId}/commits`
65+
- **URL**: `{ZEROCAT_BACKEND}/project/{projectId}/commits`
6666
- **方法**: GET
6767
- **认证**: Bearer Token
6868
- **返回**: 提交列表
6969

7070
### 创建提交
71-
- **URL**: `{apihost}/project/commit/id/{projectId}`
71+
- **URL**: `{ZEROCAT_BACKEND}/project/commit/id/{projectId}`
7272
- **方法**: PUT
7373
- **认证**: Bearer Token
7474
- **参数**:
@@ -106,7 +106,7 @@ const targetExtensions = [
106106
程序包含以下错误处理机制:
107107

108108
1. **网络错误**: 自动重试和跳过
109-
2. **认证错误**: 检查token有效性
109+
2. **认证错误**: 检查ZEROCAT_TOKEN_40CODE有效性
110110
3. **API错误**: 记录详细错误信息
111111
4. **文件错误**: 跳过无法获取的扩展
112112

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ cp env.example .env
3434

3535
2. 编辑 `.env` 文件,设置你的配置:
3636
```env
37-
token=your_api_token_here
38-
apihost=https://your-api-host.com
37+
ZEROCAT_TOKEN_40CODE=your_api_ZEROCAT_TOKEN_40CODE_here
38+
ZEROCAT_BACKEND=https://your-api-host.com
3939
```
4040

4141
## 使用方法

env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# API配置
2-
token=your_api_token_here
3-
apihost=https://your-api-host.com
2+
ZEROCAT_TOKEN_40CODE=your_api_ZEROCAT_TOKEN_40CODE_here
3+
ZEROCAT_BACKEND=https://your-api-host.com

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"description": "Extension mirror tool for ZeroCat",
66
"main": "mirror.js",
77
"scripts": {
8-
"start": "node mirror.js"
8+
"start": "node 40code-mirror.js",
9+
"40code": "node 40code-mirror.js"
910
},
1011
"dependencies": {
1112
"axios": "^1.9.0",

0 commit comments

Comments
 (0)