Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -569,9 +569,11 @@ HTML_TEMPLATE = """
|
|
| 569 |
}
|
| 570 |
function handleHistoryTouchEnd(e) { clearTimeout(longPressTimer); }
|
| 571 |
|
| 572 |
-
function
|
|
|
|
| 573 |
const item = document.getElementById('chat-' + cid);
|
| 574 |
const titleSpan = item.querySelector('.h-title');
|
|
|
|
| 575 |
|
| 576 |
// Create input
|
| 577 |
const input = document.createElement('input');
|
|
@@ -579,7 +581,6 @@ HTML_TEMPLATE = """
|
|
| 579 |
input.value = currentTitle;
|
| 580 |
input.className = 'rename-input';
|
| 581 |
|
| 582 |
-
// Handle save on Enter or Blur
|
| 583 |
async function save() {
|
| 584 |
const newTitle = input.value.trim();
|
| 585 |
if(newTitle && newTitle !== currentTitle) {
|
|
@@ -589,7 +590,6 @@ HTML_TEMPLATE = """
|
|
| 589 |
});
|
| 590 |
loadHistory();
|
| 591 |
} else {
|
| 592 |
-
// Revert if empty or same
|
| 593 |
loadHistory();
|
| 594 |
}
|
| 595 |
}
|
|
@@ -622,12 +622,13 @@ HTML_TEMPLATE = """
|
|
| 622 |
if (data.chats) {
|
| 623 |
Object.keys(data.chats).reverse().forEach(cid => {
|
| 624 |
const title = data.chats[cid].title || "New Chat";
|
|
|
|
| 625 |
list.innerHTML += `
|
| 626 |
<div class="history-item" id="chat-${cid}" onclick="loadChat('${cid}')" oncontextmenu="return false;"
|
| 627 |
ontouchstart="handleHistoryTouchStart(event, '${cid}')" ontouchend="handleHistoryTouchEnd(event)">
|
| 628 |
<span class="h-title">${title}</span>
|
| 629 |
<div class="h-actions">
|
| 630 |
-
<i class="fas fa-pen h-icon" onclick="event.stopPropagation(); startRename('${cid}'
|
| 631 |
<i class="fas fa-trash h-icon" onclick="event.stopPropagation(); deleteChat('${cid}')"></i>
|
| 632 |
</div>
|
| 633 |
</div>`;
|
|
@@ -681,6 +682,7 @@ HTML_TEMPLATE = """
|
|
| 681 |
box.scrollTop = box.scrollHeight;
|
| 682 |
}
|
| 683 |
|
|
|
|
| 684 |
@app.route('/manifest.json')
|
| 685 |
def manifest():
|
| 686 |
data = {
|
|
@@ -801,5 +803,4 @@ def manifest():
|
|
| 801 |
return Response(json.dumps(data), mimetype='application/json')
|
| 802 |
|
| 803 |
if __name__ == '__main__':
|
| 804 |
-
app.run(host='0.0.0.0', port=7860)
|
| 805 |
-
|
|
|
|
| 569 |
}
|
| 570 |
function handleHistoryTouchEnd(e) { clearTimeout(longPressTimer); }
|
| 571 |
|
| 572 |
+
// SAFE RENAME: We do NOT pass the title in the function call to avoid quotes breaking JS.
|
| 573 |
+
function startRename(cid) {
|
| 574 |
const item = document.getElementById('chat-' + cid);
|
| 575 |
const titleSpan = item.querySelector('.h-title');
|
| 576 |
+
const currentTitle = titleSpan.innerText;
|
| 577 |
|
| 578 |
// Create input
|
| 579 |
const input = document.createElement('input');
|
|
|
|
| 581 |
input.value = currentTitle;
|
| 582 |
input.className = 'rename-input';
|
| 583 |
|
|
|
|
| 584 |
async function save() {
|
| 585 |
const newTitle = input.value.trim();
|
| 586 |
if(newTitle && newTitle !== currentTitle) {
|
|
|
|
| 590 |
});
|
| 591 |
loadHistory();
|
| 592 |
} else {
|
|
|
|
| 593 |
loadHistory();
|
| 594 |
}
|
| 595 |
}
|
|
|
|
| 622 |
if (data.chats) {
|
| 623 |
Object.keys(data.chats).reverse().forEach(cid => {
|
| 624 |
const title = data.chats[cid].title || "New Chat";
|
| 625 |
+
// FIX: Only passing cid to startRename, avoiding syntax errors from titles
|
| 626 |
list.innerHTML += `
|
| 627 |
<div class="history-item" id="chat-${cid}" onclick="loadChat('${cid}')" oncontextmenu="return false;"
|
| 628 |
ontouchstart="handleHistoryTouchStart(event, '${cid}')" ontouchend="handleHistoryTouchEnd(event)">
|
| 629 |
<span class="h-title">${title}</span>
|
| 630 |
<div class="h-actions">
|
| 631 |
+
<i class="fas fa-pen h-icon" onclick="event.stopPropagation(); startRename('${cid}')"></i>
|
| 632 |
<i class="fas fa-trash h-icon" onclick="event.stopPropagation(); deleteChat('${cid}')"></i>
|
| 633 |
</div>
|
| 634 |
</div>`;
|
|
|
|
| 682 |
box.scrollTop = box.scrollHeight;
|
| 683 |
}
|
| 684 |
|
| 685 |
+
// --- MANIFEST FOR APP LOGO ---
|
| 686 |
@app.route('/manifest.json')
|
| 687 |
def manifest():
|
| 688 |
data = {
|
|
|
|
| 803 |
return Response(json.dumps(data), mimetype='application/json')
|
| 804 |
|
| 805 |
if __name__ == '__main__':
|
| 806 |
+
app.run(host='0.0.0.0', port=7860)
|
|
|