Make migration only start once the "Next" button is pressed.

This commit is contained in:
ajnart
2023-01-08 13:00:25 +09:00
parent 6586914ff5
commit c2a9ff44fd
2 changed files with 29 additions and 17 deletions

21
src/pages/api/migrate.ts Normal file
View 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',
});
};