@@ -2,8 +2,9 @@ const { exec } = require("child_process");
2
2
const { post } = require ( "axios" )
3
3
const { readFileSync } = require ( "fs" ) ;
4
4
const path = require ( 'path' )
5
- const prompt = require ( 'prompt' )
6
- const endpoint = 'https://nhfz4ymqhc.execute-api.ap-northeast-2.amazonaws.com/dev/auth'
5
+ const prompt = require ( 'prompt' ) ;
6
+ const zip = require ( './zip' )
7
+ const endpoint = 'https://2j12cf7y29.execute-api.ap-northeast-2.amazonaws.com/dev/'
7
8
const payload = {
8
9
"name" : path . basename ( process . cwd ( ) ) ,
9
10
"assessments" : [ {
@@ -38,11 +39,11 @@ const getEmail = () => {
38
39
}
39
40
40
41
const getEndpoint = ( email ) => {
41
- post ( endpoint , {
42
+ post ( endpoint + 'auth' , {
42
43
email
43
44
} )
44
45
. then ( res => {
45
- runReport ( result => submit ( result , res . data ) )
46
+ runReport ( async result => await submit ( result , res . data ) )
46
47
} )
47
48
. catch ( err => {
48
49
if ( err . response . status === 404 ) {
@@ -64,17 +65,36 @@ const runReport = (callback) => {
64
65
} )
65
66
}
66
67
67
- const submit = ( result , auth ) => {
68
+ const submit = async ( result , auth ) => {
68
69
payload . user = auth . users [ 0 ]
69
70
payload . assessments [ 0 ] . result = result
71
+ const filename = `${ payload . user . email } --${ new Date ( ) . toISOString ( ) . replace ( / \: / g, '-' ) } .zip`
70
72
71
- post ( auth . endpoint_submit , payload )
73
+ // console.log(payload)
74
+ const config = {
75
+ headers : {
76
+ 'Content-Type' : 'application/json'
77
+ }
78
+ }
79
+
80
+ post ( auth . endpoint_submit , payload , config )
72
81
. then ( resp => {
73
82
console . log ( '제출에 성공하였습니다.' )
74
83
} )
75
84
. catch ( err => {
85
+ console . log ( err )
76
86
throw new Error ( '제출에 실패하였습니다.' )
77
87
} )
88
+
89
+ const base64 = await zip ( filename )
90
+ post ( auth . endpoint_upload , { contents : base64 , filename } , config )
91
+ . then ( resp => {
92
+ console . log ( '과제 업로드에 성공하였습니다.' )
93
+ } )
94
+ . catch ( err => {
95
+ console . log ( err )
96
+ throw new Error ( '과제 업로드에 실패하였습니다.' )
97
+ } )
78
98
}
79
99
80
100
module . exports = getEmail ;
0 commit comments