добавлено много файлов, и отсутствие файлов
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
102
app.py
102
app.py
@@ -1,15 +1,13 @@
|
||||
from flask import Flask, render_template, request
|
||||
from flask_assets import Bundle, Environment
|
||||
from todo import todos
|
||||
#from boards import board_list
|
||||
from threads import threads_lists
|
||||
from threads_with_posts import open_threads
|
||||
from arango import ArangoClient
|
||||
from minio import Minio
|
||||
|
||||
import socket, os
|
||||
|
||||
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
assets = Environment(app)
|
||||
@@ -29,9 +27,11 @@ docker_short_id = socket.gethostname()
|
||||
|
||||
arango_client = ArangoClient(hosts='https://arango.guaranteedstruggle.host')
|
||||
db = arango_client.db('board1', username='root', password='stolendick527')
|
||||
|
||||
|
||||
|
||||
# предполагается что меняться список будет весьма редко, поэтому подхватываем при лишь при перезапуске
|
||||
boards0 = db.collection('boards')
|
||||
print(boards0)
|
||||
board_list = [ k['_key'] for k in boards0]
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ def healthx():
|
||||
|
||||
@app.route('/readiness')
|
||||
def healthz():
|
||||
#### TODU return arango check
|
||||
|
||||
return "<h1><center>Readiness check completed</center><h1>"
|
||||
|
||||
|
||||
@@ -80,70 +82,23 @@ def answer_post(target_post_id):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@app.route('/post_my_post/<post_key>', methods=['POST'])
|
||||
def post_a_post(post_key):
|
||||
|
||||
|
||||
postos = db.collection('posts')
|
||||
|
||||
|
||||
#### TODO проверить как-то по-умному что мы таки его добавили
|
||||
metadata = postos.insert({
|
||||
'texto': 'next post is this',
|
||||
'parent_post': f'{post_key}'
|
||||
}, overwrite_mode='update')
|
||||
|
||||
metadata = db.collection('post_parents').insert({
|
||||
# '_key': post_key,
|
||||
'_from': f'posts/{post_key}',
|
||||
'_to': f'posts/{metadata["_key"]}'
|
||||
}, overwrite_mode='update')
|
||||
|
||||
|
||||
|
||||
cursor = db.aql.execute(
|
||||
"""FOR ppp IN posts
|
||||
LET children = (FOR v IN 1..9999 OUTBOUND ppp post_parents RETURN v)
|
||||
UPDATE ppp WITH { children_num : COUNT_DISTINCT( children[*]._key ) } IN posts"""
|
||||
)
|
||||
cursor = db.aql.execute(
|
||||
"""FOR ppp IN posts
|
||||
LET children = (FOR v IN 1 OUTBOUND ppp post_parents RETURN v)
|
||||
UPDATE ppp WITH { answers_num : COUNT_DISTINCT( children[*]._key ) } IN posts"""
|
||||
)
|
||||
|
||||
cursor = db.aql.execute(
|
||||
"""FOR ppp IN posts
|
||||
LET children0 = (FOR v IN 1 OUTBOUND ppp post_parents RETURN v)
|
||||
LET children = (FOR c IN children0
|
||||
SORT c._key DESC
|
||||
RETURN c)
|
||||
UPDATE ppp WITH { answers_list : [ children[*]._key, children[*].answers_num, children[*].children_num ] } IN posts"""
|
||||
)
|
||||
|
||||
postos = db.collection('posts')
|
||||
postos = sorted(postos, key=lambda posto: posto['_key'], reverse=False)
|
||||
|
||||
return render_template("i-posts.html", host_id=docker_short_id, postos=postos)
|
||||
|
||||
|
||||
|
||||
@app.route('/post_to_another_post/<post_key>', methods=['POST'])
|
||||
def post_to_post(post_key):
|
||||
|
||||
|
||||
uploaded_file = request.files["file"]
|
||||
|
||||
#### TODO allow only imgs, videos, and gifs
|
||||
if 'file' in request.files:
|
||||
|
||||
if uploaded_file:
|
||||
minioClient = Minio( "static.guaranteedstruggle.host" )
|
||||
bucket_name = "thread-pics"
|
||||
size = os.fstat(uploaded_file.fileno()).st_size
|
||||
|
||||
minioClient.put_object(
|
||||
bucket_name, uploaded_file.filename, uploaded_file, size
|
||||
)
|
||||
files = request.files.getlist("file")
|
||||
for file in files:
|
||||
size = os.fstat(file.fileno()).st_size
|
||||
|
||||
minioClient.put_object(
|
||||
bucket_name, file.filename, file, size
|
||||
)
|
||||
|
||||
|
||||
postos = db.collection('posts')
|
||||
@@ -186,29 +141,6 @@ def post_to_post(post_key):
|
||||
return render_template("i-posts.html", host_id=docker_short_id, postos=postos)
|
||||
|
||||
|
||||
# @app.route('/post_my_file', method=['POST'])
|
||||
# def post_a_file():
|
||||
# pass
|
||||
|
||||
@app.route("/send_dudes", methods=["POST"])
|
||||
def upload_file():
|
||||
|
||||
#### TODO вынести в обычный метод отправки
|
||||
if request.method == "POST":
|
||||
uploaded_file = request.files["file"]
|
||||
|
||||
if uploaded_file:
|
||||
minioClient = Minio( "static.guaranteedstruggle.host" )
|
||||
bucket_name = "thread-pics"
|
||||
size = os.fstat(uploaded_file.fileno()).st_size
|
||||
|
||||
minioClient.put_object(
|
||||
bucket_name, uploaded_file.filename, uploaded_file, size
|
||||
)
|
||||
|
||||
return "OK"
|
||||
|
||||
return " NE OK "
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user