29 lines
971 B
Python
29 lines
971 B
Python
from pathlib import Path
|
||
import shutil
|
||
|
||
p = Path('/opt/tylorindar-safelink/main.py')
|
||
t = p.read_text(encoding='utf-8')
|
||
if 'async def ld_fdpi_page' in t:
|
||
print('route already present')
|
||
raise SystemExit(0)
|
||
|
||
needle = '@app.get("/{code}")\nasync def redirect_shortlink'
|
||
insert = '''@app.get("/ld-fdpi", include_in_schema=False)
|
||
@app.get("/ld-fdpi/", include_in_schema=False)
|
||
async def ld_fdpi_page():
|
||
page = os.path.join(static_dir, "ld-fdpi.html")
|
||
if os.path.exists(page):
|
||
return FileResponse(
|
||
page,
|
||
media_type="text/html",
|
||
headers={"Cache-Control": "no-store, max-age=0"},
|
||
)
|
||
raise HTTPException(status_code=404, detail="LD FDPI sayfası bulunamadı.")
|
||
|
||
'''
|
||
if needle not in t:
|
||
raise SystemExit('catch-all route not found')
|
||
shutil.copy2(p, '/opt/tylorindar-safelink/backups/main.py.bak-ld-fdpi-page')
|
||
t = t.replace(needle, insert + needle, 1)
|
||
p.write_text(t, encoding='utf-8')
|
||
print('route added')
|