diff --git a/rotary_phone_web.py b/rotary_phone_web.py index e591ae0..db225d0 100644 --- a/rotary_phone_web.py +++ b/rotary_phone_web.py @@ -81,7 +81,7 @@ BACKUP_ON_WRITE = BACKUP_CONFIG.get('backup_on_write', True) WEB_PORT = SYS_CONFIG['web']['port'] # Template version - increment this when HTML template changes -TEMPLATE_VERSION = "1.5.0" # Updated: Redesigned sound selection with dropdowns +TEMPLATE_VERSION = "1.6.0" # Updated: Added rename functionality for recordings # Flask app app = Flask(__name__) @@ -945,6 +945,40 @@ def delete_recording(filename): return jsonify({"success": True}) return jsonify({"error": "File not found"}), 404 +@app.route('/rename/', methods=['POST']) +def rename_recording(filename): + """Rename a recording""" + data = request.get_json() + new_name = data.get('new_name', '').strip() + + if not new_name: + return jsonify({"error": "New name is required"}), 400 + + # Ensure .wav extension + if not new_name.endswith('.wav'): + new_name += '.wav' + + # Sanitize filenames + old_filepath = os.path.join(OUTPUT_DIR, secure_filename(filename)) + new_filepath = os.path.join(OUTPUT_DIR, secure_filename(new_name)) + + if not os.path.exists(old_filepath): + return jsonify({"error": "File not found"}), 404 + + if os.path.exists(new_filepath): + return jsonify({"error": "A file with that name already exists"}), 409 + + try: + os.rename(old_filepath, new_filepath) + + # Also backup renamed file if backup is enabled + if SYS_CONFIG['backup']['enabled'] and SYS_CONFIG['backup']['backup_on_write']: + backup_file_to_usb(new_filepath, 'recordings') + + return jsonify({"success": True, "new_name": secure_filename(new_name)}) + except Exception as e: + return jsonify({"error": str(e)}), 500 + @app.route('/restore_default_sound', methods=['POST']) def restore_default_sound(): """Restore default dial tone""" @@ -1752,10 +1786,10 @@ def main(): {% for recording in recordings %}
-

{{ recording.filename }}

+

{{ recording.filename }}

- 📅 {{ recording.date }} | - ⏱️ {{ "%.1f"|format(recording.duration) }}s | + 📅 {{ recording.date }} | + ⏱️ {{ "%.1f"|format(recording.duration) }}s | 💾 {{ "%.2f"|format(recording.size_mb) }} MB
@@ -1766,6 +1800,9 @@ def main(): + @@ -1985,6 +2022,30 @@ def main(): } } + function renameRecording(filename, index) { + // Remove .wav extension for cleaner input + const nameWithoutExt = filename.replace('.wav', ''); + const newName = prompt('Enter new name for recording:', nameWithoutExt); + + if (newName && newName.trim() !== '' && newName !== nameWithoutExt) { + fetch('/rename/' + filename, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ new_name: newName.trim() }) + }) + .then(response => response.json()) + .then(data => { + if (data.success) { + showAlert('Recording renamed! ✓', 'success'); + setTimeout(() => location.reload(), 1500); + } else { + showAlert('Error: ' + data.error, 'error'); + } + }) + .catch(error => showAlert('Error: ' + error, 'error')); + } + } + function playAudio(type, filename) { const modal = document.getElementById('audio-modal'); const player = document.getElementById('audio-player');