Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit e12c293

Browse files
committed
2.6
api
1 parent 410d91d commit e12c293

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@
4040
</a>
4141
```
4242

43+
### API
44+
/api/user/*username*/
45+
/api/repo/*username*/*repo*/
46+
4347
### 🍎 Build Your Own Server | 搭建自己的服务器
4448
#### 🍒 Initialization | 初始化
4549
```shell
46-
npm install
50+
pnpm install
4751
```
4852

4953
#### 🍬 Configuration | 配置

docs/screenshot.png

186 KB
Loading

server.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ export function createServer(): void {
3737
}
3838
});
3939

40+
app.get('/api/user/:user/', async function (req: any, res: any) {
41+
const username: string = req.params['user'];
42+
43+
try {
44+
if (! await isAuthenticated(username)) {
45+
res.send({'status': false});
46+
} else {
47+
const resp = await analyseUser(username);
48+
resp['status'] = true;
49+
res.send(resp);
50+
}
51+
} catch {
52+
res.send({'status': false});
53+
}
54+
})
55+
4056
app.get('/repo/:user/:repo/', async function (req: any, res: any) {
4157
res.type('svg');
4258

@@ -57,6 +73,23 @@ export function createServer(): void {
5773
}
5874
});
5975

76+
app.get('/api/repo/:user/:repo/', async function (req: any, res: any) {
77+
const username = req.params['user'],
78+
repo = req.params['repo'];
79+
80+
try {
81+
if (! await isExistRepo(username, repo)) {
82+
res.send({'status': false});
83+
} else {
84+
const resp = await analyseRepo(username, repo);
85+
resp['status'] = true;
86+
res.send(resp);
87+
}
88+
} catch {
89+
res.send({'status': false});
90+
}
91+
});
92+
6093
app.listen(port, () =>
6194
logger.info(`Starting deployment server at http://127.0.0.1:${port}/.`));
6295
}

0 commit comments

Comments
 (0)