llamameta commited on
Commit
5c81d48
·
verified ·
1 Parent(s): 9ac06a2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ import streamlit as st
4
+
5
+ def escape_backticks(text: str) -> str:
6
+ """Escape every backtick for safe embedding in a backtick-delimited JS template."""
7
+ return text.replace("`", "\\`")
8
+
9
+ st.set_page_config(page_title="CF Worker Escaper")
10
+ st.title("🔧 Cloudflare Worker Escaper")
11
+
12
+ st.markdown(
13
+ """
14
+ Upload your **index.html** and **script.js**,
15
+ lalu app ini akan menghasilkan:
16
+ ```js
17
+ const html = `...escaped-html...`;
18
+ const script = `...escaped-js...`;
19
+ ```
20
+ siap copy–paste ke `worker.js`.
21
+ """
22
+ )
23
+
24
+ uploaded_html = st.file_uploader("📄 Upload index.html", type=["html","htm"])
25
+ uploaded_js = st.file_uploader("📄 Upload script.js", type=["js"])
26
+
27
+ if uploaded_html and uploaded_js:
28
+ try:
29
+ html_text = uploaded_html.read().decode("utf-8")
30
+ js_text = uploaded_js.read().decode("utf-8")
31
+ except UnicodeDecodeError:
32
+ st.error("Failed to decode file. Pastikan encoding UTF-8.")
33
+ st.stop()
34
+
35
+ escaped_html = escape_backticks(html_text)
36
+ escaped_js = escape_backticks(js_text)
37
+
38
+ st.subheader("▶️ Generated Constants")
39
+ const_block = (
40
+ f"const html = `{escaped_html}`;\n\n"
41
+ f"const script = `{escaped_js}`;\n"
42
+ )
43
+ st.code(const_block, language="javascript")
44
+
45
+ st.download_button(
46
+ "💾 Download as constants.js",
47
+ const_block,
48
+ file_name="escaped_constants.js",
49
+ mime="application/javascript"
50
+ )