405c1d27c9
Add a 'Python packages' button to the file-tree toolbar that opens a modal to edit the project's requirements.vrf (one package per line, pip syntax), backed by GET/POST /project/:id/python-requirements (read via ProjectEntityHandler, write via EditorController.upsertDocWithPath, write-gated). The .vrf file is now hidden from the file tree, so it is managed only through this editor rather than appearing as a loose file. Adds python_packages / python_packages_help i18n. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
39 lines
1.4 KiB
JavaScript
39 lines
1.4 KiB
JavaScript
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),
|
|
}
|