mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-06 23:59:01 +02:00
07c827e9fd
[web] last infrastructure conversions GitOrigin-RevId: ad1aff9b7df0610ed0303157d9e2c8032f32c02b
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
import logger from '@overleaf/logger'
|
|
import DocumentUpdaterHandler from './DocumentUpdaterHandler.mjs'
|
|
import ProjectLocator from '../Project/ProjectLocator.mjs'
|
|
import { plainTextResponse } from '../../infrastructure/Response.mjs'
|
|
import { expressify } from '@overleaf/promise-utils'
|
|
|
|
async function getDoc(req, res) {
|
|
const projectId = req.params.Project_id
|
|
const docId = req.params.Doc_id
|
|
|
|
try {
|
|
const { element: doc } = await ProjectLocator.promises.findElement({
|
|
project_id: projectId,
|
|
element_id: docId,
|
|
type: 'doc',
|
|
})
|
|
|
|
const { lines } = await DocumentUpdaterHandler.promises.getDocument(
|
|
projectId,
|
|
docId,
|
|
-1 // latest version only
|
|
)
|
|
|
|
res.setContentDisposition('attachment', { filename: doc.name })
|
|
plainTextResponse(res, lines.join('\n'))
|
|
} catch (err) {
|
|
if (err.name === 'NotFoundError') {
|
|
logger.warn(
|
|
{ err, projectId, docId },
|
|
'entity not found when downloading doc'
|
|
)
|
|
|
|
return res.sendStatus(404)
|
|
}
|
|
|
|
logger.err(
|
|
{ err, projectId, docId },
|
|
'error getting document for downloading'
|
|
)
|
|
|
|
return res.sendStatus(500)
|
|
}
|
|
}
|
|
|
|
export default {
|
|
getDoc: expressify(getDoc),
|
|
}
|