Skip to content

Commit f293f2a

Browse files
committed
download utility
Signed-off-by: Tathagat Thapliyal <tathagat.thapliyal@gmail.com>
1 parent ef52e51 commit f293f2a

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

src/tasks/submission.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import { cat, exec, mkdir, rm } from 'shelljs'
33
import { SubmissionJob, SubmissionResult } from '../types/job'
44
import * as path from 'path'
55
import * as fs from 'fs'
6-
import http from 'http'
6+
import * as https from 'https'
77
import { Scenario } from 'types/scenario.js'
8+
import { ClientRequest } from 'http';
89

9-
export const download = (url: string, dest: string): Promise<http.ClientRequest> => {
10+
export const download = (url: string, dest: string): Promise<ClientRequest> => {
1011
const file = fs.createWriteStream(dest);
1112
return new Promise((resolve, reject) =>
12-
http.get(url, function(response) {
13+
https.get(url, function (response) {
1314
response.pipe(file);
14-
file.on('finish', function() {
15+
file.on('finish', function () {
1516
resolve()
1617
});
1718
}).on('error', err => {
@@ -24,16 +25,6 @@ class SubmissionScenario implements Scenario {
2425
setup(currentJobDir: string, job: SubmissionJob) {
2526
const LANG_CONFIG = config.LANGS[job.lang]
2627

27-
job.testcases.map(testcase => {
28-
mkdir('-p', `currentJobDir/${testcase.id}`)
29-
// const file = fs.createWriteStream();
30-
Promise.all([http.get(testcase.input), http.get(testcase.output)])
31-
.then(values => {
32-
values.map(value => {
33-
34-
})
35-
})
36-
})
3728
fs.writeFileSync(path.join(currentJobDir, LANG_CONFIG.SOURCE_FILE),
3829
(new Buffer(job.source, 'base64')).toString('ascii'))
3930
fs.writeFileSync(path.join(currentJobDir, ),
@@ -42,9 +33,11 @@ class SubmissionScenario implements Scenario {
4233

4334
async result(currentJobDir: string): Promise<SubmissionResult> {
4435
// TODO
45-
return {
46-
47-
}
36+
return Promise.resolve({
37+
id: 1,
38+
stderr: '',
39+
testcases: []
40+
})
4841
}
4942
}
5043

test/submissionScenario.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { expect } from 'chai'
2+
import { download } from '../src/tasks/submission'
3+
import * as fs from 'fs'
4+
5+
describe('Submission Scenario', () => {
6+
it('should download', async () => {
7+
const url = 'https://minio.cb.lk/public/input'
8+
const result = await download(url, '/tmp/input')
9+
10+
// assertion
11+
const content = fs.readFileSync('/tmp/input').toString()
12+
expect(content.trim()).to.eq('World')
13+
})
14+
})

0 commit comments

Comments
 (0)