mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Merge pull request #26047 from overleaf/bg-web-api-is-leaking-disk-space
clean up temporary files in GitBridgeHandler operations GitOrigin-RevId: b4a202f4f4c563a020fed8a47da1a84417ccbd2d
This commit is contained in:
@@ -3,12 +3,16 @@ import AbstractMockApi from './AbstractMockApi.mjs'
|
||||
class MockGitBridgeApi extends AbstractMockApi {
|
||||
reset() {
|
||||
this.projects = {}
|
||||
this.postbacks = {}
|
||||
}
|
||||
|
||||
applyRoutes() {
|
||||
this.app.delete('/api/projects/:projectId', (req, res) => {
|
||||
this.deleteProject(req, res)
|
||||
})
|
||||
this.app.post('/postback/:id', (req, res) => {
|
||||
this.postback(req, res)
|
||||
})
|
||||
}
|
||||
|
||||
deleteProject(req, res) {
|
||||
@@ -16,6 +20,24 @@ class MockGitBridgeApi extends AbstractMockApi {
|
||||
delete this.projects[projectId]
|
||||
res.sendStatus(204)
|
||||
}
|
||||
|
||||
// Git bridge accepts a postback to indicate when a operation is complete.
|
||||
// Each postback is identified by a unique ID.
|
||||
// Allow registering a handler which resolves when a postback is received.
|
||||
registerPostback(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.postbacks[id] = { resolve, reject }
|
||||
})
|
||||
}
|
||||
|
||||
postback(req, res) {
|
||||
const { id } = req.params
|
||||
const postbackData = req.body
|
||||
if (this.postbacks[id]) {
|
||||
this.postbacks[id].resolve(postbackData)
|
||||
}
|
||||
res.sendStatus(204)
|
||||
}
|
||||
}
|
||||
|
||||
export default MockGitBridgeApi
|
||||
|
||||
Reference in New Issue
Block a user