hueta
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
#!/usr/bin/python3
|
||||
from flask import Flask, render_template, request, redirect, abort
|
||||
import os
|
||||
import requests as r
|
||||
app = Flask(__name__, template_folder='files')
|
||||
database_node_port = 5002
|
||||
content_node_port = 5004
|
||||
database_node = "database:" + str(database_node_port)
|
||||
INTERNAL = os.environ.get("RUSGRAM_INTERNAL", "e9b2f6d14a8c7035e1d0a6b8c4f2e7a9")
|
||||
DBH = {"X-Internal": INTERNAL}
|
||||
|
||||
# PATCH V1/V5: template_folder ('files') — это тот же том, где лежит db/users/<логин>.
|
||||
# Раньше render_template(path) с путём из URL позволял отрендерить файл юзера
|
||||
@@ -27,7 +30,8 @@ def get_login():
|
||||
if not username:
|
||||
return None
|
||||
try:
|
||||
resp = r.get(f"http://{database_node}/users/{username}/password", timeout=5)
|
||||
resp = r.get(f"http://{database_node}/users/{username}/password",
|
||||
headers=DBH, timeout=5)
|
||||
if resp.status_code != 200: # PATCH V8: раньше KeyError -> 500
|
||||
return None
|
||||
if resp.json().get("data") != password:
|
||||
@@ -39,7 +43,8 @@ def get_login():
|
||||
|
||||
def _field(username, name):
|
||||
try:
|
||||
resp = r.get(f"http://{database_node}/users/{username}/{name}", timeout=5)
|
||||
resp = r.get(f"http://{database_node}/users/{username}/{name}",
|
||||
headers=DBH, timeout=5)
|
||||
return resp.json()["data"] if resp.status_code == 200 else ""
|
||||
except (r.RequestException, ValueError, KeyError):
|
||||
return ""
|
||||
@@ -53,7 +58,8 @@ def route(path):
|
||||
imgs = list()
|
||||
for i in range(IMG_MIN, IMG_MAX + 1):
|
||||
try:
|
||||
imgs.append(r.get(f"http://{database_node}/images/{i}", timeout=5).json()["data"])
|
||||
imgs.append(r.get(f"http://{database_node}/images/{i}",
|
||||
headers=DBH, timeout=5).json()["data"])
|
||||
except (r.RequestException, ValueError, KeyError):
|
||||
continue
|
||||
imgs[-1]["id"] = str(i).zfill(2)
|
||||
@@ -76,7 +82,8 @@ def route(path):
|
||||
if not (IMG_MIN <= img_id <= IMG_MAX):
|
||||
abort(404)
|
||||
try:
|
||||
img = r.get(f"http://{database_node}/images/{img_id}", timeout=5).json()["data"]
|
||||
img = r.get(f"http://{database_node}/images/{img_id}",
|
||||
headers=DBH, timeout=5).json()["data"]
|
||||
except (r.RequestException, ValueError, KeyError):
|
||||
abort(404)
|
||||
img["id"] = str(img_id).zfill(2)
|
||||
|
||||
Reference in New Issue
Block a user