bep40 commited on
Commit
d8ed42e
·
verified ·
1 Parent(s): 8ab2850

FIX share/send-MP4: remove broken duplicate shareVideoToApps (link-only shadowed the file-share version); keep file-share (fetch blob->File->navigator.share({files})) + re-add downloadVideo fallback for desktop. doShare unchanged.

Browse files
Files changed (1) hide show
  1. static/app_v2.js +4 -27
static/app_v2.js CHANGED
@@ -124,7 +124,8 @@ async function shareVideoToApps(videoUrl, title){
124
  }
125
  } catch(e){ /* fall through to link share */ }
126
  }
127
- const shareUrl = (typeof SPACE !== 'undefined' ? SPACE : location.origin) + '/s?url=' + encodeURIComponent(videoUrl) + '&title=' + encodeURIComponent(safeTitle);
 
128
  if(navigator.share){
129
  try { await navigator.share({title: safeTitle, text: safeTitle, url: shareUrl}); return; } catch(e){ if(e && e.name === 'AbortError') return; }
130
  }
@@ -576,34 +577,10 @@ async function rewriteSlide(url){if(!url)return;const btn=document.querySelector
576
  if(j.slides && j.slides.length){showView('view-article');const el=document.getElementById('view-article');let h=`<button class="back-btn" onclick="switchCat('home')">← Tường AI</button><div class="slide-viewer" style="padding:12px;max-width:600px;margin:0 auto">`;j.slides.forEach(s=>{h+=`<div class="slide-card" style="background:#1a1a1a;border:1px solid #2a2a2a;border-radius:12px;padding:16px;margin-bottom:12px"><div class="slide-num" style="color:#5cb87a;font-size:12px;font-weight:700;margin-bottom:6px">Slide ${s.index}/${j.slides.length}</div>${s.image?`<img src="${s.image.startsWith('/api/')?s.image:'/api/proxy/img?url='+encodeURIComponent(s.image)}" style="width:100%;max-height:300px;object-fit:cover;border-radius:8px;margin-bottom:8px" loading="lazy" onerror="this.style.display='none'">`:''}<p style="color:#ddd;font-size:14px;line-height:1.6;margin:0">${esc(s.text)}</p></div>`;});h+=`</div><div style="text-align:center;padding:12px"><div id="short-ai-status" style="color:#888;font-size:12px">⏳ Đang tạo video Short AI...</div></div>`;el.innerHTML=h;}
577
  const postId=j.post&&j.post.id;if(postId){setTimeout(async()=>{const sr=await fetch('/api/ai/short/'+encodeURIComponent(postId),{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({voice:'vi-VN-HoaiMyNeural',emotion:'neutral',speed:1.2})});const sj=await sr.json();if(sr.ok&&sj.video&&typeof _wallPosts!=='undefined'){const p=_wallPosts.find(x=>String(x.id)===String(postId));if(p){p.video=sj.video;const itemId='wall-item-'+postId;const el2=document.getElementById(itemId);if(el2){const idx=_wallPosts.indexOf(p);el2.insertAdjacentHTML('afterend',makeWallItem(p,idx));el2.remove();}}toast('✅ Short AI đã sẵn sàng!');const statusEl=document.getElementById('short-ai-status');if(statusEl)statusEl.innerHTML='✅ Short AI đẵn sàng! <button class="primary" onclick="openShortAIFeed(0)" style="background:#2d8659;border:0;color:#fff;padding:6px 12px;border-radius:10px;font-size:11px;cursor:pointer;margin-left:8px">▶ Xem ngay</button>';}},500);}if(btn)btn.textContent='✅ Hoàn tất';}catch(e){toast('❌ '+e.message);if(btn){btn.disabled=false;btn.textContent='🤖 Slide Rewrite AI';}}}
578
 
579
- // ===== SHARE VIDEO TO OTHER APPS =====
580
- function shareVideoToApps(videoUrl, title){
581
- if(!videoUrl){
582
- toast('Không có video để chia sẻ');
583
- return;
584
- }
585
- var fullUrl = videoUrl.startsWith('http') ? videoUrl : window.location.origin + videoUrl;
586
-
587
- // Step 1: Try navigator.share with URL (async, works on mobile)
588
- try{
589
- if(navigator.share){
590
- navigator.share({
591
- title: title || 'Short AI Video',
592
- url: fullUrl
593
- }).then(function(){toast('✅ Đã chia sẻ!');return;}).catch(function(e){
594
- if(e.name==='AbortError')return;
595
- downloadVideo(fullUrl, title);
596
- });
597
- return;
598
- }
599
- }catch(e){}
600
- // Step 2: Fallback - download
601
- downloadVideo(fullUrl, title);
602
- }
603
  function downloadVideo(url, title){
604
  var a = document.createElement('a');
605
  a.href = url;
606
- a.download = (title||'video').replace(/[^a-zA-Z0-9_\-\p{L}]/gu,'_').substring(0,60)+'.mp4';
607
  a.target = '_blank';
608
  a.rel = 'noopener';
609
  a.style.display = 'none';
@@ -611,4 +588,4 @@ function downloadVideo(url, title){
611
  a.click();
612
  document.body.removeChild(a);
613
  toast('📥 Đang tải video xuống...');
614
- }
 
124
  }
125
  } catch(e){ /* fall through to link share */ }
126
  }
127
+ const _base = (typeof SPACE !== 'undefined' && SPACE) ? SPACE : location.origin;
128
+ const shareUrl = _base + '/s?url=' + encodeURIComponent(videoUrl) + '&title=' + encodeURIComponent(safeTitle);
129
  if(navigator.share){
130
  try { await navigator.share({title: safeTitle, text: safeTitle, url: shareUrl}); return; } catch(e){ if(e && e.name === 'AbortError') return; }
131
  }
 
577
  if(j.slides && j.slides.length){showView('view-article');const el=document.getElementById('view-article');let h=`<button class="back-btn" onclick="switchCat('home')">← Tường AI</button><div class="slide-viewer" style="padding:12px;max-width:600px;margin:0 auto">`;j.slides.forEach(s=>{h+=`<div class="slide-card" style="background:#1a1a1a;border:1px solid #2a2a2a;border-radius:12px;padding:16px;margin-bottom:12px"><div class="slide-num" style="color:#5cb87a;font-size:12px;font-weight:700;margin-bottom:6px">Slide ${s.index}/${j.slides.length}</div>${s.image?`<img src="${s.image.startsWith('/api/')?s.image:'/api/proxy/img?url='+encodeURIComponent(s.image)}" style="width:100%;max-height:300px;object-fit:cover;border-radius:8px;margin-bottom:8px" loading="lazy" onerror="this.style.display='none'">`:''}<p style="color:#ddd;font-size:14px;line-height:1.6;margin:0">${esc(s.text)}</p></div>`;});h+=`</div><div style="text-align:center;padding:12px"><div id="short-ai-status" style="color:#888;font-size:12px">⏳ Đang tạo video Short AI...</div></div>`;el.innerHTML=h;}
578
  const postId=j.post&&j.post.id;if(postId){setTimeout(async()=>{const sr=await fetch('/api/ai/short/'+encodeURIComponent(postId),{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({voice:'vi-VN-HoaiMyNeural',emotion:'neutral',speed:1.2})});const sj=await sr.json();if(sr.ok&&sj.video&&typeof _wallPosts!=='undefined'){const p=_wallPosts.find(x=>String(x.id)===String(postId));if(p){p.video=sj.video;const itemId='wall-item-'+postId;const el2=document.getElementById(itemId);if(el2){const idx=_wallPosts.indexOf(p);el2.insertAdjacentHTML('afterend',makeWallItem(p,idx));el2.remove();}}toast('✅ Short AI đã sẵn sàng!');const statusEl=document.getElementById('short-ai-status');if(statusEl)statusEl.innerHTML='✅ Short AI đẵn sàng! <button class="primary" onclick="openShortAIFeed(0)" style="background:#2d8659;border:0;color:#fff;padding:6px 12px;border-radius:10px;font-size:11px;cursor:pointer;margin-left:8px">▶ Xem ngay</button>';}},500);}if(btn)btn.textContent='✅ Hoàn tất';}catch(e){toast('❌ '+e.message);if(btn){btn.disabled=false;btn.textContent='🤖 Slide Rewrite AI';}}}
579
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
580
  function downloadVideo(url, title){
581
  var a = document.createElement('a');
582
  a.href = url;
583
+ a.download = (title||'video').toString().replace(/[^a-zA-Z0-9_\-\p{L}]/gu,'_').substring(0,60)+'.mp4';
584
  a.target = '_blank';
585
  a.rel = 'noopener';
586
  a.style.display = 'none';
 
588
  a.click();
589
  document.body.removeChild(a);
590
  toast('📥 Đang tải video xuống...');
591
+ }