From 8acd449966d1190f58382d65d01f91b110749b94 Mon Sep 17 00:00:00 2001 From: p7mj Date: Tue, 7 Apr 2026 10:24:16 -0400 Subject: [PATCH] added --- Lnkshrt/main.zip | Bin 0 -> 3274 bytes Lnkshrt/main/app.py | 74 +++++++++++++++++++++ Lnkshrt/main/generated_links/hi.html | 10 +++ Lnkshrt/main/templates/index.html | 95 +++++++++++++++++++++++++++ 4 files changed, 179 insertions(+) create mode 100644 Lnkshrt/main.zip create mode 100644 Lnkshrt/main/app.py create mode 100644 Lnkshrt/main/generated_links/hi.html create mode 100644 Lnkshrt/main/templates/index.html diff --git a/Lnkshrt/main.zip b/Lnkshrt/main.zip new file mode 100644 index 0000000000000000000000000000000000000000..17c22f9731aa141d81a8f51edf857ae63ed3e3ee GIT binary patch literal 3274 zcmZ{nc{J2*8^;F`vP6@e?2KWEW^CD)tdp!QBTLpAGb0biT9z40wjtAG$yWBYF`_}) zYo;tMBukhmX%PttuX=Lc=e*DB`knK;?{j|F_d3`8`{R3kZaZt1eL%pkNHxYIesBJ~ zSa;R{4}X-Z-JU6jcT;@5QQnt5{_^&6L;9mG1^tmQ1K0scMtDSH+O3J+om3Sj06=Un ziJw2j@2>!4c7`6RON|Q`S`a%lZe@E_#~_<>TUdvpc-QN?cdvl7b+YmPN1wo5pP4#w zfFnoV?5Fj-TiwF`&^A2L=79T&E*Et&gpA6}SKCMSEVzF;Y>kCu7lcSt9C}V4Ke6E7 zRtC;D9V+gb45yDBJex2cfBwCYnJe+jn7yjY3R~cv5oG&GqFALH5@~EQd@nBuRO&C) zV=BEcc-+Ut(ajed&-9n^VvOX|^T_jtKEqt68+<)d$aBo%^4E>4Y!3E)1Hl|p(CaLJ z|FU1_uiZI+Fz@^Tb{_y>#Q^{u*gd}o1_Qx_;hY0bGRzNdeRezQt2C<5pI{R3vXlcD zm>2KJ6g#MCtiljy=zVkz4Ye&y+@2hzeOV6R?U61sp(EO*Fl4asFHAni@`~H^ZohGB?xSwbI&H z>oM7xU@85KG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iFo3ZC4^OP zr+2m6(*+(TrV#wam*~+Nf@e^X)`55lonb}=Wh;TS3O{teDM=YDUcoA>(o9maNMCGb z$#Xpgojog$gnuZ#2`>v6;86)j*=yC>`hNj8DHW;&j z4RRm*hI5CE4?<>DHwhR;f6gV!77yn1d>N-S(d(9ZpB=2?8h^)8wVG6GWhIbekf~U7 zR<+G!e)0PZ)v(sSQ#j|NKI4wd7tE(|^^f7o^rj0_DKlR`fCYKqLVAUnuwt>I1@&}i zw~Q;eX+rnwbI=#F5}m2m(y*FNb0W{+S zHrNzqD0vVX^94-RxyhKdf|;Bbf&LFUJ-7AigVQcbDZSHiD-)Zbc2aOH=tg^PotcBP zR%0ldtg2jto&wEA{n^Wll$vV?w!J3IHk{r_#W@;{CddXVEqTr3IBUz_%%9qW7BAL=K}Ft_|HM|-~RvKDA^S^ f#>le$OZ?x#VrR{|^BDkO+j*jP+SB|6)qwv1B!P?G literal 0 HcmV?d00001 diff --git a/Lnkshrt/main/app.py b/Lnkshrt/main/app.py new file mode 100644 index 0000000..99576d1 --- /dev/null +++ b/Lnkshrt/main/app.py @@ -0,0 +1,74 @@ +from flask import Flask, render_template, request +import os +import re # <--- FIX 1: Added missing import + +app = Flask(__name__) + +# Ensure a directory exists to hold the generated links +# This makes sure we don't clutter the root directory +OUTPUT_DIR = "generated_links" +if not os.path.exists(OUTPUT_DIR): + os.makedirs(OUTPUT_DIR) + +@app.route('/') +def home(): + return render_template('index.html') + +def is_valid_subdirectory(name): + pattern = r"^[a-zA-Z0-9_-]+$" + # Added check to ensure 'name' isn't None + return bool(name and re.match(pattern, name)) + +def is_valid_link(url): + pattern = r"^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$" + return bool(url and re.match(pattern, url.lower())) + +def create_redirect_html(filename, target_url): + # Ensure target_url has a protocol so the browser doesn't think it's a local file + if not target_url.startswith(('http://', 'https://')): + target_url = 'https://' + target_url + + if not filename.endswith(".html"): + filename += ".html" + + # Save inside the output directory + file_path = os.path.join(OUTPUT_DIR, filename) + + html_content = f""" + + + + Redirecting... + + +

If you are not redirected, click here.

+ +""" + + try: + with open(file_path, "w", encoding="utf-8") as file: + file.write(html_content) + return filename + except Exception as e: + print(f"An error occurred: {e}") + return None + +@app.route('/submit', methods=['POST']) +def submit(): + val1 = request.form.get('first_name') # The URL + val2 = request.form.get('second_name') # The New Name + + # FIX 2: Validate correctly and use the right order in the function call + if is_valid_link(val1) and is_valid_subdirectory(val2): + # We want: create_redirect_html(filename, destination) + generated_file = create_redirect_html(val2, val1) + + if generated_file: + return f"Success! Created p.wholeworldcoding.com/{generated_file}" + else: + return "Error: Could not write file.", 500 + else: + return "Invalid Input! Ensure the link is valid and the page name has no slashes.", 400 + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/Lnkshrt/main/generated_links/hi.html b/Lnkshrt/main/generated_links/hi.html new file mode 100644 index 0000000..647a720 --- /dev/null +++ b/Lnkshrt/main/generated_links/hi.html @@ -0,0 +1,10 @@ + + + + + Redirecting... + + +

If you are not redirected, click here.

+ + \ No newline at end of file diff --git a/Lnkshrt/main/templates/index.html b/Lnkshrt/main/templates/index.html new file mode 100644 index 0000000..dda7149 --- /dev/null +++ b/Lnkshrt/main/templates/index.html @@ -0,0 +1,95 @@ + + + + + + + + +
+
+
+

Link Shortener

+

Insert a link and shorten it for sharing!

+
+ +
+ + +
+ +
+ + +
+ + +
+ +
+
+ + + + + \ No newline at end of file