Skip to content

Commit d8cf6c3

Browse files
committed
bug fixes
1 parent 866ff27 commit d8cf6c3

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

build.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,21 @@ const nopMap = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIj
3333
entryPoints: [path.resolve(process.cwd(), 'packages/server/index.ts')],
3434
charset: 'utf8',
3535
sourcemap: process.argv.includes('--debug') ? 'inline' : false,
36+
metafile: true,
3637
plugins: [{
3738
name: 'base16384',
3839
setup(b) {
3940
b.onLoad({ filter: /\.(frontend|ttf|wasm)$/, namespace: 'file' }, (t) => {
4041
const file = fs.readFileSync(path.join(t.path));
41-
const contents = `module.exports = "${encodeBinary(file)}";\n${nopMap}`;
42+
const contents = `module.exports = "${process.argv.includes('--no-binary') ? '' : encodeBinary(file)}";\n${nopMap}`;
4243
console.log(t.path, size(contents));
4344
return {
4445
contents,
4546
loader: 'tsx',
4647
};
4748
});
48-
b.onLoad({ filter: /node_modules\/.+\.js$/ }, (t) => ({
49-
contents: `${fs.readFileSync(t.path, 'utf8')}\n${nopMap}`,
49+
b.onLoad({ filter: /node_modules.*\.[jt]sx?$/ }, async (t) => ({
50+
contents: `${await fs.readFile(t.path, 'utf-8')}\n${nopMap}`,
5051
loader: 'default',
5152
}));
5253
},
@@ -60,6 +61,7 @@ const nopMap = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIj
6061
if (res.warnings.length) console.warn(res.warnings);
6162
logger.info(`Resource Size: ${size(res.outputFiles[0].text)}`);
6263
fs.writeFileSync(path.resolve(process.cwd(), 'dist/xcpc-tools.js'), res.outputFiles[0].text);
64+
fs.writeFileSync(path.resolve(process.cwd(), 'dist/metafile.json'), JSON.stringify(res.metafile));
6365
logger.info('Saved to dist/xcpc-tools.js');
6466
if (!process.env.SEA) return;
6567
fs.writeFileSync(path.resolve(process.cwd(), 'dist/sea-config.json'), JSON.stringify({

packages/server/service/fetcher.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class BasicFetcher extends Service implements IBasicFetcher {
4444
}
4545

4646
[Service.init]() {
47-
this.ctx.interval(() => this.cron().catch(this.logger.error), 20000);
47+
this.ctx.interval(() => this.cron().catch(this.logger.error), 10000);
4848
}
4949

5050
async cron() {
@@ -204,22 +204,21 @@ class HydroFetcher extends BasicFetcher {
204204
async balloonInfo(all) {
205205
if (all) this.logger.info('Sync all balloons...');
206206
const { body } = await fetch(`/d/${this.contest.domainId}/contest/${this.contest.id}/balloon?todo=${all ? 'false' : 'true'}`);
207-
if (!body || !body.length) return;
208-
const balloons = body;
209-
for (const balloon of balloons) {
210-
const teamTotal = await this.ctx.db.balloon.find({ teamid: balloon.teamid, time: { $lt: (balloon.time * 1000).toFixed(0) } });
207+
if (!body?.bdocs?.length) return;
208+
for (const balloon of body.bdocs) {
209+
const teamTotal = await this.ctx.db.balloon.find({ teamid: balloon.uid, time: { $lt: (balloon.time * 1000).toFixed(0) } });
211210
const encourage = teamTotal.length < (config.freezeEncourage ?? 0);
212211
const totalDict = {};
213212
for (const t of teamTotal) {
214213
totalDict[t.problem] = t.contestproblem;
215214
}
216215
const shouldPrint = this.contest.info.freeze_time ? (balloon.time * 1000) < this.contest.info.freeze_time || encourage : true;
217-
if (!shouldPrint && !balloon.done) await this.setBalloonDone(balloon.balloonid);
216+
if (!shouldPrint && !balloon.sent) await this.setBalloonDone(balloon.balloonid);
218217
const contestproblem = {
219-
id: String.fromCharCode(this.contest.pids.indexOf(balloon.pid) + 65),
218+
id: String.fromCharCode(this.contest.info.pids.indexOf(balloon.pid) + 65),
220219
name: body.pdict[balloon.pid].title,
221-
rgb: this.contest.balloon[balloon.pid].color,
222-
color: this.contest.balloon[balloon.pid].name,
220+
rgb: this.contest.info.balloon[balloon.pid].color,
221+
color: this.contest.info.balloon[balloon.pid].name,
223222
};
224223
await this.ctx.db.balloon.update({ balloonid: balloon.balloonid }, {
225224
$set: {
@@ -237,13 +236,13 @@ class HydroFetcher extends BasicFetcher {
237236
),
238237
done: balloon.sent,
239238
total: totalDict,
240-
printDone: balloon.done ? 1 : 0,
239+
printDone: balloon.sent ? 1 : 0,
241240
shouldPrint,
242241
},
243242
}, { upsert: true });
244243
}
245-
await this.ctx.parallel('balloon/newTask', balloons.length);
246-
this.logger.debug(`Found ${balloons.length} balloons`);
244+
await this.ctx.parallel('balloon/newTask', body.bdocs.length);
245+
this.logger.debug(`Found ${body.bdocs.length} balloons`);
247246
}
248247

249248
async setBalloonDone(bid) {

packages/server/service/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { Context } from 'cordis';
22
import proxy from 'koa-proxies';
33
import { ForbiddenError, WebService } from '@hydrooj/framework';
44
import { config } from '../config';
5+
import { randomstring } from '../utils';
56
export * from '@hydrooj/framework/decorators';
67

78
export async function apply(pluginContext: Context) {
89
pluginContext.plugin(WebService, {
910
host: '0.0.0.0',
1011
port: config.port,
12+
keys: [randomstring(16)],
1113
} as any);
1214
pluginContext.inject(['server'], ({ server }) => {
1315
server.addServerLayer('stream', async (ctx, next) => {

0 commit comments

Comments
 (0)