init
This commit is contained in:
57
app/main.py
Normal file
57
app/main.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from flask import Flask, render_template, current_app as this, Response
|
||||
from google.cloud import storage
|
||||
from flask_minify import Minify
|
||||
|
||||
|
||||
app = Flask(__name__.split('.')[0])
|
||||
app.jinja_env.trim_blocks = True
|
||||
app.jinja_env.lstrip_blocks = True
|
||||
Minify(app=app, html=True, js=True, cssless=True)
|
||||
|
||||
def humanSize(size: int) -> str:
|
||||
prefix = [" ", " K", " M", " G", " T"]
|
||||
i = 0
|
||||
while size > 1024:
|
||||
size /= 1024
|
||||
i += 1
|
||||
|
||||
|
||||
size = str(round(size,3-len(str(int(size)))))
|
||||
if size.endswith(".0"): size = size.replace(".0","")
|
||||
|
||||
return size+prefix[i]+"B"
|
||||
|
||||
def getDownloads(bucket_name: str) -> list:
|
||||
""" takes the name of a google storage bucket and returns a list of objects on it """
|
||||
storage_client = storage.Client.from_service_account_json(json_credentials_path="acc.json")
|
||||
blobs = []
|
||||
for blob in storage_client.list_blobs(bucket_name, prefix='dload'):
|
||||
if blob.size == 0: continue
|
||||
blobs.append({"name": blob.name.replace("dload/",""), "size": humanSize(blob.size), "url": blob.public_url})
|
||||
storage_client.close()
|
||||
return blobs
|
||||
|
||||
@app.route('/')
|
||||
def main():
|
||||
return render_template("index.html")
|
||||
|
||||
@app.route('/codecalc')
|
||||
def calc():
|
||||
return render_template("code-calc.html")
|
||||
|
||||
@app.route('/secret')
|
||||
def secret():
|
||||
imgUrl = "/static/images/kroniicopter.webp"
|
||||
return render_template("secret.html", imgUrl = imgUrl)
|
||||
|
||||
@app.route('/tests')
|
||||
def test():
|
||||
return render_template("test.html")
|
||||
|
||||
@app.route('/downloads')
|
||||
def dload():
|
||||
return render_template("downloads.htm", users = getDownloads("drath-public"))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=8080, debug=True)
|
||||
Reference in New Issue
Block a user