|
|
@ -7,6 +7,7 @@ let Article = syzoj.model('article'); |
|
|
|
|
|
|
|
|
|
|
|
const randomstring = require('randomstring'); |
|
|
|
const randomstring = require('randomstring'); |
|
|
|
const fs = require('fs-extra'); |
|
|
|
const fs = require('fs-extra'); |
|
|
|
|
|
|
|
const jwt = require('jsonwebtoken'); |
|
|
|
|
|
|
|
|
|
|
|
let Judger = syzoj.lib('judger'); |
|
|
|
let Judger = syzoj.lib('judger'); |
|
|
|
let CodeFormatter = syzoj.lib('code_formatter'); |
|
|
|
let CodeFormatter = syzoj.lib('code_formatter'); |
|
|
@ -816,6 +817,20 @@ app.post('/problem/:id/testdata/delete/:filename', async (req, res) => { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function downloadOrRedirect(req, res, filename, sendName) { |
|
|
|
|
|
|
|
if (syzoj.config.site_for_download) { |
|
|
|
|
|
|
|
res.redirect(syzoj.config.site_for_download + syzoj.utils.makeUrl(['api', 'v2', 'download', jwt.sign({ |
|
|
|
|
|
|
|
filename: filename, |
|
|
|
|
|
|
|
sendName: sendName, |
|
|
|
|
|
|
|
originUrl: syzoj.utils.getCurrentLocation(req) |
|
|
|
|
|
|
|
}, syzoj.config.session_secret, { |
|
|
|
|
|
|
|
expiresIn: '2m' |
|
|
|
|
|
|
|
})])); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
res.download(filename, sendName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
app.get('/problem/:id/testdata/download/:filename?', async (req, res) => { |
|
|
|
app.get('/problem/:id/testdata/download/:filename?', async (req, res) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
let id = parseInt(req.params.id); |
|
|
|
let id = parseInt(req.params.id); |
|
|
@ -833,7 +848,8 @@ app.get('/problem/:id/testdata/download/:filename?', async (req, res) => { |
|
|
|
let path = require('path'); |
|
|
|
let path = require('path'); |
|
|
|
let filename = req.params.filename ? path.join(problem.getTestdataPath(), req.params.filename) : (problem.getTestdataArchivePath()); |
|
|
|
let filename = req.params.filename ? path.join(problem.getTestdataPath(), req.params.filename) : (problem.getTestdataArchivePath()); |
|
|
|
if (!await syzoj.utils.isFile(filename)) throw new ErrorMessage('文件不存在。'); |
|
|
|
if (!await syzoj.utils.isFile(filename)) throw new ErrorMessage('文件不存在。'); |
|
|
|
res.download(filename, path.basename(filename)); |
|
|
|
|
|
|
|
|
|
|
|
downloadOrRedirect(req, res, filename, path.basename(filename)); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
syzoj.log(e); |
|
|
|
syzoj.log(e); |
|
|
|
res.status(404); |
|
|
|
res.status(404); |
|
|
@ -866,7 +882,7 @@ app.get('/problem/:id/download/additional_file', async (req, res) => { |
|
|
|
|
|
|
|
|
|
|
|
if (!problem.additional_file) throw new ErrorMessage('无附加文件。'); |
|
|
|
if (!problem.additional_file) throw new ErrorMessage('无附加文件。'); |
|
|
|
|
|
|
|
|
|
|
|
res.download(problem.additional_file.getPath(), `additional_file_${id}.zip`); |
|
|
|
downloadOrRedirect(req, res, problem.additional_file.getPath(), `additional_file_${id}.zip`); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
syzoj.log(e); |
|
|
|
syzoj.log(e); |
|
|
|
res.status(404); |
|
|
|
res.status(404); |
|
|
|