Files
Foundry-VTT-Docker/resources/app/dist/migrations.mjs

1 line
1.7 KiB
JavaScript
Raw Permalink Normal View History

2025-01-04 00:34:03 +01:00
import path from"node:path";import fs from"node:fs";import NeDB from"nedb";import{DOCUMENT_OWNERSHIP_LEVELS}from"../common/constants.mjs";import Files from"./files/files.mjs";async function migrateDeleteFOW(e){const a=path.join(e.path,"data","fog.db");fs.existsSync(a)&&(global.logger.info("Deleting legacy FogExploration database."),fs.unlinkSync(a))}async function migrateSceneDefaultPermission(e){const a=path.join(e.path,"data","scenes.db");if(!fs.existsSync(a))return;const t=await new Promise(((e,t)=>{const n=new NeDB(a);n.loadDatabase((a=>a?t(a):e(n)))})),n=await new Promise(((e,a)=>{t.find({},((t,n)=>t?a(t):e(n)))}));for(const e of n){const a=e.permission?.default;a===DOCUMENT_OWNERSHIP_LEVELS.OWNER&&(global.logger.info(`Migrating default ownership of Scene record [${e._id}] from OWNER to OBSERVER.`),await new Promise(((a,n)=>{t.update({_id:e._id},{$set:{"permission.default":DOCUMENT_OWNERSHIP_LEVELS.OBSERVER}},{},(e=>e?n(e):a()))})))}}async function migrateChatMessages(e){const a=path.join(e.path,"data","chat.db"),t=path.join(e.path,"data","messages.db"),n=fs.statSync(t,{throwIfNoEntry:!1});if(n&&!(n.size>0)&&fs.existsSync(a)){global.logger.info(`Migrating ChatMessage database. Copying '${a}' -> '${t}'`);try{await Files.copyLargeFile(a,t)}catch(e){return void global.logger.error(`Migration failed: ${e.message}`)}fs.unlinkSync(a)}}async function migrateDeleteDrawings(e){const a=path.join(e.path,"data","drawings"),t=path.join(e.path,"data","drawings.db"),n=fs.existsSync(a),s=fs.existsSync(t);(n||s)&&global.logger.info("Deleting unused Drawing database."),n&&fs.rmSync(a,{recursive:!0}),s&&fs.unlinkSync(t)}export default{"0.7.3":[migrateDeleteFOW],"0.8.7":[migrateSceneDefaultPermission],9.224:[migrateChatMessages],12:[migrateDeleteDrawings]};