att upload
This commit is contained in:
1 parent
33a2a3acdf
commit
3a9e9547b9
63 files changed
+44080
-907767
No files matched your search
@@ -1,16 +1,18 @@
|
||||
import os
|
||||
import subprocess # <--- 1. ADICIONE ISSO
|
||||
from flask import Flask, request, jsonify
|
||||
from flask_cors import CORS
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
# Importa suas funções e configurações existentes
|
||||
from main import process_single_file, rebuild_indexes
|
||||
from utils import MMP_FOLDER, MMPZ_FOLDER
|
||||
|
||||
# 2. ADICIONE BASE_PATH ABAIXO (Assume que utils tem o caminho raiz do projeto)
|
||||
from utils import MMP_FOLDER, MMPZ_FOLDER, CERT_PATH, KEY_PATH, BASE_PATH
|
||||
|
||||
app = Flask(__name__)
|
||||
CORS(app) # Permite que o HTML converse com o servidor
|
||||
CORS(app)
|
||||
|
||||
# Configurações de extensão
|
||||
ALLOWED_EXTENSIONS = {"mmp", "mmpz"}
|
||||
|
||||
|
||||
@@ -18,6 +20,34 @@ def allowed_file(filename):
|
||||
return "." in filename and filename.rsplit(".", 1)[1].lower() in ALLOWED_EXTENSIONS
|
||||
|
||||
|
||||
# --- 3. NOVA FUNÇÃO DE BUILD ---
|
||||
def run_jekyll_build():
|
||||
"""Roda o comando de build do Jekyll."""
|
||||
print("Iniciando build do Jekyll...")
|
||||
|
||||
# O comando que você pediu, separado em lista (mais seguro)
|
||||
command = [
|
||||
"bundle",
|
||||
"exec",
|
||||
"jekyll",
|
||||
"build",
|
||||
"--destination",
|
||||
"/nethome/jotachina/public_html/mmpSearch/",
|
||||
]
|
||||
|
||||
try:
|
||||
# cwd=BASE_PATH garante que o comando rode na pasta onde está o Gemfile
|
||||
result = subprocess.run(
|
||||
command, check=True, cwd=BASE_PATH, capture_output=True, text=True
|
||||
)
|
||||
print("Jekyll Build Sucesso!")
|
||||
print(result.stdout) # Opcional: ver log do jekyll
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"ERRO no Jekyll Build: {e.stderr}")
|
||||
# Não vamos travar o retorno para o usuário se o site falhar,
|
||||
# mas logamos o erro no console do servidor.
|
||||
|
||||
|
||||
@app.route("/api/upload", methods=["POST"])
|
||||
def upload_file():
|
||||
# 1. Verificações Básicas
|
||||
@@ -32,29 +62,34 @@ def upload_file():
|
||||
if file and allowed_file(file.filename):
|
||||
filename = secure_filename(file.filename)
|
||||
|
||||
# 2. Define onde salvar (MMP ou MMPZ)
|
||||
if filename.endswith(".mmpz"):
|
||||
save_path = os.path.join(MMPZ_FOLDER, filename)
|
||||
else:
|
||||
save_path = os.path.join(MMP_FOLDER, filename)
|
||||
|
||||
# Salva o arquivo físico
|
||||
try:
|
||||
file.save(save_path)
|
||||
print(f"Arquivo salvo em: {save_path}")
|
||||
except Exception as e:
|
||||
return jsonify({"error": f"Falha ao salvar disco: {str(e)}"}), 500
|
||||
|
||||
# 3. DISPARA SEU PIPELINE (Processamento)
|
||||
# Chama a função do seu main.py para gerar WAV e extrair dados
|
||||
# 3. DISPARA SEU PIPELINE
|
||||
result = process_single_file(filename)
|
||||
|
||||
if result["success"]:
|
||||
# 4. Atualiza o site.data.all (all.json)
|
||||
rebuild_indexes()
|
||||
|
||||
# --- 5. AQUI ESTÁ A MÁGICA ---
|
||||
# Só roda se o processamento e o indice derem certo
|
||||
run_jekyll_build()
|
||||
# -----------------------------
|
||||
|
||||
return jsonify(
|
||||
{"message": "Projeto processado com sucesso!", "data": result["data"]}
|
||||
{
|
||||
"message": "Projeto processado e Site Atualizado!",
|
||||
"data": result["data"],
|
||||
}
|
||||
), 200
|
||||
else:
|
||||
return jsonify({"error": f"Erro no processamento: {result['error']}"}), 500
|
||||
@@ -65,15 +100,10 @@ def upload_file():
|
||||
if __name__ == "__main__":
|
||||
print("Iniciando Servidor de Upload MMP...")
|
||||
|
||||
# Tenta localizar os certificados reais do servidor (Comum em servidores Linux/Apache/Nginx)
|
||||
# Ajuste esses caminhos se souber onde os certificados do alice.ufsj.edu.br estão
|
||||
cert_path = "/etc/letsencrypt/live/alice.ufsj.edu.br/fullchain.pem"
|
||||
key_path = "/etc/letsencrypt/live/alice.ufsj.edu.br/privkey.pem"
|
||||
|
||||
# Opção 1: Usar certificado real (O ideal - Navegador aceita de primeira)
|
||||
if os.path.exists(cert_path) and os.path.exists(key_path):
|
||||
if os.path.exists(CERT_PATH) and os.path.exists(KEY_PATH):
|
||||
print("Certificados encontrados! Rodando HTTPS seguro na porta 33002.")
|
||||
context = (cert_path, key_path)
|
||||
context = (CERT_PATH, KEY_PATH)
|
||||
# Use host='0.0.0.0' para garantir que escute externamente
|
||||
app.run(host="0.0.0.0", port=33002, ssl_context=context, debug=True)
|
||||
|
||||
|
||||
Reference in new issue
Block a user