30 lines
1.4 KiB
Python
30 lines
1.4 KiB
Python
import pathlib,shutil,subprocess,datetime,time,urllib.request
|
|
target=pathlib.Path('/www/dk_project/dk_app/trilium/patched/main.cjs')
|
|
source=pathlib.Path('/tmp/trilium-korean-release/main.cjs')
|
|
text=source.read_text()
|
|
# Static assets are mapped by Express from the SAME jg variable into public/src.
|
|
# This is a URL prefix, not a new physical directory.
|
|
assert 'jg=`assets/v${CR.version}-ko-20260905`' in text
|
|
assert 'e.use(`/${jg}/src`,TQ(x2.default.join(n,"src")))' in text
|
|
assert 'assetPath:jl' in text
|
|
stamp=datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
|
|
backup=target.parent/('main.cjs.before-cache-fix-'+stamp)
|
|
shutil.copy2(target,backup)
|
|
try:
|
|
target.write_bytes(source.read_bytes())
|
|
subprocess.run(['docker','restart','trilium'],check=True,stdout=subprocess.DEVNULL)
|
|
for attempt in range(20):
|
|
try:
|
|
with urllib.request.urlopen('http://127.0.0.1:18082/assets/v0.95.0-ko-20260905/src/layout_commons.js',timeout=3) as response:
|
|
assert response.read(120).startswith(b'import triliumKoreanEditorTranslations')
|
|
with urllib.request.urlopen('http://127.0.0.1:18082/api/health-check',timeout=3) as response: assert response.status==200
|
|
print('Cache version fix verified. Backup: '+str(backup));break
|
|
except Exception:
|
|
if attempt==19:raise
|
|
time.sleep(1)
|
|
except Exception:
|
|
target.write_bytes(backup.read_bytes())
|
|
subprocess.run(['docker','restart','trilium'],check=True)
|
|
print('Rolled back cache version fix')
|
|
raise
|