upload de samples
This commit is contained in:
1 parent
826147c667
commit
e38f1ea662
5 files changed
+347726
-340435
No files matched your search
@@ -8,7 +8,7 @@ from werkzeug.utils import secure_filename
|
||||
from main import process_single_file, rebuild_indexes, generate_manifests
|
||||
|
||||
# 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_DATA, SRC_MMPSEARCH
|
||||
from utils import MMP_FOLDER, MMPZ_FOLDER, CERT_PATH, KEY_PATH, BASE_DATA, SRC_MMPSEARCH, SAMPLE_SRC
|
||||
|
||||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
@@ -101,6 +101,62 @@ def upload_file():
|
||||
|
||||
return jsonify({"error": "Tipo de arquivo não permitido"}), 400
|
||||
|
||||
ALLOWED_SAMPLE_EXTENSIONS = {'wav', 'mp3', 'ogg', 'flac'}
|
||||
|
||||
def allowed_sample(filename):
|
||||
return '.' in filename and \
|
||||
filename.rsplit('.', 1)[1].lower() in ALLOWED_SAMPLE_EXTENSIONS
|
||||
|
||||
@app.route('/api/upload/sample', methods=['POST'])
|
||||
def upload_sample():
|
||||
if 'sample_file' not in request.files:
|
||||
return jsonify({'error': 'Nenhum arquivo enviado'}), 400
|
||||
|
||||
file = request.files['sample_file']
|
||||
# Pega a subpasta (opcional), ex: "Drums/Kicks"
|
||||
subfolder = request.form.get('subfolder', '').strip()
|
||||
|
||||
if file.filename == '':
|
||||
return jsonify({'error': 'Nome do arquivo vazio'}), 400
|
||||
|
||||
if file and allowed_sample(file.filename):
|
||||
filename = secure_filename(file.filename)
|
||||
|
||||
# Define o caminho final (Raiz de samples + Subpasta)
|
||||
# Evita "directory traversal" removendo ..
|
||||
safe_subfolder = subfolder.replace('..', '').strip('/')
|
||||
target_dir = os.path.join(SAMPLE_SRC, safe_subfolder)
|
||||
|
||||
# Cria a pasta se não existir
|
||||
if not os.path.exists(target_dir):
|
||||
try:
|
||||
os.makedirs(target_dir, exist_ok=True)
|
||||
# Garante permissão para o grupo www-data
|
||||
os.system(f"chmod -R 775 {target_dir}")
|
||||
except Exception as e:
|
||||
return jsonify({'error': f"Erro ao criar pasta: {str(e)}"}), 500
|
||||
|
||||
save_path = os.path.join(target_dir, filename)
|
||||
|
||||
try:
|
||||
file.save(save_path)
|
||||
# Garante permissão do arquivo
|
||||
os.chmod(save_path, 0o664)
|
||||
print(f"Sample salvo em: {save_path}")
|
||||
|
||||
# 1. Regenerar o manifesto (samples-manifest.json)
|
||||
# Passamos SRC_MMPSEARCH pois o generate_manifests espera a raiz do projeto
|
||||
generate_manifests(SRC_MMPSEARCH)
|
||||
|
||||
# 2. Reconstruir o site (para o Jekyll ler o novo JSON)
|
||||
run_jekyll_build()
|
||||
|
||||
return jsonify({'message': 'Sample enviado e biblioteca atualizada!'}), 200
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({'error': f"Falha ao processar: {str(e)}"}), 500
|
||||
|
||||
return jsonify({'error': 'Tipo de arquivo não permitido (apenas wav, mp3, ogg, flac)'}), 400
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Iniciando Servidor de Upload MMP...")
|
||||
|
||||
Reference in new issue
Block a user