1
1
import path from 'path' ;
2
2
import superagent from 'superagent' ;
3
3
import {
4
- fs , Logger , receiptGenerate , sleep ,
4
+ fs , Logger , receiptText , sleep ,
5
5
} from './utils' ;
6
6
7
7
const logger = new Logger ( 'fetcher' ) ;
8
8
9
9
let timer = null ;
10
10
let printer = null ;
11
11
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
+
12
27
async function fetchTask ( c ) {
13
28
if ( timer ) clearTimeout ( timer ) ;
14
29
logger . info ( 'Fetching Task from tools server...' ) ;
15
30
try {
16
- const printersInfo = await getPrinters ( ) ;
17
31
const { body } = await superagent . post ( `${ c . server } /client/${ c . token } /balloon` ) . send ( ) ;
18
32
if ( body . doc ) {
19
33
logger . info ( `Print task ${ body . doc . tid } #${ body . doc . _id } ...` ) ;
20
- await printFile ( body . doc ) ;
34
+ await printBalloon ( body . doc ) ;
21
35
await superagent . post ( `${ c . server } /client/${ c . token } /doneballoon/${ body . doc . _id } ` ) ;
22
36
logger . info ( `Print task ${ body . doc . tid } #${ body . doc . _id } completed.` ) ;
23
37
} else {
@@ -31,11 +45,6 @@ async function fetchTask(c) {
31
45
timer = setTimeout ( ( ) => fetchTask ( c ) , 3000 ) ;
32
46
}
33
47
34
- async function printBaloon ( doc ) {
35
- const printer = global . Tools . config . balloon ;
36
- const bReceipt = receiptGenerate ( doc ) ;
37
- }
38
-
39
48
export async function apply ( ) {
40
49
const { config } = global . Tools ;
41
50
if ( ! config ) {
0 commit comments