@@ -12,19 +12,50 @@ const db = require('./../utils/db/db');
1212const Solution = require ( './../models/solution/solution' ) ;
1313const router = express . Router ( ) ;
1414
15+ < << << << HEAD
1516//var upload = multer({dest:'solutions/'})
1617//var originalname = 'solution';
1718router . post ( '/' , async ( req , res ) => {
1819 var count = await Solution . getObjCount ( req . body . username , req . body . contest , req . body . problem ) + 1 ;
1920 var solution = new Solution ( {
21+ === === =
22+ var upload = multer ( { dest :'solutions/' } )
23+ var originalname = 'solution' ;
24+ router . post ( '/' , upload . single ( originalname ) , async ( req , res ) => {
25+ var solution ;
26+ if ( req . file ) {
27+ var count = await Solution . getObjCount ( req . body . username , req . body . contest , req . body . problem ) + 1 ;
28+ solution = new Solution ( {
29+ problem :req . body . problem ,
30+ contest :req . body . contest ,
31+ username :req . body . username ,
32+ id :req . body . contest + req . body . problem + req . body . username + count ,
33+ language :req . body . language . toLowerCase ( ) ,
34+ description :new Buffer ( fs . readFileSync ( req . file . path ) ) . toString ( 'base64' ) ,
35+ submitted_on :new Date ( )
36+ } ) ;
37+ }
38+
39+ else if ( ! req . file ) {
40+ var count = await Solution . getObjCount ( req . body . username , req . body . contest , req . body . problem ) + 1 ;
41+ solution = new Solution ( {
42+ >>> >>> > 5 b116472edb8e59b201766368eae67301e945e2b
2043 problem :req . body . problem ,
2144 contest :req . body . contest ,
2245 username :req . body . username ,
2346 id :req . body . contest + req . body . problem + req . body . username + count ,
2447 language :req . body . language . toLowerCase ( ) ,
48+ << < << << HEAD
2549 description :req . body . description ,
2650 submitted_on :new Date ( )
2751 } ) ;
52+ = === ===
53+ description:req . body . description . toString ( 'base64' ) ,
54+ submitted_on :new Date ( )
55+ } ) ;
56+ }
57+
58+ >>> > >>> 5 b116472edb8e59b201766368eae67301e945e2b
2859 solution . save ( ) . then ( ( sol ) => {
2960 const agentOptions = new Object ( ) ;
3061 agentOptions . keepAliveMsecs = 6000 ;
0 commit comments