Skip to content

Commit 4433cb6

Browse files
committed
fix
1 parent a079055 commit 4433cb6

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

packages/client/balloon.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
import path from 'path';
22
import superagent from 'superagent';
33
import {
4-
fs, Logger, receiptGenerate, sleep,
4+
fs, Logger, receiptText, sleep,
55
} from './utils';
66

77
const logger = new Logger('fetcher');
88

99
let timer = null;
1010
let printer = null;
1111

12+
async function printBalloon(doc) {
13+
const bReceipt = receiptText(
14+
doc.balloonid,
15+
doc.location ? doc.location : 'N/A',
16+
doc.problem,
17+
doc.contestproblem.color,
18+
doc.awards ? doc.awards : 'N/A',
19+
doc.team,
20+
doc.total ? Object.keys(doc.total).map((k) => `- ${k}: ${doc.total[k].color}`).join('\n') : 'N/A',
21+
);
22+
if (printer) {
23+
fs.writeFileSync(path.resolve(printer), bReceipt);
24+
}
25+
}
26+
1227
async function fetchTask(c) {
1328
if (timer) clearTimeout(timer);
1429
logger.info('Fetching Task from tools server...');
1530
try {
16-
const printersInfo = await getPrinters();
1731
const { body } = await superagent.post(`${c.server}/client/${c.token}/balloon`).send();
1832
if (body.doc) {
1933
logger.info(`Print task ${body.doc.tid}#${body.doc._id}...`);
20-
await printFile(body.doc);
34+
await printBalloon(body.doc);
2135
await superagent.post(`${c.server}/client/${c.token}/doneballoon/${body.doc._id}`);
2236
logger.info(`Print task ${body.doc.tid}#${body.doc._id} completed.`);
2337
} else {
@@ -31,11 +45,6 @@ async function fetchTask(c) {
3145
timer = setTimeout(() => fetchTask(c), 3000);
3246
}
3347

34-
async function printBaloon(doc) {
35-
const printer = global.Tools.config.balloon;
36-
const bReceipt = receiptGenerate(doc);
37-
}
38-
3948
export async function apply() {
4049
const { config } = global.Tools;
4150
if (!config) {

packages/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Logger.levels.base = 3;
88

99
const logger = new Logger('tools');
1010

11-
require('./init').load();
11+
require('./config');
1212
process.on('unhandledRejection', (e) => { logger.error(e); });
1313
process.on('uncaughtException', (e) => { logger.error(e); });
1414
Error.stackTraceLimit = 50;

0 commit comments

Comments
 (0)