almeira-web/scripts/verify_appwrite_health.py

56 lines
2.6 KiB
Python

import urllib.request
import json
import random
ENDPOINT = "https://appwrite.almeira.com.co/v1"
PROJECT_ID = "69b84df5003bd8957c5c"
BUCKET_ID = "media_bucket"
API_KEY = "standard_cce3cdb866ea6433888d40cedd24dc45987372308fdc3dd0697de08648c0e5c7e04b02c3bcee271403fd656b00a5820f04c08b51631284a6e8a3582d8aed2aa33234f3c29cc777e9b162eb54810b789251b0d006a9a3b081ebc2da53b9baa94614b124b3508ad849fd9a4187cc6094f506d4b57f409b69d9562a74df594f3ec3"
def check_system():
print("=== VERIFICACIÓN DEL SISTEMA APPWRITE TRAS OPTIMIZACIÓN ===")
# 1. List files via Appwrite API
list_url = f"{ENDPOINT}/storage/buckets/{BUCKET_ID}/files?queries[0]=limit(25)"
req = urllib.request.Request(list_url, headers={
"X-Appwrite-Project": PROJECT_ID,
"X-Appwrite-Key": API_KEY
})
with urllib.request.urlopen(req) as resp:
data = json.loads(resp.read().decode('utf-8'))
files = data.get('files', [])
total = data.get('total', 0)
print(f"✓ Total archivos reportados por Appwrite API: {total}")
print(f"✓ Muestra obtenida: {len(files)} archivos.")
# 2. Test HTTP download/view of 5 sample images
print("\n--- Verificando descarga HTTP pública de imágenes ---")
sample_files = random.sample(files, min(5, len(files)))
for f in sample_files:
fid = f['$id']
name = f['name']
mime = f['mimeType']
size = f['sizeOriginal']
view_url = f"{ENDPOINT}/storage/buckets/{BUCKET_ID}/files/{fid}/view?project={PROJECT_ID}"
v_req = urllib.request.Request(view_url, headers={"User-Agent": "Mozilla/5.0"})
with urllib.request.urlopen(v_req) as v_resp:
status = v_resp.status
c_len = v_resp.headers.get("Content-Length")
c_type = v_resp.headers.get("Content-Type")
print(f" ✓ [{status}] ID: {fid} | {name[:30]} | {int(c_len):,} bytes | Type: {c_type}")
# 3. Test Preview endpoint (on-the-fly transformation)
print("\n--- Verificando endpoint de previsualización dinámica (/preview) ---")
test_f = sample_files[0]
prev_url = f"{ENDPOINT}/storage/buckets/{BUCKET_ID}/files/{test_f['$id']}/preview?project={PROJECT_ID}&width=300&output=webp"
p_req = urllib.request.Request(prev_url, headers={"User-Agent": "Mozilla/5.0"})
with urllib.request.urlopen(p_req) as p_resp:
print(f" ✓ [{p_resp.status}] Preview dinámico WebP: {p_resp.headers.get('Content-Type')}, tamaño: {p_resp.headers.get('Content-Length')} bytes")
print("\n✅ TODAS LAS PRUEBAS DE INTEGRIDAD Y DISPONIBILIDAD PASARON EXITOSAMENTE.")
if __name__ == '__main__':
check_system()