llamameta's picture
Create app.py
5c81d48 verified
raw
history blame
1.45 kB
# app.py
import streamlit as st
def escape_backticks(text: str) -> str:
"""Escape every backtick for safe embedding in a backtick-delimited JS template."""
return text.replace("`", "\\`")
st.set_page_config(page_title="CF Worker Escaper")
st.title("🔧 Cloudflare Worker Escaper")
st.markdown(
"""
Upload your **index.html** and **script.js**,
lalu app ini akan menghasilkan:
```js
const html = `...escaped-html...`;
const script = `...escaped-js...`;
```
siap copy–paste ke `worker.js`.
"""
)
uploaded_html = st.file_uploader("📄 Upload index.html", type=["html","htm"])
uploaded_js = st.file_uploader("📄 Upload script.js", type=["js"])
if uploaded_html and uploaded_js:
try:
html_text = uploaded_html.read().decode("utf-8")
js_text = uploaded_js.read().decode("utf-8")
except UnicodeDecodeError:
st.error("Failed to decode file. Pastikan encoding UTF-8.")
st.stop()
escaped_html = escape_backticks(html_text)
escaped_js = escape_backticks(js_text)
st.subheader("▶️ Generated Constants")
const_block = (
f"const html = `{escaped_html}`;\n\n"
f"const script = `{escaped_js}`;\n"
)
st.code(const_block, language="javascript")
st.download_button(
"💾 Download as constants.js",
const_block,
file_name="escaped_constants.js",
mime="application/javascript"
)