Skip to content

Commit 31f1a17

Browse files
author
robot
committed
feat: daily check
1 parent b19b425 commit 31f1a17

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

routes/github.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
const router = require("koa-router")();
22
const fetch = require("node-fetch");
3+
const fs = require("fs");
4+
const path = require("path");
5+
const process = require("child_process");
36

47
const { getDay } = require("../utils/day");
58
const { success, fail } = require("../utils/request");
9+
const mySolutions = require("../static/my/solutions.json");
610
const solutions = require("../static/solution/solutions.json");
7-
// const mySolutions = require("../database");
811

912
router.all("/api/v1/github/content", async (ctx) => {
1013
const { url, ...params } = ctx.query;
@@ -30,13 +33,30 @@ router.all("/api/v1/github/content", async (ctx) => {
3033

3134
router.all("/api/v1/github/webhook", async (ctx) => {
3235
const { action, comment, issue } = ctx.request.body;
33-
if (issue.number === solutions[getDay() - 1].issue_number) {
36+
37+
if (issue.number !== solutions[getDay()].issue_number) {
3438
ctx.body = success("只处理当天的打卡信息");
3539
return;
3640
}
3741
if (action === "created" && comment.body.length > 20) {
38-
ctx.body = success("收到!");
42+
mySolutions[comment.user.login][getDay() - 1] = {
43+
// title: problem.title,
44+
url: comment.html_url,
45+
body: comment.body,
46+
};
47+
48+
fs.writeFileSync(
49+
path.resolve(__dirname, "../static/my/solutions.json"),
50+
JSON.stringify(mySolutions)
51+
);
52+
53+
process.exec(
54+
"sh " + path.resolve(__dirname, "../scripts/commit.sh"),
55+
console.log
56+
);
3957
}
58+
59+
ctx.body = success(mySolutions[comment.user.login]);
4060
});
4161

4262
module.exports = router;

0 commit comments

Comments
 (0)