// Upgrader2 45: úpravy ovladače Scramjetu, které brána potřebuje. // SPDX-License-Identifier: AGPL-3.0-or-later // // Server je provede při startu v paměti nad souborem z node_modules. Každý // hledaný text musí v souboru být přesně jednou, jinak server nenastartuje: // nová verze ovladače se tak nepřeklopí potichu bez úprav. export const ZAPLATY = [ { soubor: 'scramjet-controller/dist/controller.api.js', popis: 'Dotaz, který přijde dřív, než se založí rám, počká až 10 s, místo aby hned spadl.', hledej: 'request:async e=>{let t=new URL(e.rawUrl).pathname,r=this.frames.find(e=>t.startsWith(e.prefix));if(!r)throw', nahrad: 'request:async e=>{let t=new URL(e.rawUrl).pathname,r=this.frames.find(e=>t.startsWith(e.prefix));' + 'for(let i=0;!r&&i<400;i++)await new Promise(e=>setTimeout(e,25)),r=this.frames.find(e=>t.startsWith(e.prefix));if(!r)throw', }, { soubor: 'scramjet-controller/dist/controller.api.js', popis: 'Ovladač si vezme id zvenku: stránka po novém načtení najde svůj ovladač pod stejnou adresou.', hledej: 'this.id=b(),this.config=j(c,t.config||{})', nahrad: 'this.id=t.id||b(),this.config=j(c,t.config||{})', }, { soubor: 'scramjet-controller/dist/controller.api.js', popis: 'Rám si vezme id zvenku ze stejného důvodu.', hledej: 'this.options=o,this.id=b(),this.prefix=this.controller.prefix+t', nahrad: 'this.options=o,this.id=o.id||b(),this.prefix=this.controller.prefix+t', }, { soubor: 'scramjet-controller/dist/controller.api.js', popis: 'Cookie zapsaná stránkou platí hned: ovladač ji vezme dřív, než si přečte uložené cookies, takže ji nese i navigace spuštěná hned po zápisu.', hledej: 'sendSetCookie:async({cookies:e,options:t})=>{await this.loadSavedCookies(!0),t?.clear&&this.cookieJar.clear(),' + 'this.applyCookieSyncEntries(e),await this.persistCookies(),await this.propagateCookieSync(e,t)}', nahrad: 'sendSetCookie:async({cookies:e,options:t})=>{let c=this.coralCekajici||(this.coralCekajici=[]);' + 't?.clear&&(this.cookieJar.clear(),c.length=0),this.applyCookieSyncEntries(e),c.push(...e);' + 'try{await this.loadSavedCookies(!0),t?.clear&&this.cookieJar.clear(),this.applyCookieSyncEntries(c),await this.persistCookies()}' + 'finally{for(let x of e){let i=c.indexOf(x);i>=0&&c.splice(i,1)}}' + 'await this.propagateCookieSync(e,t)}', }, { soubor: 'scramjet-controller/dist/controller.api.js', popis: 'Cookies načtené z úložiště nepřepíšou cookie, kterou stránka právě zapsala a ještě se neuložila.', hledej: 'e&&e.updatedAt>this.cookieUpdatedAt&&(this.cookieJar.load(e.cookies),this.cookieUpdatedAt=e.updatedAt)', nahrad: 'e&&e.updatedAt>this.cookieUpdatedAt&&(this.cookieJar.load(e.cookies),' + 'this.coralCekajici&&this.applyCookieSyncEntries(this.coralCekajici),this.cookieUpdatedAt=e.updatedAt)', }, ]; export function zaplatuj(soubor, text) { for (const z of ZAPLATY) { if (z.soubor !== soubor) continue; const kolik = text.split(z.hledej).length - 1; if (kolik !== 1) throw new Error(`Záplata „${z.popis}“ v ${soubor}: hledaný text je tam ${kolik}×, čekal jsem 1×.`); text = text.replace(z.hledej, () => z.nahrad); } return text; }