those are some haxxor moments
This commit is contained in:
1 parent
88d4ce7320
commit
a8e5c26d55
7 files changed
+936
-331
No files matched your search
@@ -0,0 +1,4 @@
|
||||
db_user = user
|
||||
db_password = pa55w0rd
|
||||
db_host = 127..1
|
||||
db_name = database
|
||||
+11
-1
@@ -8,13 +8,21 @@ import http.server as serverhttp
|
||||
from the_server_handler import ServerLogic, connectionSettings, get_that_connection
|
||||
import mysql.connector as sqlcon
|
||||
|
||||
import sys
|
||||
|
||||
if not (
|
||||
sys.version_info.major > 3
|
||||
or (sys.version_info.major == 3 and sys.version_info.minor >= 11)
|
||||
):
|
||||
raise Exception(f"python 3.11 up, u running {sys.version}")
|
||||
|
||||
PORT = 8088
|
||||
def runServer():
|
||||
# while True:
|
||||
# connectio,e = get_that_connection(**connectionSettings)
|
||||
# if not e:
|
||||
# break
|
||||
server = serverhttp.HTTPServer(("", 8088), ServerLogic)
|
||||
server = serverhttp.HTTPServer(("", PORT), ServerLogic)
|
||||
try:
|
||||
server.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
@@ -23,6 +31,8 @@ def runServer():
|
||||
raise SystemExit("\nctrl c")
|
||||
except BaseException as e:
|
||||
print(e)
|
||||
# finally:
|
||||
# print("why am i printing")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+644
-280
@@ -1,19 +1,41 @@
|
||||
import http.server as serverhttp
|
||||
import mysql.connector as sqlcon
|
||||
from dotenv import dotenv_values
|
||||
import json
|
||||
# import urllib, sql
|
||||
import warnings
|
||||
|
||||
# import chardet
|
||||
from http import HTTPStatus as rescode
|
||||
import mimetypes
|
||||
|
||||
# import traceback
|
||||
import os
|
||||
from typing import Literal
|
||||
import mysql.connector as sqlcon
|
||||
|
||||
# from mysql.connector import errorcode
|
||||
from dotenv import dotenv_values
|
||||
from urllib import parse as urlparse # lmao the normal person
|
||||
import json
|
||||
from functools import wraps
|
||||
from pathlib import Path
|
||||
from dotenv import dotenv_values
|
||||
|
||||
|
||||
# import urllib, sql
|
||||
class ServerLogic(serverhttp.BaseHTTPRequestHandler): ...
|
||||
|
||||
|
||||
webrootdir = "webRoot"
|
||||
if os.path.isdir(webrootdir): # unfuckable
|
||||
os.chdir(webrootdir) # move to safe part of world
|
||||
curdir = os.path.curdir or os.getcwd()
|
||||
print(os.path.curdir, os.getcwd())
|
||||
from things import (
|
||||
process_datetime_DICTS,
|
||||
process_datetime_tuples,
|
||||
funny_tuples_to_dicts_processor,
|
||||
getnewdicttranslate,
|
||||
)
|
||||
|
||||
|
||||
from dotenv import dotenv_values
|
||||
|
||||
dotenv_values1 = dotenv_values() ## change so fast
|
||||
dotenv_values1 = dotenv_values() ## change so fast
|
||||
db_name = dotenv_values1["db_name"]
|
||||
|
||||
comectomKeys = ["user", "password", "host", "database"]
|
||||
@@ -26,6 +48,8 @@ comectomtrk = {
|
||||
connectionSettings = {
|
||||
**getnewdicttranslate(dotenv_values1, comectomtrk),
|
||||
"raise_on_warnings": True,
|
||||
"pool_name": "aPool", # wow!
|
||||
"pool_size": 3,
|
||||
}
|
||||
|
||||
|
||||
@@ -40,18 +64,251 @@ def get_that_connection(
|
||||
return (connectio, None)
|
||||
|
||||
|
||||
def better_connection_actuallyworking(connectionSettings: dict):
|
||||
"""
|
||||
arg for func:
|
||||
1. conn (do you hate life)
|
||||
2. thingElse
|
||||
"""
|
||||
|
||||
def ONETHING(func):
|
||||
@wraps(func)
|
||||
def huh(*a, **kw):
|
||||
# conn = sqlcon.connect(**connectionSettings)
|
||||
try:
|
||||
with sqlcon.connect(
|
||||
**connectionSettings
|
||||
) as conn: # HOLY SHIT THANK YOU CHAT GPT
|
||||
return func(conn, *a, **kw)
|
||||
except sqlcon.Error as e:
|
||||
print("oh hey errorSql FromtheWrapper", e)
|
||||
raise e
|
||||
except Exception as e:
|
||||
print("betterConnection NoWorked", e)
|
||||
raise e
|
||||
# finally: # they run even after return! try finally gon go crazy
|
||||
# conn.close()
|
||||
|
||||
return huh
|
||||
|
||||
return ONETHING
|
||||
|
||||
|
||||
@better_connection_actuallyworking(connectionSettings)
|
||||
def funnying_funnytheFunnier(
|
||||
conn: sqlcon.MySQLConnection | sqlcon.pooling.PooledMySQLConnection,
|
||||
):
|
||||
return conn # WHAT NOT TO DO
|
||||
|
||||
|
||||
# if __name__ == "__main__":
|
||||
# conn = funnying_funnytheFunnier()
|
||||
# print(f"Connection object: {conn}")
|
||||
# print(f"Internal connection (_cnx): {getattr(conn, '_cnx', 'Not available')}")
|
||||
# try:
|
||||
# with conn.cursor() as cur:
|
||||
# cur.execute('SELECT "Hello world"')
|
||||
# print(cur.fetchall())
|
||||
# except Exception as e:
|
||||
# traceback.print_exc()
|
||||
# if __name__ == "__main__":
|
||||
# print("a separator")
|
||||
# with sqlcon.connect( pool_name = "ig", **connectionSettings) as conn:
|
||||
# print(f"Connection object: {conn}")
|
||||
# print(f"Internal connection (_cnx): {getattr(conn, '_cnx', 'Not available')}")
|
||||
# with conn.cursor() as cur:
|
||||
# cur.execute('SELECT "Hello world!~"') #gayà
|
||||
# print(cur.fetchall())
|
||||
|
||||
|
||||
@better_connection_actuallyworking(connectionSettings)
|
||||
def fulltable(
|
||||
conn: sqlcon.MySQLConnection | sqlcon.pooling.PooledMySQLConnection,
|
||||
tbaleName: str,
|
||||
returnType: Literal["zip", "dict"] = "dict",
|
||||
) -> dict | tuple[list[tuple], list[str]]: # connection is inserted in by the thing
|
||||
print(tbaleName)
|
||||
if not (tableName := ifTableInDB(db_name, tbaleName)):
|
||||
raise sqlcon.DatabaseError(f"{tbaleName} where tELL ME")
|
||||
ifdict = returnType == "dict"
|
||||
try:
|
||||
with conn.cursor(dictionary=ifdict, prepared=True) as cur:
|
||||
res = cur.execute(f"select * from {tableName}")
|
||||
r = cur.fetchall()
|
||||
if ifdict:
|
||||
return r
|
||||
this = getColumename(tableName)
|
||||
return this, r
|
||||
except sqlcon.Error as e:
|
||||
print("table has a", e)
|
||||
raise e
|
||||
except Exception as e:
|
||||
print("Hi. Your except saved yo ass:", e)
|
||||
raise e
|
||||
|
||||
|
||||
@better_connection_actuallyworking(connectionSettings)
|
||||
def getColumename(
|
||||
conn: sqlcon.MySQLConnection | sqlcon.pooling.PooledMySQLConnection, tbaleName: str
|
||||
) -> list[str]:
|
||||
print(tbaleName)
|
||||
try:
|
||||
with conn.cursor(prepared=True) as cur:
|
||||
res = cur.execute(
|
||||
"select column_name from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = ?",
|
||||
(tbaleName,),
|
||||
)
|
||||
coln = cur.fetchall()
|
||||
for a, i in enumerate(coln):
|
||||
coln[a] = i[0]
|
||||
return coln
|
||||
except sqlcon.Error as e:
|
||||
print("getColumename has a", e)
|
||||
raise e
|
||||
except Exception as e:
|
||||
print("Hi. Your except saved yo ass:", e)
|
||||
raise e
|
||||
|
||||
|
||||
@better_connection_actuallyworking(connectionSettings)
|
||||
def getTableNmaes(
|
||||
conn: sqlcon.MySQLConnection | sqlcon.pooling.PooledMySQLConnection, db_name: str
|
||||
) -> list[str]:
|
||||
try:
|
||||
with conn.cursor(prepared=True) as cur:
|
||||
res = cur.execute(
|
||||
"select table_name from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = ?",
|
||||
(db_name,),
|
||||
)
|
||||
coln = cur.fetchall()
|
||||
for a, i in enumerate(coln):
|
||||
coln[a] = i[0]
|
||||
return coln
|
||||
except sqlcon.Error as e:
|
||||
print("getTableNmaes has a", e)
|
||||
raise e
|
||||
except Exception as e:
|
||||
print("Hi. Your except saved yo ass:", e)
|
||||
raise e
|
||||
|
||||
|
||||
tableNamesListsth: list = getTableNmaes(db_name)
|
||||
tabletbale = "tbale" if "tbale" in tableNamesListsth else None ## hard Coding
|
||||
colnmaes = getColumename(tabletbale)
|
||||
# {"neme": "one", "kewod": "two", "cod": "three", "expi": "four"}
|
||||
severColum = ["neme", "kewod", "cod", "expi"]
|
||||
clietColum = ["one", "two", "three", "four"]
|
||||
scTrtb = dict(zip(severColum, clietColum))
|
||||
csTrtb = dict(zip(clietColum, severColum))
|
||||
print(scTrtb, csTrtb)
|
||||
|
||||
|
||||
@better_connection_actuallyworking(connectionSettings)
|
||||
def ifTableInDB(
|
||||
conn: sqlcon.MySQLConnection | sqlcon.pooling.PooledMySQLConnection,
|
||||
db_name: str,
|
||||
tabN: str,
|
||||
) -> str | None:
|
||||
"""you dont believe it but it works like a true false, as python is good enough
|
||||
|
||||
if (vari := ifTableInDB(dbname, tablename)):"""
|
||||
try:
|
||||
with conn.cursor(prepared=True) as cur:
|
||||
|
||||
res = cur.execute(
|
||||
"select table_name from information_schema.tables where table_schema = ? and table_name = ? Limit 1;",
|
||||
(db_name, tabN),
|
||||
)
|
||||
a = cur.fetchall()
|
||||
if a:
|
||||
return a[0][0] # deadass dont understand why this shi weird like that
|
||||
return
|
||||
except sqlcon.Error as e:
|
||||
print("getTableNmaes has a", e)
|
||||
raise e
|
||||
except Exception as e:
|
||||
print("Hi. Your except saved yo ass:", e)
|
||||
raise e
|
||||
|
||||
|
||||
notfound404 = b"""<h1>404</h1><p>where u at</p>"""
|
||||
notallowed403 = b"""<h1>403</h1><p>tf u doin</p>"""
|
||||
|
||||
|
||||
def openFileManually(
|
||||
theGuy: ServerLogic,
|
||||
webDir: str,
|
||||
defaultFile: str | None = "index.html",
|
||||
dir: str | None = None,
|
||||
headers: dict | None = None,
|
||||
rootDir: str | None = curdir,
|
||||
) -> None:
|
||||
print(webDir, dir, headers)
|
||||
if dir:
|
||||
filename = dir
|
||||
else:
|
||||
filename = webDir.lstrip("/")
|
||||
path = Path(rootDir, filename)
|
||||
print(path)
|
||||
if not path.exists():
|
||||
theGuy.header_setup(rescode.NOT_FOUND)
|
||||
if path.is_dir():
|
||||
path /= defaultFile
|
||||
if not path.is_file():
|
||||
theGuy.header_setup(rescode.NOT_FOUND)
|
||||
theGuy.wfile.write(notfound404)
|
||||
print(path)
|
||||
fileMime, fileEncoding = mimetypes.guess_type(path)
|
||||
print(fileMime, fileEncoding)
|
||||
finalMime = fileMime
|
||||
a = {}
|
||||
if headers:
|
||||
gay = next(
|
||||
(i for i in reversed(headers) if i.casefold() == "content-type"), None
|
||||
)
|
||||
if gay:
|
||||
print(gay, headers[gay])
|
||||
headerMime = headers[gay]
|
||||
if headerMime not in mimetypes.types_map.values():
|
||||
warnings.warn(
|
||||
f"what is {headerMime}. mimetypes say {fileMime} basically uhh you uhh do this for me please: if you dont know what it is dont include it",
|
||||
UserWarning,
|
||||
)
|
||||
|
||||
finalMime = headerMime
|
||||
a["content-type"] = finalMime
|
||||
headers |= a
|
||||
theGuy.header_setup(headers=headers or a)
|
||||
|
||||
with open(path, "rb") as file:
|
||||
theGuy.wfile.write(file.read())
|
||||
return
|
||||
|
||||
|
||||
## USE THE @ if you know how
|
||||
### i surely dont know how
|
||||
|
||||
|
||||
class ServerLogic(serverhttp.BaseHTTPRequestHandler):
|
||||
|
||||
def youJustHaveToDoTheseStuff(self):
|
||||
def __init__(self, *a, **kw): # AHAHHAHAHAHAHAHAHA
|
||||
super().__init__(*a, **kw)
|
||||
|
||||
def reallyEveryTime(self) -> tuple:
|
||||
# print("all headers:\n", self.headers)
|
||||
print("the path is : ", self.path)
|
||||
print(
|
||||
"connected at: ",
|
||||
self.headers.get("X-Forwarded-For", "directly").split(", ")[0],
|
||||
)
|
||||
print(urlparse.urlparse(self.path))
|
||||
|
||||
# table = 'tbale'
|
||||
# print("there is no" ,table,ifTableInDB(db_name, table))
|
||||
# tableli = getTableNmaes(db_name)
|
||||
# print(getColumename(tableli[0])) # i know damn well
|
||||
# print(fulltable(tableli[0]))
|
||||
return
|
||||
|
||||
def close(self):
|
||||
try:
|
||||
@@ -63,310 +320,417 @@ class ServerLogic(serverhttp.BaseHTTPRequestHandler):
|
||||
raise SystemExit("truly the /close")
|
||||
|
||||
def header_setup(
|
||||
self, code: int = 200, headers: dict = {"Content-type": "text/html"}
|
||||
self,
|
||||
code: int | rescode = rescode.OK,
|
||||
headers: dict = {"Content-type": "text/html"},
|
||||
):
|
||||
"""
|
||||
code as int and headers as keyvalue pairs.
|
||||
"""
|
||||
|
||||
self.send_response(code)
|
||||
if headers is not None:
|
||||
for key in headers:
|
||||
self.send_header(key, headers[key]) # why!
|
||||
for key, value in headers.items():
|
||||
self.send_header(key, value) # why!
|
||||
self.end_headers()
|
||||
|
||||
def do_GET(self):
|
||||
self.youJustHaveToDoTheseStuff()
|
||||
self.reallyEveryTime()
|
||||
pathObj: urlparse.ParseResult = urlparse.urlparse(self.path)
|
||||
match pathObj.path:
|
||||
case "/close":
|
||||
return self.close()
|
||||
case a if a in (
|
||||
thisATable := {
|
||||
"/": {
|
||||
# {"dir" : "index.html",}
|
||||
},
|
||||
"/index/style.css": {
|
||||
# "headers": {"Content-Type": "text/css"}
|
||||
},
|
||||
"/index/script.js": {
|
||||
"headers": {"Content-Type": "text/javascript"} # bout Stupid
|
||||
},
|
||||
}
|
||||
):
|
||||
return openFileManually(
|
||||
self, a, **thisATable[a]
|
||||
) # i can waste objects!!!! simple or empty dicts have same id
|
||||
|
||||
if self.path == "/close":
|
||||
return self.close()
|
||||
# (connectio, eror) = get_that_connection(connectionSettings)
|
||||
# if eror:
|
||||
# print("coneti eror: ", eror)
|
||||
# return
|
||||
# # HE. MUST. AVOID. THE. TRYCATCH
|
||||
# with connectio.cursor(buffered=True) as cur:
|
||||
# try:
|
||||
# res = cur.execute("select * from tbale")
|
||||
# w = cur.fetchall()
|
||||
# res = cur.execute(
|
||||
# "select column_name from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'tbale'"
|
||||
# )
|
||||
# anotherone2 = cur.fetchall()
|
||||
# except Exception as e:
|
||||
# print(e)
|
||||
# return # return ealy no else
|
||||
|
||||
if self.path == "/":
|
||||
self.header_setup()
|
||||
with open("index.html", "rb") as file:
|
||||
self.wfile.write(file.read())
|
||||
return
|
||||
if self.path == "/style.css": # allowed files is funny
|
||||
self.header_setup(headers={"Content-Type": "text/css"})
|
||||
with open("style.css", "rb") as file:
|
||||
self.wfile.write(file.read())
|
||||
return
|
||||
if self.path == "/script.js": #
|
||||
self.header_setup(
|
||||
headers={"Content-Type": "text/javascript"}
|
||||
) ## never knew!
|
||||
with open("script.js", "rb") as file:
|
||||
self.wfile.write(file.read())
|
||||
return
|
||||
|
||||
(connectio, eror) = get_that_connection(connectionSettings)
|
||||
if eror:
|
||||
print("coneti eror: ", eror)
|
||||
return
|
||||
# HE. MUST. AVOID. THE. TRYCATCH
|
||||
with connectio.cursor(buffered=True) as cur:
|
||||
try:
|
||||
res = cur.execute("select * from tbale")
|
||||
w = cur.fetchall()
|
||||
res = cur.execute(
|
||||
"select column_name from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'tbale'"
|
||||
case "/endp":
|
||||
ncnw = process_datetime_DICTS(fulltable(tabletbale))
|
||||
efg = json.dumps(
|
||||
[ # haha yeah right why cant you do it client side
|
||||
## BIGGER QUESTION is that this is 2 of the same data
|
||||
getnewdicttranslate(
|
||||
i,
|
||||
scTrtb,
|
||||
)
|
||||
for i in ncnw
|
||||
]
|
||||
)
|
||||
anotherone2 = cur.fetchall()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return # return ealy no else
|
||||
c = process_datetime_tuples(w)
|
||||
ncnw = funny_tuples_to_dicts_processor(anotherone2, c)
|
||||
|
||||
if self.path == "/endp":
|
||||
efg = json.dumps(
|
||||
[ # haha yeah right why cant you do it client side
|
||||
## BIGGER QUESTION is that this is 2 of the same data
|
||||
getnewdicttranslate(
|
||||
i,
|
||||
{"neme": "one", "kewod": "two", "cod": "three", "expi": "four"},
|
||||
)
|
||||
for i in ncnw
|
||||
]
|
||||
)
|
||||
self.header_setup(headers={"Content-type": "application/json"})
|
||||
# self.wfile.write(str(c).encode())
|
||||
# self.wfile.write(str(anotherone2).encode())
|
||||
self.wfile.write(str(efg).encode())
|
||||
return
|
||||
else:
|
||||
wd = [(a["neme"], a["kewod"], a["cod"]) for a in ncnw]
|
||||
# print(wd)
|
||||
for a, v, c in wd:
|
||||
# print(a,v)
|
||||
# print(self.path, a)
|
||||
if self.path.lstrip("/") == a:
|
||||
if c == 200:
|
||||
self.header_setup(c, {"Content-type": "text/plain"})
|
||||
self.wfile.write(v.encode()) if v else None ## i mean crashes are handled anyway things keep running as is
|
||||
elif c in [301, 302]:
|
||||
self.header_setup(c, {"Location": v})
|
||||
return
|
||||
self.header_setup(404)
|
||||
self.wfile.write(
|
||||
b"""
|
||||
<h1>404</h1>
|
||||
<p>where u at</p>
|
||||
"""
|
||||
)
|
||||
self.header_setup(headers={"Content-type": "application/json"})
|
||||
# self.wfile.write(str(c).encode())
|
||||
# self.wfile.write(str(anotherone2).encode())
|
||||
self.wfile.write(str(efg).encode())
|
||||
return
|
||||
# wd = [(a["neme"], a["kewod"], a["cod"]) for a in ncnw]
|
||||
# print(wd)
|
||||
# npnd = {i["neme"]: i for i in ncnw} # simple as
|
||||
# # for p in npnd:
|
||||
# a = npnd.get(self.path.lstrip("/"))
|
||||
with sqlcon.connect(**connectionSettings) as n:
|
||||
with n.cursor(prepared=True) as r:
|
||||
r.execute(
|
||||
f"select neme, kewod, cod from {tabletbale} where neme = ?;",
|
||||
(self.path.lstrip("/"),),
|
||||
)
|
||||
ee = r.fetchone()
|
||||
if not ee:
|
||||
self.header_setup(rescode.NOT_FOUND)
|
||||
self.wfile.write(notfound404)
|
||||
return
|
||||
v, c = ee[1], ee[2] # value, code
|
||||
# print(a,v)
|
||||
# print(self.path, a)
|
||||
# if self.path.lstrip("/") == p["neme"]:
|
||||
# a, v, c
|
||||
# print(v, c)
|
||||
if v:
|
||||
if c == rescode.OK:
|
||||
self.header_setup(c, {"Content-type": "text/plain;charset=utf-8"})
|
||||
self.wfile.write(v.encode())
|
||||
## i mean crashes are handled anyway things keep running as is
|
||||
# what bro sayin
|
||||
return
|
||||
elif c // 100 == 2:
|
||||
pass
|
||||
elif c // 100 == 3: # redirects
|
||||
self.header_setup(c, {"Location": v})
|
||||
return
|
||||
# case what????
|
||||
self.header_setup(rescode.OK)
|
||||
self.wfile.write(
|
||||
f'<p>u at <a href=".{pathObj.path}">{pathObj.path}</a>. probably content is None python said so idfk</p>'.encode()
|
||||
)
|
||||
if c == rescode.OK:
|
||||
self.wfile.write(b"<p>this shouldve been a text file</p>")
|
||||
elif c // 100 == 3:
|
||||
self.wfile.write(b"<p>this shouldve been a redirect</p>")
|
||||
return
|
||||
|
||||
def do_POST(self):
|
||||
self.youJustHaveToDoTheseStuff()
|
||||
class lmao(Exception):
|
||||
def __init__(
|
||||
self, rc: int | rescode | None = None, case: int | None = None, *a, **kw
|
||||
):
|
||||
"""
|
||||
rc: rescode
|
||||
case: special thingy. truly the hax
|
||||
msg: msg!!!!
|
||||
"""
|
||||
super().__init__(rc, case, *a, **kw)
|
||||
self.stupid = case
|
||||
if type(rc) == int:
|
||||
print("what")
|
||||
self.ldarescode = rescode(rc) # why do i have to do this
|
||||
print(self.ldarescode)
|
||||
elif type(rc) == rescode:
|
||||
print("good")
|
||||
self.ldarescode = rc
|
||||
print(self.ldarescode)
|
||||
|
||||
@property
|
||||
def ldacause(self):
|
||||
return self.__cause__
|
||||
|
||||
self.reallyEveryTime()
|
||||
match self.path:
|
||||
case "/close":
|
||||
return self.close()
|
||||
|
||||
case "/endp":
|
||||
self.header_setup(headers={"Content-type": "text/plain"})
|
||||
content_type = self.headers.get("Content-Type")
|
||||
content_length = int(self.headers.get("Content-Length"))
|
||||
with self.rfile as r:
|
||||
post_data_bytes = r.read(content_length)
|
||||
## read how many bytes is the content length
|
||||
case p if p != "/endp": # self.path
|
||||
self.header_setup(rescode.FORBIDDEN)
|
||||
self.wfile.write(notallowed403)
|
||||
return
|
||||
try:
|
||||
content_type = self.headers.get("Content-Type", str())
|
||||
content_length = int(self.headers.get("Content-Length"), int())
|
||||
print("cccc", content_type, content_length)
|
||||
with self.rfile as r:
|
||||
post_data_bytes = r.read(content_length)
|
||||
## read how many bytes is the content length
|
||||
|
||||
self.wfile.write(
|
||||
b"Ive got a POST at "
|
||||
+ self.headers.get("Origin", "nowhere lmao").encode()
|
||||
+ b" from "
|
||||
+ self.headers.get("Referer", "who?").encode()
|
||||
+ b" with the following data:\n"
|
||||
+ post_data_bytes
|
||||
if content_type != "application/json":
|
||||
raise lmao(rescode.OK, 1)
|
||||
# self.wfile.write(b"its of the type: ")
|
||||
# self.wfile.write(content_type.encode())
|
||||
|
||||
try:
|
||||
data_dict: dict = json.loads(post_data_bytes)
|
||||
##
|
||||
except json.JSONDecodeError as e:
|
||||
raise lmao(rescode.BAD_REQUEST, 2) from e
|
||||
# print(e)
|
||||
# self.header_setup(
|
||||
# code=rescode.BAD_REQUEST,
|
||||
# headers={"Content-type": "text/plain"},
|
||||
# )
|
||||
# self.wfile.write(
|
||||
# b"haha your data sucks (json.loads is not necessarily strict/bad, its just u sent bad): "
|
||||
# + str(e).encode()
|
||||
# )
|
||||
|
||||
##
|
||||
# print((*data_dict.keys(), *data_dict.values()))
|
||||
##
|
||||
if data_dict.get("from") == "ldlda":
|
||||
# ogdata_dict = data_dict.copy() ## as this isnt deep copy also because the thing is short lived i guess i dont ever need this for anything
|
||||
# print("b4: ", data_dict, ogdata_dict) ## initial state for comp
|
||||
data_dict = getnewdicttranslate(
|
||||
# ogdata_dict[
|
||||
data_dict[
|
||||
"data"
|
||||
], ## this would actually change ogdatadict.data ## OR NOT
|
||||
csTrtb,
|
||||
)
|
||||
# print(
|
||||
# "aftr: ", data_dict, ogdata_dict
|
||||
# ) ## notice that the thing changed.
|
||||
##
|
||||
|
||||
if content_type == "application/json":
|
||||
wwwww = tuple(key for key in data_dict if key in colnmaes)
|
||||
# hmmm
|
||||
# repated cod? huh?
|
||||
|
||||
updated_Verybreakablequery_insert_into = (
|
||||
f"insert into {tabletbale} "
|
||||
+ "({0}) values ({0})".format( ## LEARN PYTHON SQL this is nasty
|
||||
",".join(("{}",) * len(wwwww)) # incredibly real update
|
||||
).format(*wwwww, *("?",) * len(wwwww))
|
||||
)
|
||||
print(
|
||||
wwwww,
|
||||
tuple(data_dict[w] for w in wwwww),
|
||||
updated_Verybreakablequery_insert_into,
|
||||
sep="\n",
|
||||
)
|
||||
##
|
||||
try:
|
||||
with sqlcon.connect(**connectionSettings) as conn:
|
||||
# a = connectio.autocommit # archiver
|
||||
conn.autocommit = (
|
||||
True # where is my ASDFCKjugsadkfjywgefdklajegdlagf
|
||||
)
|
||||
try:
|
||||
data_dict: dict = json.loads(post_data_bytes)
|
||||
##
|
||||
except Exception as e:
|
||||
print(e)
|
||||
self.wfile.write(
|
||||
b"\nhaha your data sucks (json.load is strict/bad): "
|
||||
+ str(e).encode()
|
||||
)
|
||||
return
|
||||
##
|
||||
(connectio, eror) = get_that_connection(connectionSettings)
|
||||
##
|
||||
if eror:
|
||||
print("coneti eror: ", eror)
|
||||
self.wfile.write(
|
||||
b"the thing cant even start like what f: "
|
||||
+ str(eror).encode()
|
||||
)
|
||||
return
|
||||
##
|
||||
# print((*data_dict.keys(), *data_dict.values()))
|
||||
|
||||
with connectio.cursor(buffered=True) as cur:
|
||||
try:
|
||||
anotherone = cur.execute(
|
||||
"select column_name from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'tbale'"
|
||||
)
|
||||
this_list_of_colnaes = cur.fetchall()
|
||||
except Exception as e:
|
||||
print("to day i cant get the damn colums: ", e)
|
||||
this_list_of_colnaes = [u[0] for u in this_list_of_colnaes] # weird
|
||||
##
|
||||
if data_dict.get("from") == "ldlda":
|
||||
ogdata_dict = data_dict.copy() ## as this isnt deep copy also because the thing is short lived i guess i dont ever need this for anything
|
||||
print("b4: ",data_dict, ogdata_dict) ## initial state for comp
|
||||
data_dict = getnewdicttranslate(
|
||||
ogdata_dict["data"], ## this would actually change ogdatadict.data
|
||||
{
|
||||
"one": "neme",
|
||||
"two": "kewod",
|
||||
"three": "cod",
|
||||
"four": "expi",
|
||||
},
|
||||
)
|
||||
print("aftr: ",data_dict, ogdata_dict) ## notice that the thing changed.
|
||||
##
|
||||
|
||||
wwwww = tuple(
|
||||
key for key in data_dict if key in this_list_of_colnaes
|
||||
)
|
||||
# hmmm
|
||||
# repated cod? huh?
|
||||
|
||||
updated_Verybreakablequery_insert_into = ( ## LEARN PYTHON SQL this is nasty
|
||||
"insert into tbale ({0}) values ({0})".format(
|
||||
",".join(["{}"] * len(wwwww))
|
||||
).format(*wwwww, *("?",) * len(wwwww))
|
||||
)
|
||||
print(
|
||||
wwwww,
|
||||
tuple(data_dict[w] for w in wwwww),
|
||||
updated_Verybreakablequery_insert_into,
|
||||
sep="\n",
|
||||
)
|
||||
|
||||
with connectio.cursor(prepared=True) as cur:
|
||||
connectio.autocommit = True
|
||||
try:
|
||||
res = cur.execute(
|
||||
with conn.cursor(prepared=True) as cur:
|
||||
conn.autocommit = True # WHERE!!!! IS COMMIT!!!!!!!
|
||||
cur.execute(
|
||||
updated_Verybreakablequery_insert_into,
|
||||
tuple(data_dict[w] for w in wwwww),
|
||||
# multi=True,
|
||||
)
|
||||
print("insert into qure: ", cur.fetchall())
|
||||
another = cur.execute("select * from tbale")
|
||||
w2f = cur.fetchall()
|
||||
##
|
||||
except Exception as e:
|
||||
print("execute err: ", e)
|
||||
self.wfile.write(
|
||||
b"\n is it very much Invalid: " + str(e).encode()
|
||||
conn.commit() # WHYWHYWHYWHYWHYWHYWHYWHYWHYWHYWHYWHYWHYWHYWHYWHYWHYWHYWHYWHYWHYWHYWHYWH
|
||||
cur.execute(
|
||||
f"select * from tbale where neme = ?",
|
||||
(data_dict["neme"],),
|
||||
)
|
||||
##
|
||||
else:
|
||||
# print(cur)
|
||||
# cur.execute("select * from tbale")
|
||||
# aq142 = cur.fetchall()
|
||||
# self.do_GET()
|
||||
pass
|
||||
##
|
||||
# self.wfile.write(b"\n We have this in the this: ")
|
||||
# self.wfile.write(str(process_datetime_tuples(w2f)).encode())
|
||||
print("res of:", cur.fetchone())
|
||||
# e = cur.fetchall()
|
||||
# print("insert into qure: ")
|
||||
# e = str(e)
|
||||
# map(lambda a, b: e.replace(a, b), severColum, clietColum)
|
||||
# with self.wfile as wf:
|
||||
# wf.write(b"uh what you mightve submitted SuperSsdajfhgaswjkdfaw "+e.encode())
|
||||
# another = cur.execute("select * from tbale")
|
||||
# w2f = cur.fetchall()
|
||||
##
|
||||
except sqlcon.Error as er:
|
||||
raise lmao(rescode.BAD_REQUEST, 3) from er
|
||||
# print("execute err: ", er)
|
||||
# q = str(er)
|
||||
# map(
|
||||
# lambda a, b: q.replace(a, b),
|
||||
# severColum,
|
||||
# clietColum,
|
||||
# )
|
||||
|
||||
## what is a get to endp
|
||||
else: # elif content-type != json
|
||||
self.wfile.write(b"\nits of the type: ")
|
||||
self.wfile.write(content_type.encode())
|
||||
# self.header_setup(
|
||||
# code=rescode.BAD_REQUEST,
|
||||
# headers={"Content-type": "text/plain"},
|
||||
# )
|
||||
# self.wfile.write(
|
||||
# b"is it very much Invalid: "
|
||||
# + q.encode()
|
||||
# + b"\n funny Stuff: q=str(error);map(lambda a, b: q.replace(a, b), severColum, clietColum)"
|
||||
# )
|
||||
|
||||
case _: # self.path
|
||||
self.header_setup(403)
|
||||
self.wfile.write(
|
||||
b"""
|
||||
<h1>403</h1>
|
||||
<p>tf u doin</p>
|
||||
"""
|
||||
)
|
||||
##
|
||||
else:
|
||||
raise lmao(rescode.CREATED, 4)
|
||||
# self.header_setup(
|
||||
# code=rescode.CREATED,
|
||||
# headers={"Content-type": "text/plain"},
|
||||
# )
|
||||
|
||||
return
|
||||
# print(cur)
|
||||
# cur.execute("select * from tbale")
|
||||
# aq142 = cur.fetchall()
|
||||
# self.do_GET()
|
||||
# pass
|
||||
##
|
||||
# finally:
|
||||
# connectio.autocommit = a
|
||||
except sqlcon.Error as eror:
|
||||
raise lmao(rescode.INTERNAL_SERVER_ERROR, 5) from eror
|
||||
# print("coneti eror: ", eror)
|
||||
# self.header_setup(
|
||||
# code=rescode.INTERNAL_SERVER_ERROR,
|
||||
# headers={"Content-type": "text/plain"},
|
||||
# )
|
||||
# self.wfile.write(
|
||||
# b"the thing cant even start like what f: " + str(eror).encode()
|
||||
# )
|
||||
except lmao as e:
|
||||
print(e.args)
|
||||
efg = (
|
||||
f'Ive got a POST at {self.headers.get("Origin", "_nowhere lmao_")} from {self.headers.get("Referer", "_who?_")} with the following data:\n'.encode()
|
||||
+ (
|
||||
post_data_bytes
|
||||
or b"nothing??? what? (no fr nothing fr ALSO YOU KNOW YOUR OWN POST????????????)"
|
||||
) # why so hectic
|
||||
+ b"\n"
|
||||
)
|
||||
headerWhat = {"Content-type": "text/plain;charset=utf-8"} # tf
|
||||
match e.stupid:
|
||||
case 1:
|
||||
print("cccc", content_type, content_length)
|
||||
|
||||
self.header_setup(
|
||||
code=e.ldarescode,
|
||||
headers=headerWhat,
|
||||
)
|
||||
self.wfile.write(efg)
|
||||
self.wfile.write(b"its of the type: ")
|
||||
self.wfile.write(content_type.encode() or b"fdahjklfdashkjlasdf")
|
||||
case 2:
|
||||
cc = e.ldacause
|
||||
print(cc)
|
||||
self.header_setup(
|
||||
code=rescode.BAD_REQUEST,
|
||||
headers=headerWhat,
|
||||
)
|
||||
self.wfile.write(efg)
|
||||
self.wfile.write(
|
||||
b"haha your data sucks (json.loads is not necessarily strict/bad, its just u sent bad): "
|
||||
+ str(cc).encode()
|
||||
)
|
||||
case 3:
|
||||
cc = e.ldacause
|
||||
# print("execute err: ", cc)
|
||||
q = str(cc)
|
||||
for a, b in zip(severColum, clietColum):
|
||||
q = q.replace(a, b)
|
||||
# print("execute errd: ", q)
|
||||
self.header_setup(
|
||||
code=rescode.BAD_REQUEST,
|
||||
headers=headerWhat,
|
||||
)
|
||||
self.wfile.write(efg)
|
||||
self.wfile.write(
|
||||
b"is it very much Invalid: "
|
||||
+ q.encode()
|
||||
+ b"\n funny Stuff: # replace strings found in list old to same index in list new. used for, zip, string.replace"
|
||||
)
|
||||
case 4:
|
||||
self.header_setup(
|
||||
code=rescode.CREATED,
|
||||
headers=headerWhat,
|
||||
)
|
||||
self.wfile.write(efg)
|
||||
case 5:
|
||||
cc = e.ldacause
|
||||
print("coneti eror: ", cc)
|
||||
self.header_setup(
|
||||
code=rescode.INTERNAL_SERVER_ERROR,
|
||||
headers=headerWhat,
|
||||
)
|
||||
self.wfile.write(efg)
|
||||
self.wfile.write(
|
||||
b"the thing cant even start like what f: " + str(cc).encode()
|
||||
)
|
||||
# self.wfile.write(b"\n We have this in the this: ")
|
||||
# self.wfile.write(str(process_datetime_tuples(w2f)).encode())
|
||||
|
||||
## what is a get to endp
|
||||
# elif content-type != json
|
||||
|
||||
|
||||
# out
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
|
||||
# def __do_POST2(self):
|
||||
# if self.path == "/close":
|
||||
# return self.close()
|
||||
# self.header_setup()
|
||||
# content_length = int(self.headers["Content-Length"])
|
||||
# with self.rfile as r:
|
||||
# post_data_bytes = self.rfile.read(content_length)
|
||||
# self.wfile.write(
|
||||
# b"MY SERVER: The post data I received from the request has following data:\n"
|
||||
# + post_data_bytes
|
||||
# )
|
||||
# try:
|
||||
# data_dict = json.loads(post_data_bytes.decode("utf-8"))
|
||||
# except Exception as e:
|
||||
# print(e)
|
||||
# try:
|
||||
# connectio = sqlcon.connect(**connectionSettings)
|
||||
# connectio.autocommit = True # EUYOEYOEYOEYOEYO
|
||||
# except sqlcon.Error as e:
|
||||
# print(e.errno, e.msg)
|
||||
# else:
|
||||
# with connectio.cursor(buffered=True) as cur:
|
||||
# try:
|
||||
# res = cur.execute(
|
||||
# "insert into tbale (kewod, id) values (%s, %s)",
|
||||
# (
|
||||
# data_dict["kewod"],
|
||||
# data_dict["id"],
|
||||
# ),
|
||||
# multi=True,
|
||||
# )
|
||||
# rememver
|
||||
# with
|
||||
# def a(f)
|
||||
# def m(c)
|
||||
# return f(c)
|
||||
# return m
|
||||
#
|
||||
# @a
|
||||
# def b(c)
|
||||
# equals
|
||||
# def b(c)
|
||||
# b = a(b)
|
||||
|
||||
# print(res)
|
||||
# except Exception as e:
|
||||
# print("execute err: ", e)
|
||||
# self.wfile.write(b"\n is it very much Invalid." + str(e).encode())
|
||||
# else:
|
||||
# print(cur)
|
||||
# cur.execute("select * from tbale")
|
||||
# self.wfile.write(
|
||||
# b"\n We have this in the this: "
|
||||
# + str.encode(str(cur.fetchall()))
|
||||
# )
|
||||
# return
|
||||
# so if
|
||||
# @a(x)
|
||||
# def b(c)
|
||||
# a should be
|
||||
# def a(x)
|
||||
# def w(b)
|
||||
# def m(c)
|
||||
# return b(c)
|
||||
# return m
|
||||
# return w
|
||||
|
||||
# def __do_GET2(self):
|
||||
# if self.path == "/close":
|
||||
# return self.close()
|
||||
# you_thought_you_are_funny_helper = {"GET":{}, "POST":{}}
|
||||
# def you_thought_you_are_funny(
|
||||
# serverHandler, # classHUH how Would i get the class instance tho huh
|
||||
# method: Literal["GET", "POST"],
|
||||
# webpath: str,
|
||||
# resCode: int,
|
||||
# headers: dict,
|
||||
# ):
|
||||
# # no yo not
|
||||
# """
|
||||
# @gay("GET", '/', 200, {"Content-type":"text/html"})
|
||||
# def handlerMethod(self, why, do, i, do, this):
|
||||
# return "gay"
|
||||
# """
|
||||
# def g(ggg):
|
||||
# you_thought_you_are_funny_helper[method] = ggg #no more understand
|
||||
# def gg(serverHandler, *gggg, **ggggg):
|
||||
# serverHandler.header_setup(resCode, headers)
|
||||
# return ggg(serverHandler, *gggg, **ggggg)
|
||||
|
||||
# self.header_setup()
|
||||
# try:
|
||||
# connectio = sqlcon.connect(**connectionSettings)
|
||||
# except sqlcon.Error as e:
|
||||
# print(e)
|
||||
# else:
|
||||
# with connectio.cursor(buffered=True, raw=True) as cur:
|
||||
# try:
|
||||
# res = cur.execute("select * from tbale")
|
||||
# w = cur.fetchall()
|
||||
# except Exception as e:
|
||||
# print(e)
|
||||
# else:
|
||||
# print(w)
|
||||
# self.wfile.write(bytes(w).decode())
|
||||
# return
|
||||
# return gg
|
||||
|
||||
# def __close2(self):
|
||||
# try:
|
||||
# self.server.server_close()
|
||||
# except BaseException as e:
|
||||
# print(e)
|
||||
# finally:
|
||||
# print("gato")
|
||||
# raise SystemExit("truly the /close")
|
||||
# do i need the funny trycatch ONCE
|
||||
# def close(self):
|
||||
# funny_trycatch_wrapper(
|
||||
# tries=[(self.server.server_close)],
|
||||
# finallies=[(print, ("gato")), ('raise SystemExit("truly the /close")')],
|
||||
# )
|
||||
# # this is So not ok SCRAP
|
||||
# return g
|
||||
@@ -1,4 +1,7 @@
|
||||
from typing import Callable, Dict, Any, List, Tuple, Union
|
||||
from collections import defaultdict
|
||||
import random
|
||||
import string
|
||||
from typing import Callable, Dict, Any, List, Literal, Tuple, Union
|
||||
from itertools import zip_longest
|
||||
import datetime
|
||||
import copy
|
||||
@@ -116,7 +119,7 @@ def function_splitter(
|
||||
works like your function caller, (function, (args), {kwargs})
|
||||
function(*oa, **args, **okwa, **kwargs) # funny order huhg
|
||||
|
||||
Execute a function or a string using eval if it's the only argument.
|
||||
Execute a function or a string using exec????? if it's the only argument.
|
||||
|
||||
:param t: Tuple containing a function or string, args, and kwargs.
|
||||
:param e: Additional positional arguments.
|
||||
@@ -259,9 +262,32 @@ def process_datetime_tuples(
|
||||
return processed_tuples
|
||||
|
||||
|
||||
def process_datetime_DICTS(
|
||||
dicts: List[Dict[str, Any]], action: Literal["timestamp", "string"] = "timestamp"
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""check process datetime tuples"""
|
||||
for dict in dicts:
|
||||
for k, v in dict.items():
|
||||
if isinstance(v, datetime.datetime):
|
||||
if action == "string":
|
||||
dict[k] = v.strftime("%Y-%m-%d %H:%M:%S")
|
||||
elif action == "timestamp":
|
||||
dict[k] = v.timestamp()
|
||||
|
||||
else:
|
||||
raise ValueError(f"Unsupported action {action}. Use 'string' or 'timestamp'.") # bet this will run
|
||||
return dicts # in place processing
|
||||
|
||||
|
||||
def funny_tuples_to_dicts_processor(colname: list[tuple], coldata: list[tuple]):
|
||||
"""
|
||||
sql return such shit
|
||||
"""
|
||||
if len(colname) != len(coldata[0]):
|
||||
raise ValueError("unless im stupid, even then curate ur list first")
|
||||
raise IndexError(
|
||||
"unless im stupid, even then curate ur list first.",
|
||||
f"size of first arg {len(colname)} != second arg {len(coldata[0])}",
|
||||
)
|
||||
new_dicts: list[dict] = []
|
||||
for ee in coldata:
|
||||
new_dict = {}
|
||||
@@ -271,5 +297,110 @@ def funny_tuples_to_dicts_processor(colname: list[tuple], coldata: list[tuple]):
|
||||
return new_dicts
|
||||
|
||||
|
||||
getnewdict = lambda d, l: {k: d[k] for k in d if k in l}
|
||||
getnewdicttranslate = lambda d, tltb: {tltb[k]: d[k] for k in d if k in tltb}
|
||||
getnewdictl = lambda d, l: {k: d[k] for k in d if k in l}
|
||||
|
||||
|
||||
def getnewdict(d: dict, l: list) -> dict:
|
||||
"""
|
||||
from a list of keys filter that dict (filter)
|
||||
"""
|
||||
return {k: d[k] for k in d if k in l}
|
||||
|
||||
|
||||
getnewdicttranslatel = lambda d, tltb: {tltb[k]: d[k] for k in d if k in tltb}
|
||||
|
||||
|
||||
def getnewdicttranslate(d: dict, tltb: dict) -> dict:
|
||||
"""
|
||||
from (key: value) of dict to (value of translate table: value of dict)
|
||||
"""
|
||||
return {tltb[k]: d[k] for k in d if k in tltb}
|
||||
|
||||
|
||||
def lists_toDict_funnyaf(k: list, v: list):
|
||||
"""thank you chat"""
|
||||
d = {}
|
||||
dup = defaultdict(list)
|
||||
# if len(l1) != len(l2):
|
||||
# raise ValueError("not equal lsit")
|
||||
for key, val in zip_longest(k, v):
|
||||
if key in d and d[key] != val:
|
||||
dup[key].append(val)
|
||||
d[key] = val
|
||||
return d, dict(dup)
|
||||
|
||||
|
||||
def simpler_ltd(k, v):
|
||||
if len(k) != len(v):
|
||||
raise ValueError("wrong size")
|
||||
return dict(zip(k, v))
|
||||
|
||||
|
||||
def zipSkipNone(*its, noneValue=None):
|
||||
if len(its) == 0:
|
||||
raise TypeError("wfehiufwehiu", noneValue + " where")
|
||||
for i in zip(*its):
|
||||
if any(a == noneValue for a in i):
|
||||
# print(f"none: {i}")
|
||||
continue
|
||||
yield i
|
||||
|
||||
|
||||
def rN(a=6, b=24):
|
||||
return random.randint(a, b)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
l = [*string.digits, None]
|
||||
a = random.choices(l, k=rN())
|
||||
b = random.choices(l, k=rN())
|
||||
c = random.choices(l, k=rN())
|
||||
print(a, b, c, list(zipSkipNone(a, b, c)), sep="\n")
|
||||
|
||||
|
||||
def HowToDecorator(*a1, **k1):
|
||||
print("your decorator looks like this:")
|
||||
print("@HowToDecorator(something)")
|
||||
print(
|
||||
"this is a decorator maker. right. as if you put something different the returned function from this HowToDecorator will have the different something"
|
||||
)
|
||||
print(
|
||||
"as where this is ran, its when you are trying to make a decorator from the decorator maker. \nIf i do this: deco = decomaker(**arguments) then use the @deco as normal, i will be running this print call once, and not again."
|
||||
)
|
||||
print(f"just so you know u put {a1} as pos args and {k1} as kwargs")
|
||||
|
||||
# the decorator will decorate the function like this:
|
||||
# if i write
|
||||
# @d
|
||||
# def b()
|
||||
# its the same as saying b = d(b)
|
||||
def TheDecorator(function):
|
||||
print("if you dont have parenthesis")
|
||||
print(
|
||||
"@TheDecorator \\n def fn() for example, then its like calling this TheDecorator func with (fn) as the arg"
|
||||
)
|
||||
print(f"u can access {a1} and {k1} here as well")
|
||||
print(
|
||||
"any time you are using the deco (which is decomaker(**arguments)) then you are calling this print"
|
||||
)
|
||||
|
||||
def SupportForArgs(*a2, **k2):
|
||||
print("if you are running function early, then this is great.")
|
||||
print("you can modify the args here, add some, take some idk")
|
||||
print(
|
||||
"imagine instead of function(arg) ur running SupportForArgs(arg) instead"
|
||||
)
|
||||
returnValue = function(*a1, *a2, **k1, **k2)
|
||||
print("this line of text appears anytime a function decorated gets called")
|
||||
print("you can append do stuff with the decorated function and its result")
|
||||
return "something else?", returnValue
|
||||
|
||||
print(
|
||||
"the decorator could just return function as normal, running things. but with the inner function it can also change stuff with the calling of the function itself."
|
||||
)
|
||||
print(
|
||||
"i believe in having an inner function (support for args) here even if you dont do anything (rare af)"
|
||||
)
|
||||
return SupportForArgs
|
||||
|
||||
return TheDecorator
|
||||
@@ -5,10 +5,10 @@
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>lđa testing</title>
|
||||
<link type="text/css" rel="stylesheet" href="./style.css" />
|
||||
<link type="text/css" rel="stylesheet" href="./index/style.css" />
|
||||
<!-- huh? what? -->
|
||||
<script type="module" src="./script.js" defer></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css">
|
||||
<script type="module" src="./index/script.js" defer></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" />
|
||||
<!-- real -->
|
||||
</head>
|
||||
|
||||
@@ -36,29 +36,45 @@
|
||||
<div class="box">
|
||||
<form action="./endp" method="post" id="only_form" enctype="text/plain">
|
||||
<label for="oneid">url (no space please thanks)
|
||||
<div style=>
|
||||
<a id="woah" style="text-align: right; min-width: 240px;
|
||||
"></a>
|
||||
<input style="display: inline;" required type="text" name="one" id="oneid" placeholder="url"
|
||||
<div style>
|
||||
<a id="woah" style="text-align: right; min-width: 240px"></a>
|
||||
<input style="display: inline" required type="text" name="one" id="oneid" placeholder="url"
|
||||
maxlength="15" pattern="\S+" />
|
||||
</div>
|
||||
</label>
|
||||
<label for="the_Textarea">content (idk how it works anymore):
|
||||
</label>
|
||||
<span id="i_appear" hidden>so uh if you choose redirect then this should be a complete link and nothing
|
||||
else uh example <a target="_blank" href="https://ldlda.com">https://ldlda.com</a> uh</span>
|
||||
<div>
|
||||
<div class="setting-buttons">
|
||||
<!-- <input type="button" id="viewTextarea" value="show textarea" /> -->
|
||||
<input type="button" id="viewDiv" value="show rendered" />
|
||||
<input type="button" value="markdown to html" id="translateMD">
|
||||
<input type="checkbox" id="auto_translate">
|
||||
<input type="button" value="markdown to html" id="translateMD" />
|
||||
<label for="auto_translate"><input type="checkbox" id="auto_translate" /> auto (lag)</label>
|
||||
</div>
|
||||
</label>
|
||||
<div>
|
||||
<textarea class="why" name="two" id="the_Textarea" placeholder="what"></textarea>
|
||||
<textarea required class="why" name="two" id="the_Textarea" placeholder="what"></textarea>
|
||||
<!-- <div class="why" name="two" id="the_div" placeholder="type in here"></div> -->
|
||||
</div>
|
||||
<label for="threeid">response code if path visited. Default 200<input type="number" name="three"
|
||||
id="threeid" placeholder="http res code" min="0" pattern="\d*" /></label>
|
||||
<label for="threeid"><span style="display: block;">response code if path visited. Default 200</span>
|
||||
<select required name="three" id="threeid">
|
||||
<option value="" disabled>-- CHOOSE --</option>
|
||||
<optgroup label="content">
|
||||
<option selected value="200">text file</option>
|
||||
</optgroup>
|
||||
<optgroup label="redirect">
|
||||
<option value="302">shortlinks</option>
|
||||
<option value="301">shortlinks permanent</option>
|
||||
</optgroup>
|
||||
<option id="uniqueID">do NOT:</option>
|
||||
</select>
|
||||
<input type="number" id="rescode" placeholder="advanced type shi" style="width: 5em; display: none;"
|
||||
min="100" max="599" step="1">
|
||||
</label>
|
||||
<label for="fourid">expiration time for anything (todo idk how to do )<input type="number" name="four"
|
||||
id="fourid" placeholder="expiration in days" min="0" pattern="\d*" /></label>
|
||||
id="fourid" placeholder="expiration in days" pattern="\d{1,3}" min="0" max="255"
|
||||
step="1" /></label>
|
||||
<!-- bulletproof -->
|
||||
<p>leave empty for none / default</p>
|
||||
<input type="submit" value="Sumit rn" />
|
||||
</form>
|
||||
@@ -59,7 +59,7 @@ const translateMDButton = document.getElementById("translateMD");
|
||||
const MDtoHTMLEngine = (v) =>
|
||||
micromark(v, {
|
||||
extensions: [frontmatter(), gfm(), math()],
|
||||
htmlExtensions: [frontmatterHtml(), gfmHtml(), mathHtml()],
|
||||
htmlExtensions: [frontmatterHtml(), gfmHtml(), mathHtml()], // please if i can CodeHighlight maybe PLEAS
|
||||
});
|
||||
const updateMD = (e) => {
|
||||
divTextarea.innerHTML = MDtoHTMLEngine(realTextarea.value);
|
||||
@@ -68,12 +68,23 @@ const updateMD = (e) => {
|
||||
translateMDButton.addEventListener("click", updateMD);
|
||||
//
|
||||
let updatingInterval = 240;
|
||||
let justUpdated = false;
|
||||
// let justUpdated = false;
|
||||
let updateTimeout;
|
||||
// let a = 0 // was trying to make a hey why do i have to translate your every keystroke??????? thingamajig
|
||||
const typingHandler = (f) => (e) => {
|
||||
if (!justUpdated && !updateTimeout) {
|
||||
justUpdated = true;
|
||||
// a++
|
||||
// if (a > 4) { // thats 12wpm
|
||||
// a = 0
|
||||
// if (updateTimeout)
|
||||
// clearTimeout(updateTimeout);
|
||||
// updateTimeout = undefined;
|
||||
// }
|
||||
if (
|
||||
// !justUpdated &&
|
||||
!updateTimeout) {
|
||||
// justUpdated = true;
|
||||
updateTimeout = setTimeout(() => {
|
||||
|
||||
try {
|
||||
f();
|
||||
document.getElementById("errorfrommd").textContent = null;
|
||||
@@ -81,10 +92,12 @@ const typingHandler = (f) => (e) => {
|
||||
document.getElementById("errorfrommd").textContent = e.message;
|
||||
}
|
||||
|
||||
justUpdated = false;
|
||||
updateTimeout = null;
|
||||
// justUpdated = false;
|
||||
clearTimeout(updateTimeout)
|
||||
updateTimeout = undefined;
|
||||
}, updatingInterval);
|
||||
}
|
||||
|
||||
};
|
||||
const mdUpdatingHandler = typingHandler(updateMD); //why
|
||||
document.getElementById("auto_translate").addEventListener("change", (e) => {
|
||||
@@ -109,10 +122,10 @@ const click_out_the_div = (e) => {
|
||||
divTextarea.addEventListener("focus", click_in_the_div); // if function () {}
|
||||
divTextarea.addEventListener("blur", click_out_the_div); // i can use this
|
||||
|
||||
const resizeObserver = new ResizeObserver((mutation) => [
|
||||
mutation[0].contentRect.width,
|
||||
mutation[0].contentRect.height,
|
||||
]);
|
||||
// const resizeObserver = new ResizeObserver((mutation) => [
|
||||
// mutation[0].contentRect.width,
|
||||
// mutation[0].contentRect.height,
|
||||
// ]);
|
||||
|
||||
divTextarea.style.setProperty;
|
||||
const toggleDivTextarea = document.getElementById("viewDiv");
|
||||
@@ -130,6 +143,44 @@ document.querySelectorAll('input[type="number"]').forEach((e) => {
|
||||
});
|
||||
});
|
||||
|
||||
const selectorAll = document.getElementById("threeid");
|
||||
const AlertOfAllTime = document.getElementById("i_appear");
|
||||
const optionOfTheYear = document.getElementById("uniqueID");
|
||||
const advancedTypeShit = document.getElementById("rescode");
|
||||
const haxxor = (e) => {
|
||||
if (/^[1-5][0-9][0-9]$/.test(advancedTypeShit.value)) {
|
||||
advancedTypeShit.setCustomValidity("");
|
||||
optionOfTheYear.value = advancedTypeShit.value;
|
||||
} else {
|
||||
advancedTypeShit.setCustomValidity(
|
||||
"seems like its not a valid status code. i think its numbers from 100 to 599"
|
||||
);
|
||||
}
|
||||
};
|
||||
selectorAll.addEventListener("change", function (e) {
|
||||
if (this.value == "301" || this.value == "302") {
|
||||
AlertOfAllTime.hidden = false;
|
||||
} else {
|
||||
AlertOfAllTime.hidden = true;
|
||||
}
|
||||
console.log(
|
||||
selectorAll.selectedOptions[0],
|
||||
optionOfTheYear,
|
||||
selectorAll.selectedOptions[0] == optionOfTheYear
|
||||
);
|
||||
});
|
||||
selectorAll.addEventListener("change", (e) => {
|
||||
if (selectorAll.selectedOptions[0] === optionOfTheYear) {
|
||||
advancedTypeShit.style.display = "inline";
|
||||
selectorAll.style.display = "inline";
|
||||
advancedTypeShit.addEventListener("input", haxxor);
|
||||
} else {
|
||||
advancedTypeShit.style.display = "none";
|
||||
selectorAll.style.display = null;
|
||||
advancedTypeShit.value = null;
|
||||
advancedTypeShit.removeEventListener("input", haxxor);
|
||||
}
|
||||
});
|
||||
const form = document.getElementById("only_form");
|
||||
form.addEventListener("submit", (e) => {
|
||||
e.preventDefault();
|
||||
@@ -189,11 +240,12 @@ const GETendp = (_) =>
|
||||
// damn
|
||||
case 301:
|
||||
case 302:
|
||||
case 307:
|
||||
case 308: // DONT EVER stick with 302
|
||||
responsecontent = "redirect";
|
||||
break;
|
||||
}
|
||||
htmlContent +=
|
||||
`<tr>
|
||||
htmlContent += `<tr>
|
||||
<th>${key}</th>
|
||||
<td><a href="${"./" + url}">${url}</a></td>
|
||||
<td>${responsecontent}</td>
|
||||
@@ -203,6 +255,7 @@ const GETendp = (_) =>
|
||||
|
||||
// htmlContent += "</tbody>";
|
||||
actualTableContent.innerHTML = htmlContent;
|
||||
htmlContent = ''
|
||||
})
|
||||
.catch((e) => console.error(e));
|
||||
|
||||
@@ -25,7 +25,8 @@ body {
|
||||
grid-template-areas: "head head" "nav main" "nav foot";
|
||||
max-width: 100%;
|
||||
}
|
||||
body, html{
|
||||
body,
|
||||
html {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@@ -57,17 +58,18 @@ nav {
|
||||
transition: height 1s ease-in-out, background-color 1s ease-in-out;
|
||||
|
||||
&:hover,
|
||||
&:focus{
|
||||
&:focus,
|
||||
&:has(a:active) {
|
||||
height: 7em;
|
||||
background-color: paleturquoise;
|
||||
transition: height 1s ease-in-out, background-color 1s ease-in-out;
|
||||
}
|
||||
> a {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
align-content: center;
|
||||
text-align: center;
|
||||
}
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
align-content: center;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +86,7 @@ header nav {
|
||||
font-size: xx-large;
|
||||
display: flex;
|
||||
gap: 1em;
|
||||
}
|
||||
}
|
||||
/* previous design */
|
||||
|
||||
main {
|
||||
@@ -106,7 +108,6 @@ footer {
|
||||
place-content: center;
|
||||
}
|
||||
|
||||
|
||||
.box {
|
||||
background-color: mistyrose;
|
||||
padding: 0.5em;
|
||||
@@ -117,9 +118,14 @@ footer {
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
gap: 1em;
|
||||
justify-content: space-evenly;
|
||||
> * {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
form label,
|
||||
input {
|
||||
input,
|
||||
select {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@@ -158,14 +164,14 @@ textarea::placeholder {
|
||||
background-color: field;
|
||||
border: thin solid var(--dark-enough);
|
||||
border-radius: 6px;
|
||||
/* width: max-content; */
|
||||
width: fit-content;
|
||||
max-height: 86vh;
|
||||
outline: none;
|
||||
overflow: auto;
|
||||
overflow-wrap: break-word;
|
||||
resize: none;
|
||||
min-height: 16rem;
|
||||
flex: 1 1 50%;
|
||||
height:max-content;
|
||||
}
|
||||
/* ????? */
|
||||
|
||||
@@ -176,16 +182,11 @@ img {
|
||||
|
||||
.why {
|
||||
min-width: 20rem;
|
||||
/* padding: 4px; */
|
||||
padding-inline: 4px;
|
||||
max-width: 960px;
|
||||
|
||||
min-height: 7rem;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.table > table {
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
@@ -206,3 +207,29 @@ td {
|
||||
/* selecting all cells using NOT & > * > * > * */
|
||||
padding: 3px 6px;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 820px) {
|
||||
body {
|
||||
gap: 1em;
|
||||
grid-auto-flow: column;
|
||||
grid-template-columns: auto;
|
||||
grid-template-rows: auto;
|
||||
grid-template-areas: "head " "nav" "main" "foot";
|
||||
}
|
||||
nav {
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
}
|
||||
nav ul {
|
||||
display: flex;
|
||||
flex-flow: row nowrap;
|
||||
flex: 1;
|
||||
}
|
||||
nav li {
|
||||
&:hover,
|
||||
&:focus,
|
||||
&:has(a:active) {
|
||||
height: unset;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user