Notes/server/src/routes/setup.ts

37 lines
1.1 KiB
TypeScript
Raw Normal View History

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';
2024-05-12 10:53:34 +03:00
function buildSetupRoute(setupCompleteCallback: SetupCompleteCallback) {
return (req: Request, res: Response) => {
if (sqlInit.isDbInitialized()) {
setupCompleteCallback(res);
return;
}
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();
}
2024-05-12 10:53:34 +03:00
res.render('setup', {
syncInProgress: syncInProgress,
assetPath: assetPath,
appPath: appPath
});
}
}
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
};