Archives and restore now works to S3 and file system

If a file is stored on the file system and s3 settings later become 
available it is still correctly fetched from the file system.
This commit is contained in:
Stefan Zermatten
2022-02-03 11:48:03 +02:00
parent 2abaa86795
commit 78c313e3d1
5 changed files with 49 additions and 87 deletions

View File

@@ -8,13 +8,12 @@ import CreatureLogs from '/imports/api/creature/log/CreatureLogs.js';
import Experiences from '/imports/api/creature/experience/Experiences.js';
import { removeCreatureWork } from '/imports/api/creature/creatures/methods/removeCreature.js';
import ArchiveCreatureFiles from '/imports/api/creature/archive/ArchiveCreatureFiles.js';
import readFile from '/imports/api/creature/archive/methods/readFile.js';
let migrateArchive;
if (Meteor.isServer){
migrateArchive = require('/imports/migrations/server/migrateArchive.js').default;
}
function restoreCreature(file, archive){
function restoreCreature(archive){
if (SCHEMA_VERSION < archive.meta.schemaVersion){
throw new Meteor.Error('Incompatible',
'The archive file is from a newer version. Update required to read.')
@@ -72,12 +71,11 @@ const restoreCreaturefromFile = new ValidatedMethod({
}
if (Meteor.isServer){
// Read the file data
const string = await readFile(file);
const archive = JSON.parse(string);
restoreCreature(file, archive);
//Remove the archive once the restore succeeded
ArchiveCreatureFiles.remove({_id: fileId})
const archive = await ArchiveCreatureFiles.readJSONFile(file);
restoreCreature(archive);
}
//Remove the archive once the restore succeeded
ArchiveCreatureFiles.remove({_id: fileId});
},
});