29 lines
1.7 KiB
Python
29 lines
1.7 KiB
Python
"""Restore the pre-streaming OpenWebUI files after validating no later edits."""
|
|
import gzip
|
|
from pathlib import Path
|
|
from install_pcm_streaming import browser_patch
|
|
|
|
def main():
|
|
backend=Path('/app/backend/open_webui/routers/audio.py')
|
|
index=Path('/app/build/index.html')
|
|
assets=[p for p in Path('/app/build/_app/immutable/chunks').glob('*.js') if p.with_name(p.name+'.athena-pcm.bak').exists()]
|
|
if len(assets)!=1:raise RuntimeError('Expected exactly one backed-up call asset.')
|
|
asset=assets[0]
|
|
originals={p:p.with_name(p.name+'.athena-pcm.bak').read_text() for p in (backend,index,asset)}
|
|
addition=Path(__file__).with_name('pcm_route.txt').read_text()
|
|
expected={backend:originals[backend]+addition,index:originals[index].replace('</head>','<script src="/athena-pcm-stream.js"></script></head>'),asset:browser_patch(originals[asset])}
|
|
for p in originals:
|
|
if p.read_text() not in (originals[p],expected[p]):raise RuntimeError(f'Later changes detected in {p}; refusing to overwrite.')
|
|
if any(Path(str(p)+'.br').exists() for p in (asset,index)):import brotli
|
|
compile(originals[backend],str(backend),'exec')
|
|
for p,text in originals.items():
|
|
p.write_text(text)
|
|
if Path(str(p)+'.gz').exists():Path(str(p)+'.gz').write_bytes(gzip.compress(text.encode()))
|
|
if Path(str(p)+'.br').exists():Path(str(p)+'.br').write_bytes(brotli.compress(text.encode()))
|
|
Path('/app/build/athena-pcm-stream.js').unlink(missing_ok=True)
|
|
assert 'athenaPCM' not in asset.read_text()
|
|
assert 'athena-pcm-stream.js' not in index.read_text()
|
|
assert 'async def athena_pcm_speech(' not in backend.read_text()
|
|
print('Original pre-streaming playback and backend restored; restart and reload OpenWebUI.')
|
|
if __name__=='__main__':main()
|