2017-12-03 22:29:23 -05:00
|
|
|
"use strict";
|
|
|
|
|
2024-04-07 14:33:41 +03:00
|
|
|
import sqlInit = require('../services/sql_init');
|
|
|
|
import setupService = require('../services/setup');
|
|
|
|
import assetPath = require('../services/asset_path');
|
|
|
|
import appPath = require('../services/app_path');
|
|
|
|
import { Request, Response } from 'express';
|
2024-05-12 10:53:34 +03:00
|
|
|
import { SetupCompleteCallback } from './types';
|
2018-07-24 08:12:36 +02:00
|
|
|
|
2024-05-12 10:53:34 +03:00
|
|
|
function buildSetupRoute(setupCompleteCallback: SetupCompleteCallback) {
|
|
|
|
return (req: Request, res: Response) => {
|
|
|
|
if (sqlInit.isDbInitialized()) {
|
|
|
|
setupCompleteCallback(res);
|
|
|
|
return;
|
2019-12-24 14:42:03 +01:00
|
|
|
}
|
2024-05-12 10:53:34 +03:00
|
|
|
|
|
|
|
// we got here because DB is not completely initialized, so if schema exists,
|
|
|
|
// it means we're in "sync in progress" state.
|
|
|
|
const syncInProgress = sqlInit.schemaExists();
|
|
|
|
|
|
|
|
if (syncInProgress) {
|
|
|
|
// trigger sync if it's not already running
|
|
|
|
setupService.triggerSync();
|
2019-12-24 14:42:03 +01:00
|
|
|
}
|
2024-05-12 10:53:34 +03:00
|
|
|
|
|
|
|
res.render('setup', {
|
|
|
|
syncInProgress: syncInProgress,
|
|
|
|
assetPath: assetPath,
|
|
|
|
appPath: appPath
|
|
|
|
});
|
2018-07-24 08:12:36 +02:00
|
|
|
}
|
2018-03-30 19:31:22 -04:00
|
|
|
}
|
2017-12-03 22:29:23 -05:00
|
|
|
|
2024-04-07 14:33:41 +03:00
|
|
|
export = {
|
2024-05-12 10:53:34 +03:00
|
|
|
buildSetupRoute
|
2018-03-30 19:31:22 -04:00
|
|
|
};
|