mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 16:05:47 +01:00
Make migration only start once the "Next" button is pressed.
This commit is contained in:
21
src/pages/api/migrate.ts
Normal file
21
src/pages/api/migrate.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import fs from 'fs';
|
||||
import { backendMigrateConfig } from '../../tools/config/backendMigrateConfig';
|
||||
|
||||
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
// Get all the configs in the /data/configs folder
|
||||
const configs = fs.readdirSync('./data/configs');
|
||||
// If there is no config, redirect to the index
|
||||
configs.every((config) => {
|
||||
const configData = JSON.parse(fs.readFileSync(`./data/configs/${config}`, 'utf8'));
|
||||
if (!configData.schemaVersion) {
|
||||
// Migrate the config
|
||||
backendMigrateConfig(configData, config.replace('.json', ''));
|
||||
}
|
||||
return config;
|
||||
});
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: 'Configs migrated',
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user