init
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/venv/
|
||||
/.idea/
|
||||
37
.replit
Normal file
37
.replit
Normal file
@@ -0,0 +1,37 @@
|
||||
run = "python3 main.py"
|
||||
language = "python3"
|
||||
entrypoint = "main.py"
|
||||
|
||||
hidden = ["**/__pycache__", "**/.mypy_cache", "**/*.pyc"]
|
||||
|
||||
[nix]
|
||||
channel = "stable-22_11"
|
||||
|
||||
[interpreter]
|
||||
[interpreter.command]
|
||||
args = [
|
||||
"stderred",
|
||||
"--",
|
||||
"prybar-python310",
|
||||
"-q",
|
||||
"--ps1",
|
||||
"\u0001\u001b[33m\u0002\u0001\u001b[00m\u0002 ",
|
||||
"-i",
|
||||
]
|
||||
env = { LD_LIBRARY_PATH = "$PYTHON_LD_LIBRARY_PATH" }
|
||||
|
||||
[env]
|
||||
VIRTUAL_ENV = "/home/runner/${REPL_SLUG}/venv"
|
||||
PATH = "${VIRTUAL_ENV}/bin"
|
||||
PYTHONPATH = "${VIRTUAL_ENV}/lib/python3.10/site-packages"
|
||||
|
||||
[gitHubImport]
|
||||
requiredFiles = [".replit", "replit.nix", ".config", "venv"]
|
||||
|
||||
[languages]
|
||||
|
||||
[languages.python3]
|
||||
pattern = "**/*.py"
|
||||
|
||||
[languages.python3.languageServer]
|
||||
start = "pylsp"
|
||||
93
main.py
Normal file
93
main.py
Normal file
@@ -0,0 +1,93 @@
|
||||
import requests
|
||||
import juneberry
|
||||
from juneberry.colors import Color, R, G, B
|
||||
from uvicorn import run
|
||||
from fastapi import FastAPI
|
||||
from starlette.requests import Request
|
||||
from fastapi.responses import PlainTextResponse, StreamingResponse, RedirectResponse
|
||||
|
||||
app = FastAPI()
|
||||
logger = juneberry.Logger(theme=juneberry.Theme(
|
||||
Color.Custom.from_rgb((R(189), G(224), B(254))),
|
||||
Color.Custom.from_rgb((R(205), G(180), B(219))),
|
||||
Color.Custom.from_rgb((R(162), G(210), B(255))),
|
||||
Color.Custom.from_rgb((R(255), G(200), B(221))),
|
||||
Color.Custom.from_rgb((R(255), G(175), B(204))),
|
||||
Color.Custom.from_rgb((R(255), G(254), B(214))),
|
||||
Color.Custom.from_rgb((R(255), G(254), B(214)))
|
||||
))
|
||||
|
||||
|
||||
@app.get("/")
|
||||
@app.head("/")
|
||||
async def root(request: Request):
|
||||
logger.info(f'Root accessed from {request.client.host}')
|
||||
return PlainTextResponse(
|
||||
f"Simple linkbox.to direct link grabber. \n"
|
||||
f"Paste full link to LinkBox shared file to get direct download link, that you can share to friends. \n"
|
||||
f"Add /s to end of this link, to create proxied streamed link that can be accessible from curl or wget "
|
||||
f"(slower stream, shorter link). \n"
|
||||
f"Add /l to end of this link to get direct link on LinkBox cdn (faster stream, longer link) \n"
|
||||
f"Paste file id (symbols after last slash in original link) to directly download file. You can also add /s or "
|
||||
f"/l to it. \n"
|
||||
f"Use {request.url._url}[original share link]/d to download file directly."
|
||||
)
|
||||
|
||||
|
||||
@app.get("/{linkbox:path}")
|
||||
async def return_hui(linkbox: str, request: Request):
|
||||
mode = None
|
||||
for catch in ['d', 'l', 's']:
|
||||
if '/' + catch == linkbox[-2:]:
|
||||
mode = catch
|
||||
linkbox = linkbox[:-2]
|
||||
|
||||
if linkbox[-1] == '/':
|
||||
linkbox = linkbox[:-1]
|
||||
|
||||
if (is_link := 'linkbox.to' in linkbox or 'lbx.to' in linkbox) and \
|
||||
(resp := request.url._url.replace(request.url.path, '/' + linkbox.split('/')[-1])) and \
|
||||
mode != 'd':
|
||||
logger.info(f"{request.client.host} - Url for https://lbx.to/f/{linkbox} - {resp} (default full link)")
|
||||
return PlainTextResponse(resp)
|
||||
elif is_link:
|
||||
logger.info(f"{request.client.host} - Url for https://lbx.to/f/{linkbox} - {resp} (d mode)")
|
||||
return RedirectResponse(resp)
|
||||
|
||||
try:
|
||||
itemId = requests.get(
|
||||
f'https://linkbox.to/api/file/share_out_list?shareToken={linkbox}'
|
||||
).json()["data"]["itemId"]
|
||||
iteminfo = requests.get(f'https://linkbox.to/api/file/detail?itemId={itemId}').json()['data']['itemInfo']
|
||||
url = iteminfo['url'].replace('wht.nuplink', 'wdl.nuplink') + f'&filename={iteminfo["name"]}'
|
||||
except Exception as e:
|
||||
logger.error(f"{request.client.host} - Error {e} while processing {linkbox}")
|
||||
return PlainTextResponse(f'Error: {e}. Check file id or url.', status_code=404)
|
||||
|
||||
if mode == 's':
|
||||
def iterate_file():
|
||||
session = requests.Session()
|
||||
r = session.get(url, stream=True)
|
||||
r.raise_for_status()
|
||||
|
||||
for chunk in r.iter_content(1024 * 1024):
|
||||
yield chunk
|
||||
|
||||
logger.info(f"{request.client.host} - Streaming {iteminfo['name']} from {url}")
|
||||
return StreamingResponse(iterate_file(), headers=requests.head(url).headers)
|
||||
|
||||
if mode == 'l':
|
||||
logger.info(f"{request.client.host} - Url for https://lbx.to/f/{linkbox} - {url} (l mode)")
|
||||
return PlainTextResponse(url)
|
||||
|
||||
logger.info(f"{request.client.host} - Redirecting https://lbx.to/f/{linkbox} to {url} (default mode)")
|
||||
return RedirectResponse(url)
|
||||
|
||||
|
||||
@app.on_event('startup')
|
||||
def on_startup():
|
||||
logger.info('Started!')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run(app=app, host="0.0.0.0", port=1488, log_level='critical')
|
||||
21
replit.nix
Normal file
21
replit.nix
Normal file
@@ -0,0 +1,21 @@
|
||||
{ pkgs }: {
|
||||
deps = [
|
||||
pkgs.strace
|
||||
pkgs.python310Full
|
||||
pkgs.python310Packages.pip.out
|
||||
pkgs.replitPackages.prybar-python310
|
||||
pkgs.replitPackages.stderred
|
||||
];
|
||||
env = {
|
||||
PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
|
||||
pkgs.stdenv.cc.cc.lib
|
||||
pkgs.zlib
|
||||
pkgs.glib
|
||||
pkgs.xorg.libX11
|
||||
];
|
||||
PYTHONBIN = "${pkgs.python310Full}/bin/python3.10";
|
||||
LANG = "en_US.UTF-8";
|
||||
STDERREDBIN = "${pkgs.replitPackages.stderred}/bin/stderred";
|
||||
PRYBAR_PYTHON_BIN = "${pkgs.replitPackages.prybar-python310}/bin/prybar-python310";
|
||||
};
|
||||
}
|
||||
5
requirements.txt
Normal file
5
requirements.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
fastapi
|
||||
uvicorn
|
||||
requests
|
||||
juneberry
|
||||
starlette
|
||||
Reference in New Issue
Block a user