2021-12-14 08:00:35 -05:00
|
|
|
const logger = require('@overleaf/logger')
|
2024-10-24 07:43:10 -04:00
|
|
|
const ObjectPersistor = require('@overleaf/object-persistor')
|
2021-07-12 12:47:19 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2024-11-08 05:21:56 -05:00
|
|
|
const { promisify } = require('node:util')
|
2024-10-24 07:43:10 -04:00
|
|
|
const App = require('../../../app')
|
|
|
|
const FileHandler = require('../../../app/js/FileHandler')
|
2019-12-16 05:42:36 -05:00
|
|
|
|
2019-12-23 08:36:12 -05:00
|
|
|
logger.logger.level('info')
|
|
|
|
|
|
|
|
class FilestoreApp {
|
|
|
|
async runServer() {
|
2024-10-24 07:43:10 -04:00
|
|
|
if (!this.server) {
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
this.server = App.listen(
|
|
|
|
Settings.internal.filestore.port,
|
|
|
|
'127.0.0.1',
|
|
|
|
err => {
|
|
|
|
if (err) {
|
|
|
|
return reject(err)
|
|
|
|
}
|
|
|
|
resolve()
|
2019-12-16 05:42:41 -05:00
|
|
|
}
|
2024-10-24 07:43:10 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
2019-12-23 08:36:12 -05:00
|
|
|
|
2024-10-24 07:43:10 -04:00
|
|
|
this.persistor = ObjectPersistor({
|
|
|
|
...Settings.filestore,
|
|
|
|
paths: Settings.path,
|
|
|
|
})
|
|
|
|
FileHandler._TESTONLYSwapPersistorManager(this.persistor)
|
2019-12-23 08:36:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async stop() {
|
2020-02-23 13:26:30 -05:00
|
|
|
if (!this.server) return
|
2020-01-02 04:53:07 -05:00
|
|
|
const closeServer = promisify(this.server.close).bind(this.server)
|
|
|
|
try {
|
|
|
|
await closeServer()
|
|
|
|
} finally {
|
2019-12-23 08:36:12 -05:00
|
|
|
delete this.server
|
2019-12-16 05:42:41 -05:00
|
|
|
}
|
2019-12-23 08:36:12 -05:00
|
|
|
}
|
2019-12-16 05:42:41 -05:00
|
|
|
}
|
2019-12-23 08:36:12 -05:00
|
|
|
|
|
|
|
module.exports = FilestoreApp
|