[O] Color printing
This commit is contained in:
@@ -6,6 +6,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
from fastapi import FastAPI, Body
|
from fastapi import FastAPI, Body
|
||||||
|
from hyfetch.color_util import printc
|
||||||
from pysafebrowsing import SafeBrowsing
|
from pysafebrowsing import SafeBrowsing
|
||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
from starlette.responses import RedirectResponse, HTMLResponse, FileResponse, PlainTextResponse
|
from starlette.responses import RedirectResponse, HTMLResponse, FileResponse, PlainTextResponse
|
||||||
@@ -84,13 +85,14 @@ def put(request: Request, name: str | None = None, body: str = Body()):
|
|||||||
|
|
||||||
ip = request.headers.get('X-Real-IP') or request.client.host
|
ip = request.headers.get('X-Real-IP') or request.client.host
|
||||||
|
|
||||||
print(f'New PUT request from {ip}')
|
print()
|
||||||
print(f'> URL: {body.replace("https://", "").replace("http://", "")}')
|
printc(f'&aPUT - New request from {ip}')
|
||||||
|
printc(f'&e> URL: {body.replace("https://", "").replace("http://", "")}')
|
||||||
|
|
||||||
# Check valid html
|
# Check valid html
|
||||||
assert re_url.match(body), 'Invalid HTML'
|
assert re_url.match(body), 'Invalid HTML'
|
||||||
sb = safe_browsing.lookup_url(body)
|
sb = safe_browsing.lookup_url(body)
|
||||||
print(f'> SafeBrowsing Result: {sb}')
|
printc(f'&e> SafeBrowsing Result: {sb}')
|
||||||
assert not sb['malicious'], f'Link is malicious ({",".join(sb["threats"]).lower()})'
|
assert not sb['malicious'], f'Link is malicious ({",".join(sb["threats"]).lower()})'
|
||||||
|
|
||||||
# Generate name
|
# Generate name
|
||||||
@@ -102,15 +104,16 @@ def put(request: Request, name: str | None = None, body: str = Body()):
|
|||||||
|
|
||||||
# Put name
|
# Put name
|
||||||
links[name] = body
|
links[name] = body
|
||||||
print(f'> Added link: {name}')
|
printc(f'&a> Added link: /{name}')
|
||||||
store()
|
store()
|
||||||
|
|
||||||
return PlainTextResponse(f'/{name}')
|
return PlainTextResponse(f'/{name}')
|
||||||
|
|
||||||
except AssertionError as e:
|
except AssertionError as e:
|
||||||
print(f'> Rejected. {e}')
|
printc(f'&c> Rejected. {e}')
|
||||||
return PlainTextResponse(f'Error: {e}', status_code=400)
|
return PlainTextResponse(f'Error: {e}', status_code=400)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
load()
|
load()
|
||||||
uvicorn.run(app, host='0.0.0.0', port=8000)
|
uvicorn.run(app, host='0.0.0.0', port=8000)
|
||||||
|
|||||||
+1
-1
@@ -119,7 +119,7 @@
|
|||||||
const resp = await fetch('/', {method: 'PUT', body: url})
|
const resp = await fetch('/', {method: 'PUT', body: url})
|
||||||
const txt = await resp.text()
|
const txt = await resp.text()
|
||||||
this.error = resp.status !== 200
|
this.error = resp.status !== 200
|
||||||
this.short = this.error ? txt : window.location.origin.replaceAll(/https?:\/\//, '') + txt
|
this.short = this.error ? txt : window.location.origin.replaceAll(/https?:\/\//g, '') + txt
|
||||||
|
|
||||||
// Copy to clipboard
|
// Copy to clipboard
|
||||||
if (!this.error)
|
if (!this.error)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
uvicorn
|
uvicorn
|
||||||
fastapi
|
fastapi
|
||||||
pysafebrowsing
|
pysafebrowsing
|
||||||
|
hyfetch
|
||||||
|
|||||||
Reference in New Issue
Block a user