Skip to content

Commit

Permalink
修复示例代码的一些细节并添加 withHandlerClass 方法示例 (#60)
Browse files Browse the repository at this point in the history
Co-authored-by: undefined <[email protected]>
  • Loading branch information
Molmin and undefined-moe authored Apr 3, 2024
1 parent 1661811 commit fb393ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 17 additions & 0 deletions dev/hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,26 @@ export async function apply(ctx: Context) {
// RecordDetail 为需要捕获的路由名
// #get 表示仅捕获 GET 请求,若无此后缀表示捕获该路由的所有请求
ctx.on('handler/after/RecordDetail#get', (h) => { // handler 系列钩子的一参数为对应的 Handler 实例
// 不允许查看 24 小时以前的提交记录
if (h.rdoc._id.getTimestamp() < new Date(Date.now() - Time.day)) {
h.rdoc.code = '';
}
});
}
```

```ts
import { Context } from 'hydrooj';

async function getAnnounce(domainId: string, limit = 5) {
// 获取公告...
return adocs;
}

export async function apply(ctx: Context) {
ctx.withHandlerClass('HomeHandler', (HomeHandler) => {
// 修改 HomeHandler 中的一个方法(添加公告)
HomeHandler.prototype.getAnnounce = getAnnounce;
});
}
```
5 changes: 2 additions & 3 deletions docs/user/problem-create.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,14 @@ int main(int argc, char* argv[]) {
rnd.setSeed(time(NULL));
int a = rnd.next(1000);
int b = rnd.next(1000);
int d = a+b;
// 本程序的输出将作为用户程序的输入
cout << a << " " << b << endl;
int c;
// 用户程序的最后输出将作为本程序的输入
cin >> c;
//对比用户结果和预期结果
if (a+b != ans)
quitf(_wa, "%d + %d expected %d, found %d", a, b,d,c); //输出错误的具体信息,便于做题者调试
if (a+b != c)
quitf(_wa, "%d + %d expected %d, found %d", a, b, a+b, c); //输出错误的具体信息,便于做题者调试
else
quitf(_ok, "answer of %d + %d is %d",a,b,c);
}
Expand Down

0 comments on commit fb393ae

Please sign in to comment.