bep40 commited on
Commit
a3918ef
·
verified ·
1 Parent(s): a38a3b7

Fix: No-op rewrite_fix_v2.js — all voice/emotion/slide logic now built into app_v2.js to fix conflicts

Browse files
Files changed (1) hide show
  1. rewrite_fix_v2.js +5 -238
rewrite_fix_v2.js CHANGED
@@ -1,240 +1,7 @@
1
- // Fix rewriteArticle - call correct endpoint for VNEWS
2
- // Uses /api/rewrite_share which now returns {post, slides}
3
- // Includes full multilingual voice + emotion UI
4
-
5
  (function(){
6
- // Full voice list with languages and emotions
7
- const VOICE_OPTIONS = [
8
- {id:'hoaimy', label:'🎙️ Hoài My (VI)', lang:'vi'},
9
- {id:'namminh', label:'🎙️ Nam Minh (VI)', lang:'vi'},
10
- {id:'andrew', label:'🎙️ Andrew (Multilingual)', lang:'en'},
11
- {id:'jenny', label:'🎙️ Jenny (EN)', lang:'en'},
12
- {id:'thalita', label:'🎙️ Thalita (PT)', lang:'pt'},
13
- {id:'pt_francisco', label:'🎙️ Francisco (PT)', lang:'pt'},
14
- {id:'ela', label:'🎙️ Ela (ES)', lang:'es'},
15
- {id:'es_carlos', label:'🎙️ Carlos (ES)', lang:'es'},
16
- {id:'denise', label:'🎙️ Denise (FR)', lang:'fr'},
17
- {id:'katja', label:'🎙️ Katja (DE)', lang:'de'},
18
- {id:'nanami', label:'🎙️ Nanami (JA)', lang:'ja'},
19
- {id:'sunhee', label:'🎙️ SunHee (KO)', lang:'ko'},
20
- {id:'xiaochen', label:'🎙️ XiaoChen (ZH)', lang:'zh'},
21
- ];
22
-
23
- const EMOTION_OPTIONS = [
24
- {id:'neutral', label:'😐 Trung tính', emoji:'😐'},
25
- {id:'happy', label:'😊 Vui vẻ', emoji:'😊'},
26
- {id='excited', label:'🔥 Hào hứng', emoji:'🔥'},
27
- {id:'sad', label:'😢 Buồn', emoji:'😢'},
28
- {id:'humorous', label:'😂 Hài hước', emoji:'😂'},
29
- {id:'serious', label:'⚠️ Nghiêm túc', emoji:'⚠️'},
30
- {id:'urgent', label:'🚨 Khẩn cấp', emoji:'🚨'},
31
- {id:'warm', label:'💖 Ấm áp', emoji:'💖'},
32
- ];
33
-
34
- window.rewriteArticle = async function(){
35
- var url = window._currentArticle && window._currentArticle.url;
36
- if(!url) return;
37
- toast('⏳ Đang tạo bài đăng Tường AI...');
38
- try {
39
- var r = await fetch('/api/rewrite_share', {
40
- method: 'POST',
41
- headers: {'Content-Type': 'application/json'},
42
- body: JSON.stringify({url: url, context: document.querySelector('.article-view') ? document.querySelector('.article-view').innerText.slice(0,14000) : ''})
43
- });
44
- var j = await r.json();
45
- if (!r.ok || j.error) throw new Error(j.error);
46
- toast('✅ Đã đăng Tường AI!');
47
- if (j.post) prependWallPost(j.post);
48
- if (j.post && typeof goToWallPost === 'function') goToWallPost(j.post.id);
49
- // Show slides if available
50
- if (j.slides && j.slides.length) {
51
- setTimeout(function(){ showSlidePreview(j.slides, j.post ? j.post.title : ''); }, 500);
52
- }
53
- // Show voice + emotion selector
54
- if (j.post && !j.post.video) {
55
- setTimeout(function(){ showVoiceEmotionSelector(j.post.id, j.post.title, j.post.text); }, 1000);
56
- }
57
- } catch(e) {
58
- toast('❌ ' + e.message);
59
- }
60
- };
61
-
62
- // Full voice + emotion selector popup
63
- window.showVoiceEmotionSelector = function(postId, title, text) {
64
- var overlay = document.createElement('div');
65
- overlay.id = 'voice-emotion-selector';
66
- overlay.style.cssText = 'position:fixed;inset:0;background:rgba(0,0,0,.85);z-index:99999;display:flex;align-items:center;justify-content:center;padding:16px';
67
-
68
- var box = document.createElement('div');
69
- box.style.cssText = 'background:#1a1a1a;border:2px solid #2d8659;border-radius:16px;padding:20px;max-width:400px;width:100%;max-height:80vh;overflow-y:auto';
70
-
71
- var h = '<h3 style="color:#5cb87a;margin-bottom:12px;font-size:16px">🎬 Tạo Short AI</h3>';
72
-
73
- // Voice selection
74
- h += '<div style="margin-bottom:12px"><div style="color:#aaa;font-size:11px;margin-bottom:6px">🎙️ Chọn giọng đọc:</div>';
75
- VOICE_OPTIONS.forEach(function(v){
76
- h += '<button class="ve-voice-btn" data-voice="'+v.id+'" style="display:inline-block;background:#222;border:1px solid #333;color:#ccc;padding:5px 10px;border-radius:12px;font-size:10px;margin:2px;cursor:pointer" onmouseover="this.style.background=\'#333\'" onmouseout="this.style.background=\'#222\'">'+esc(v.label)+'</button>';
77
- });
78
- h += '</div>';
79
-
80
- // Emotion selection
81
- h += '<div style="margin-bottom:12px"><div style="color:#aaa;font-size:11px;margin-bottom:6px">😊 Chọn cảm xúc:</div>';
82
- EMOTION_OPTIONS.forEach(function(e){
83
- h += '<button class="ve-emotion-btn" data-emotion="'+e.id+'" style="display:inline-block;background:#222;border:1px solid #333;color:#ccc;padding:5px 10px;border-radius:12px;font-size:10px;margin:2px;cursor:pointer" onmouseover="this.style.background=\'#333\'" onmouseout="this.style.background=\'#222\'">'+esc(e.label)+'</button>';
84
- });
85
- h += '</div>';
86
-
87
- // Speed
88
- h += '<div style="margin-bottom:12px"><div style="color:#aaa;font-size:11px;margin-bottom:6px">⚡ Tốc độ:</div>';
89
- h += '<select id="ve-speed" style="background:#222;border:1px solid #333;color:#ccc;padding:6px 12px;border-radius:10px;font-size:11px">';
90
- h += '<option value="0.85">0.85x — Chậm</option>';
91
- h += '<option value="1.0">1.0x — Bình thường</option>';
92
- h += '<option value="1.2" selected>1.2x — Nhanh</option>';
93
- h += '<option value="1.35">1.35x — Rất nhanh</option>';
94
- h += '</select></div>';
95
-
96
- // Actions
97
- h += '<div style="display:flex;gap:8px;margin-top:12px">';
98
- h += '<button id="ve-create-btn" style="flex:1;background:#2d8659;border:0;color:#fff;padding:10px;border-radius:12px;font-size:12px;font-weight:700;cursor:pointer">🎬 Tạo Short</button>';
99
- h += '<button id="ve-cancel-btn" style="background:#333;border:0;color:#ccc;padding:10px 16px;border-radius:12px;font-size:11px;cursor:pointer">✕</button>';
100
- h += '</div>';
101
-
102
- // Status
103
- h += '<div id="ve-status" style="color:#888;font-size:10px;margin-top:8px;display:none"></div>';
104
-
105
- box.innerHTML = h;
106
- overlay.appendChild(box);
107
- document.body.appendChild(overlay);
108
-
109
- var selectedVoice = 'hoaimy';
110
- var selectedEmotion = 'neutral';
111
-
112
- // Voice click handlers
113
- box.querySelectorAll('.ve-voice-btn').forEach(function(btn){
114
- btn.addEventListener('click', function(){
115
- box.querySelectorAll('.ve-voice-btn').forEach(function(b){b.style.borderColor='#333';b.style.background='#222';});
116
- this.style.borderColor='#5cb87a';
117
- this.style.background='#1a2a1f';
118
- selectedVoice = this.dataset.voice;
119
- });
120
- });
121
- // Select first voice by default
122
- box.querySelector('.ve-voice-btn').style.borderColor = '#5cb87a';
123
- box.querySelector('.ve-voice-btn').style.background = '#1a2a1f';
124
-
125
- // Emotion click handlers
126
- box.querySelectorAll('.ve-emotion-btn').forEach(function(btn){
127
- btn.addEventListener('click', function(){
128
- box.querySelectorAll('.ve-emotion-btn').forEach(function(b){b.style.borderColor='#333';b.style.background='#222';});
129
- this.style.borderColor='#5cb87a';
130
- this.style.background='#1a2a1f';
131
- selectedEmotion = this.dataset.emotion;
132
- });
133
- });
134
- // Select first emotion by default
135
- box.querySelector('.ve-emotion-btn').style.borderColor = '#5cb87a';
136
- box.querySelector('.ve-emotion-btn').style.background = '#1a2a1f';
137
-
138
- // Cancel
139
- box.querySelector('#ve-cancel-btn').addEventListener('click', function(){
140
- overlay.remove();
141
- });
142
-
143
- // Create short
144
- box.querySelector('#ve-create-btn').addEventListener('click', async function(){
145
- this.disabled = true;
146
- this.textContent = '⏳ Đang tạo...';
147
- box.querySelector('#ve-status').style.display = 'block';
148
- box.querySelector('#ve-status').textContent = 'Đang tạo video shorts (có thể mất 1-3 phút)...';
149
-
150
- try {
151
- var speed = parseFloat(box.querySelector('#ve-speed').value) || 1.2;
152
- var r = await fetch('/api/ai/short/' + encodeURIComponent(postId), {
153
- method: 'POST',
154
- headers: {'Content-Type': 'application/json'},
155
- body: JSON.stringify({voice: selectedVoice, emotion: selectedEmotion, speed: speed})
156
- });
157
- var j = await r.json();
158
- if (!r.ok || j.error) throw new Error(j.error || 'Lỗi tạo video');
159
- toast('✅ Đã tạo Short AI!');
160
- overlay.remove();
161
- // Update wall
162
- var p = _wallPosts.find(function(x){return String(x.id)===String(postId);});
163
- if (p) {
164
- p.video = j.video;
165
- p.voice = j.voice;
166
- p.emotion = j.emotion;
167
- }
168
- // Refresh wall view
169
- var track = document.getElementById('ai-wall-track');
170
- if (track) {
171
- var idx = _wallPosts.findIndex(function(x){return String(x.id)===String(postId);});
172
- if (idx >= 0) {
173
- var el = track.children[idx];
174
- if (el) el.outerHTML = makeWallItem(p, idx);
175
- }
176
- }
177
- refreshShortAISlider();
178
- } catch(e) {
179
- this.disabled = false;
180
- this.textContent = '🎬 Tạo Short';
181
- box.querySelector('#ve-status').textContent = '❌ ' + e.message;
182
- }
183
- });
184
- };
185
-
186
- // Show slides as fullscreen overlay
187
- window.showSlidePreview = function(slides, title) {
188
- if (!slides || !slides.length) return;
189
- var overlay = document.createElement('div');
190
- overlay.id = 'slide-preview';
191
- overlay.style.cssText = 'position:fixed;inset:0;background:#000;z-index:99999;display:flex;flex-direction:column;overflow:hidden';
192
-
193
- var currentSlide = 0;
194
- function renderSlide(idx) {
195
- var s = slides[idx];
196
- overlay.innerHTML = '<div style="position:absolute;top:10px;left:10px;right:10px;display:flex;justify-content:space-between;align-items:center;z-index:2">' +
197
- '<button onclick="document.getElementById(\'slide-preview\').remove()" style="background:rgba(0,0,0,.6);border:0;color:#fff;padding:8px 14px;border-radius:20px;font-size:12px;cursor:pointer">✕ Đóng</button>' +
198
- '<span style="color:#fff;font-size:11px;background:rgba(0,0,0,.6);padding:4px 10px;border-radius:10px">' + (idx+1) + '/' + slides.length + '</span>' +
199
- '<button onclick="document.getElementById(\'slide-preview\').remove()" style="background:rgba(0,0,0,.6);border:0;color:#fff;padding:8px 14px;border-radius:20px;font-size:12px;cursor:pointer">✕</button>' +
200
- '</div>' +
201
- '<div style="flex:1;display:flex;align-items:center;justify-content:center;padding:20px">' +
202
- (s.image ? '<img src="' + esc(s.image) + '" style="max-width:100%;max-height:60vh;border-radius:10px;object-fit:contain" onerror="this.style.display=\'none\'">' : '') +
203
- '</div>' +
204
- '<div style="padding:16px 20px;background:linear-gradient(transparent,rgba(0,0,0,.9));min-height:100px">' +
205
- '<p style="color:#fff;font-size:14px;line-height:1.6;text-align:center">' + esc(s.text) + '</p>' +
206
- '</div>' +
207
- '<div style="display:flex;gap:10px;padding:10px 20px 20px;justify-content:center">' +
208
- '<button onclick="prevSlide()" style="background:#333;border:0;color:#fff;padding:10px 20px;border-radius:20px;font-size:12px;cursor:pointer"' + (idx===0?' disabled style="opacity:.3"':'') + '>← Trước</button>' +
209
- '<button onclick="nextSlideRip(currentSlide)" id="slide-next-btn" style="background:#2d8659;border:0;color:#fff;padding:10px 20px;border-radius:20px;font-size:12px;cursor:pointer"' + (idx===slides.length-1?' disabled style="opacity:.3"':'') + '>Tiếp →</button>' +
210
- '</div>';
211
- }
212
-
213
- window.nextSlideRip = function(currentIdx) { if (currentIdx < slides.length - 1) { currentSlide = currentIdx + 1; renderSlide(currentSlide); } };
214
- window.prevSlide = function() { if (currentSlide > 0) { currentSlide--; renderSlide(currentSlide); } };
215
-
216
- // Fix: update next button onclick properly
217
- var origRender = renderSlide;
218
- renderSlide = function(idx) {
219
- currentSlide = idx;
220
- origRender(idx);
221
- var nextBtn = document.getElementById('slide-next-btn');
222
- if (nextBtn) {
223
- nextBtn.onclick = function(){ if (idx < slides.length - 1) { currentSlide = idx + 1; renderSlide(currentSlide); } };
224
- nextBtn.disabled = (idx === slides.length - 1);
225
- nextBtn.style.opacity = (idx === slides.length - 1) ? '.3' : '1';
226
- }
227
- };
228
-
229
- renderSlide(0);
230
- document.body.appendChild(overlay);
231
-
232
- var startX = 0;
233
- overlay.addEventListener('touchstart', function(e) { startX = e.touches[0].clientX; });
234
- overlay.addEventListener('touchend', function(e) {
235
- var diff = e.changedTouches[0].clientX - startX;
236
- if (diff < -50) window.nextSlideRip(currentSlide);
237
- else if (diff > 50) window.prevSlide();
238
- });
239
- };
240
  })();
 
1
+ // rewrite_fix_v2.js - No-op patch
2
+ // All voice+emotion+slide functionality is now built into app_v2.js directly.
3
+ // This file is kept for backward compatibility but does not override any functions.
 
4
  (function(){
5
+ // No patches needed - everything is in app_v2.js
6
+ console.log("[VNEWS] Voice+emotion+slide system loaded (built-in)");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  })();