Files
triliumnext-korean-patch/updates/2026-09-05/work/trilium/build-server.mjs
T

46 lines
2.7 KiB
JavaScript

import fs from 'node:fs';
import crypto from 'node:crypto';
const b='work/trilium';
let main=fs.readFileSync(b+'/scoped/main.cjs','utf8');
const needle='vr.init(()=>{LN.checkHiddenSubtree()})';
if(main.split(needle).length!==2)throw Error('Startup patch point mismatch');
const migration=`
function triliumApplyKoreanNotes(){
const fs=require('fs'),crypto=require('crypto');
const filename='/home/node/trilium-data/korean-notes-pending.json';
if(!fs.existsSync(filename))return;
const plan=JSON.parse(fs.readFileSync(filename,'utf8'));
if(plan.version!==1||!Array.isArray(plan.changes))throw Error('Invalid Korean migration');
const digest=s=>crypto.createHash('sha256').update(s||'').digest('hex');
let applied=0,unchanged=0;
de.transactional(()=>{
for(const change of plan.changes){
const note=J.getNoteOrThrow(change.noteId);
const content=note.getContent();
if(note.title===change.title&&(!('content' in change)||content===change.content)){unchanged++;continue;}
if(note.isDeleted||note.isProtected||note.title!==change.oldTitle)throw Error('Korean migration title conflict: '+change.noteId);
if(change.oldContentSha256&&digest(content)!==change.oldContentSha256)throw Error('Korean migration content conflict: '+change.noteId);
}
for(const change of plan.changes){
const note=J.getNoteOrThrow(change.noteId),content=note.getContent();
if(note.title===change.title&&(!('content' in change)||content===change.content))continue;
const revision=new Mk({noteId:note.noteId,title:note.title,type:note.type,mime:note.mime,isProtected:note.isProtected,utcDateLastEdited:note.utcDateModified,utcDateCreated:kr.utcNowDateTime(),utcDateModified:kr.utcNowDateTime(),dateLastEdited:note.dateModified,dateCreated:kr.localNowDateTime()},true);
revision.save();revision.setContent(content);
note.title=change.title;note.save();
if('content' in change)note.setContent(change.content);
applied++;
}
});
fs.renameSync(filename,filename+'.applied-'+Date.now());
console.log('KOREAN_MIGRATION '+JSON.stringify({applied,unchanged}));
}
`;
main=main.replace(needle,'vr.init(()=>{LN.checkHiddenSubtree();triliumApplyKoreanNotes()})');
main=migration+main;
if(!main.includes('jg=`assets/v${CR.version}`'))throw Error('Asset version patch point mismatch');
main=main.replace('jg=`assets/v${CR.version}`','jg=`assets/v${CR.version}-ko-20260905`');
fs.writeFileSync(b+'/release/main.cjs',main);
const sources={};
for(const [local,remote] of [['scoped/main.cjs','patched/main.cjs'],['layout_commons.js','patched/layout_commons.js'],['translation.ko.json','i18n_ko/translation.json']])sources[remote]=crypto.createHash('sha256').update(fs.readFileSync(b+'/'+local)).digest('hex');
fs.writeFileSync(b+'/release/source-hashes.json',JSON.stringify(sources));