import { expressify } from '@overleaf/promise-utils' import SessionManager from '../Authentication/SessionManager.mjs' import ProjectEntityHandler from '../Project/ProjectEntityHandler.mjs' import EditorController from '../Editor/EditorController.mjs' // The project's Python dependency list lives in a single Verso requirements // file at the project root. It is hidden from the file tree and edited through // the dedicated "Python packages" modal instead. const REQUIREMENTS_PATH = '/requirements.vrf' async function getRequirements(req, res) { const projectId = req.params.Project_id const docs = await ProjectEntityHandler.promises.getAllDocs(projectId) const doc = docs[REQUIREMENTS_PATH] res.json({ content: doc ? doc.lines.join('\n') : '' }) } async function setRequirements(req, res) { const projectId = req.params.Project_id const userId = SessionManager.getLoggedInUserId(req.session) const content = typeof req.body.content === 'string' ? req.body.content : '' // Normalise line endings; an empty body still upserts an (empty) file, which // is harmless and keeps the editor state simple. const docLines = content.replace(/\r\n?/g, '\n').split('\n') await EditorController.promises.upsertDocWithPath( projectId, REQUIREMENTS_PATH, docLines, 'python-requirements', userId ) res.json({ content }) } export default { getRequirements: expressify(getRequirements), setRequirements: expressify(setRequirements), }