overleaf/services/filestore/app/js/PersistorManager.js

40 lines
1,006 B
JavaScript
Raw Normal View History

const settings = require('settings-sharelatex')
const logger = require('logger-sharelatex')
logger.log(
{
backend: settings.filestore.backend,
fallback: settings.filestore.fallback && settings.filestore.fallback.backend
},
'Loading backend'
)
if (!settings.filestore.backend) {
throw new Error('no backend specified - config incomplete')
}
2014-02-26 06:58:48 -05:00
function getPersistor(backend) {
switch (backend) {
case 'aws-sdk':
case 's3':
return require('./S3Persistor')
case 'fs':
return require('./FSPersistor')
2020-02-12 06:00:45 -05:00
case 'gcs':
return require('./GcsPersistor')
default:
throw new Error(`unknown filestore backend: ${backend}`)
}
}
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