Init user storage module before server listening

This commit is contained in:
Cohee
2024-04-26 14:09:40 +03:00
parent babb4cb57b
commit 1b60e4a013
2 changed files with 40 additions and 30 deletions

View File

@@ -543,22 +543,13 @@ const setupTasks = async function () {
} }
console.log(); console.log();
// TODO: do endpoint init functions depend on certain directories existing or not existing? They should be callable const directories = await userModule.getUserDirectoriesList();
// in any order for encapsulation reasons, but right now it's unknown if that would break anything.
await userModule.initUserStorage(dataRoot);
if (listen && !basicAuthMode && enableAccounts) {
await userModule.checkAccountsProtection();
}
await settingsEndpoint.init();
const directories = await userModule.ensurePublicDirectoriesExist();
await userModule.migrateUserData();
await contentManager.checkForNewContent(directories); await contentManager.checkForNewContent(directories);
await ensureThumbnailCache(); await ensureThumbnailCache();
cleanUploads(); cleanUploads();
await loadTokenizers(); await loadTokenizers();
await settingsEndpoint.init();
await statsEndpoint.init(); await statsEndpoint.init();
const cleanupPlugins = await loadPlugins(); const cleanupPlugins = await loadPlugins();
@@ -581,7 +572,6 @@ const setupTasks = async function () {
exitProcess(); exitProcess();
}); });
console.log('Launching...'); console.log('Launching...');
if (autorun) open(autorunUrl.toString()); if (autorun) open(autorunUrl.toString());
@@ -601,6 +591,9 @@ const setupTasks = async function () {
} }
} }
if (listen && !basicAuthMode && enableAccounts) {
await userModule.checkAccountsProtection();
}
}; };
/** /**
@@ -642,6 +635,11 @@ function setWindowTitle(title) {
} }
} }
// User storage module needs to be initialized before starting the server
userModule.initUserStorage(dataRoot)
.then(userModule.ensurePublicDirectoriesExist)
.then(userModule.migrateUserData)
.finally(() => {
if (cliArguments.ssl) { if (cliArguments.ssl) {
https.createServer( https.createServer(
{ {
@@ -660,3 +658,4 @@ if (cliArguments.ssl) {
setupTasks, setupTasks,
); );
} }
});

View File

@@ -112,6 +112,16 @@ async function ensurePublicDirectoriesExist() {
return directoriesList; return directoriesList;
} }
/**
* Gets a list of all user directories.
* @returns {Promise<import('./users').UserDirectoryList[]>} - The list of user directories
*/
async function getUserDirectoriesList() {
const userHandles = await getAllUserHandles();
const directoriesList = userHandles.map(handle => getUserDirectories(handle));
return directoriesList;
}
/** /**
* Perform migration from the old user data format to the new one. * Perform migration from the old user data format to the new one.
*/ */
@@ -707,6 +717,7 @@ module.exports = {
toAvatarKey, toAvatarKey,
initUserStorage, initUserStorage,
ensurePublicDirectoriesExist, ensurePublicDirectoriesExist,
getUserDirectoriesList,
getAllUserHandles, getAllUserHandles,
getUserDirectories, getUserDirectories,
setUserDataMiddleware, setUserDataMiddleware,