2019-12-16 10:42:31 +00:00
|
|
|
const settings = require('settings-sharelatex')
|
|
|
|
const logger = require('logger-sharelatex')
|
2014-02-25 09:10:22 +00:00
|
|
|
|
2020-01-04 17:27:12 +00:00
|
|
|
logger.log(
|
|
|
|
{
|
2020-02-17 14:04:42 +00:00
|
|
|
backend: settings.filestore.backend,
|
|
|
|
fallback: settings.filestore.fallback && settings.filestore.fallback.backend
|
2020-01-04 17:27:12 +00:00
|
|
|
},
|
|
|
|
'Loading backend'
|
|
|
|
)
|
|
|
|
if (!settings.filestore.backend) {
|
|
|
|
throw new Error('no backend specified - config incomplete')
|
|
|
|
}
|
2014-02-26 11:58:48 +00:00
|
|
|
|
2020-02-17 14:04:42 +00:00
|
|
|
function getPersistor(backend) {
|
|
|
|
switch (backend) {
|
|
|
|
case 'aws-sdk':
|
|
|
|
case 's3':
|
|
|
|
return require('./S3Persistor')
|
|
|
|
case 'fs':
|
|
|
|
return require('./FSPersistor')
|
2020-02-12 11:00:45 +00:00
|
|
|
case 'gcs':
|
|
|
|
return require('./GcsPersistor')
|
2020-02-17 14:04:42 +00:00
|
|
|
default:
|
|
|
|
throw new Error(`unknown filestore backend: ${backend}`)
|
|
|
|
}
|
2020-01-04 17:27:12 +00:00
|
|
|
}
|
2020-02-17 14:04:42 +00:00
|
|
|
|
|
|
|
let persistor = getPersistor(settings.filestore.backend)
|
|
|
|
|
|
|
|
if (settings.filestore.fallback && settings.filestore.fallback.backend) {
|
|
|
|
const migrationPersistor = require('./MigrationPersistor')
|
|
|
|
persistor = migrationPersistor(
|
|
|
|
persistor,
|
|
|
|
getPersistor(settings.filestore.fallback.backend)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = persistor
|