Move functions to prepare for async/await

GitOrigin-RevId: b0f43d14a214d1f7695b3b312d63827d2c82470c
This commit is contained in:
andrew rumble 2024-10-02 14:31:52 +01:00 committed by Copybot
parent 50723d0f8f
commit 696bfa3756

View file

@ -46,32 +46,7 @@ const { plainTextResponse } = require('../../infrastructure/Response')
const ReferencesHandler = require('../References/ReferencesHandler')
const EditorRealTimeController = require('../Editor/EditorRealTimeController')
module.exports = LinkedFilesController = {
Agents: _.extend(
{
url: require('./UrlAgent'),
project_file: require('./ProjectFileAgent'),
project_output_file: require('./ProjectOutputFileAgent'),
},
Modules.linkedFileAgentsIncludes()
),
_getAgent(provider) {
if (
!Object.prototype.hasOwnProperty.call(
LinkedFilesController.Agents,
provider
)
) {
return null
}
if (!Array.from(Settings.enabledLinkedFileTypes).includes(provider)) {
return null
}
return LinkedFilesController.Agents[provider]
},
createLinkedFile(req, res, next) {
function createLinkedFile(req, res, next) {
const { project_id: projectId } = req.params
const { name, provider, data, parent_folder_id: parentFolderId } = req.body
const userId = SessionManager.getLoggedInUserId(req.session)
@ -106,9 +81,9 @@ module.exports = LinkedFilesController = {
return res.json({ new_file_id: newFileId })
}
)
},
}
refreshLinkedFile(req, res, next) {
function refreshLinkedFile(req, res, next) {
const { project_id: projectId, file_id: fileId } = req.params
const userId = SessionManager.getLoggedInUserId(req.session)
@ -172,7 +147,36 @@ module.exports = LinkedFilesController = {
)
}
)
}
module.exports = LinkedFilesController = {
Agents: _.extend(
{
url: require('./UrlAgent'),
project_file: require('./ProjectFileAgent'),
project_output_file: require('./ProjectOutputFileAgent'),
},
Modules.linkedFileAgentsIncludes()
),
_getAgent(provider) {
if (
!Object.prototype.hasOwnProperty.call(
LinkedFilesController.Agents,
provider
)
) {
return null
}
if (!Array.from(Settings.enabledLinkedFileTypes).includes(provider)) {
return null
}
return LinkedFilesController.Agents[provider]
},
createLinkedFile,
refreshLinkedFile,
handleError(error, req, res, next) {
if (error instanceof AccessDeniedError) {