64 lines
2.1 KiB
Python
Executable File
64 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env cached-nix-shell
|
|
#!nix-shell -i python3 -p "python3.withPackages(ps: with ps; [ ps.flask ps.requests ])"
|
|
from flask import Flask, redirect
|
|
import requests
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
def get_files(uuid, password):
|
|
r = requests.get(
|
|
"https://www.odrive.com/rest/weblink/list_folder",
|
|
params={"weblinkUri": f"/{uuid}", "password": password},
|
|
)
|
|
return dict(
|
|
(item["name"], item["downloadUrl"]) for item in r.json()["data"]["items"]
|
|
)
|
|
|
|
|
|
@app.route("/")
|
|
def help():
|
|
return """<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>rclone proxy for odrive</title>
|
|
<meta charset="utf-8">
|
|
</head>
|
|
<body>
|
|
<h1>rclone proxy for odrive</h1>
|
|
<p style="max-width: 720px;">Fill the two fields with the UUID (the
|
|
part after https://www.odrive.com/s/) and the access password. You
|
|
will be redirected to the proxied directory listing. Point rclone
|
|
at that URL and it should be able to download the files
|
|
(<code>rclone copy --http-url "YOUR_URL_HERE" :http:
|
|
remote:bucket</code>).</p>
|
|
<input id="uuid" name="uuid" placeholder="uuid" size="40">
|
|
<input id="password" name="password" placeholder="password" size="30">
|
|
<input id="submit" type="submit" value="Get link">
|
|
<script>
|
|
document.querySelector("#submit").onclick = () => {
|
|
const uuid = document.querySelector("#uuid").value
|
|
const password = document.querySelector("#password").value
|
|
location = `/${uuid}/${encodeURIComponent(password)}`
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>"""
|
|
|
|
|
|
@app.route("/<string:uuid>/<string:password>/")
|
|
def index(uuid, password):
|
|
res = f'<!DOCTYPE html><html><head><title>Index of /{uuid}</title><meta charset="utf-8"></head><body><h1>Index of /{uuid}</h1><pre>'
|
|
for name, url in get_files(uuid, password).items():
|
|
res += f'<a href="{name}">{name}</a>\n'
|
|
res += "</pre></body></html>"
|
|
return res
|
|
|
|
|
|
@app.route("/<string:uuid>/<string:password>/<string:name>")
|
|
def file(uuid, password, name):
|
|
return redirect(get_files(uuid, password)[name])
|
|
|
|
|
|
app.run()
|