Vanderson da Silva Quintino commited on
Commit
2d3aa2b
·
1 Parent(s): d6db4e5

feat: add delete video

Browse files
src/ClipForge.Api/Endpoints/VideoEndpoints.cs CHANGED
@@ -3,6 +3,7 @@ using ClipForge.Contracts.Responses;
3
  using ClipForge.Core.Interfaces;
4
  using ClipForge.Core.Interfaces.Services;
5
  using Microsoft.AspNetCore.Hosting;
 
6
 
7
  namespace ClipForge.Api.Endpoints;
8
 
@@ -36,6 +37,32 @@ public static class VideoEndpoints
36
  return Results.Ok(videos.Select(MapToResponse));
37
  });
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  group.MapGet("/{id:guid}/download", async (Guid id, IVideoAssetRepository repository, IWebHostEnvironment env) =>
40
  {
41
  var video = await repository.GetByIdAsync(id);
 
3
  using ClipForge.Core.Interfaces;
4
  using ClipForge.Core.Interfaces.Services;
5
  using Microsoft.AspNetCore.Hosting;
6
+ using Microsoft.EntityFrameworkCore;
7
 
8
  namespace ClipForge.Api.Endpoints;
9
 
 
37
  return Results.Ok(videos.Select(MapToResponse));
38
  });
39
 
40
+ group.MapDelete("/{id:guid}", async (Guid id, IVideoAssetRepository repository, ClipForge.Infrastructure.Data.AppDbContext db) =>
41
+ {
42
+ var video = await repository.GetByIdAsync(id);
43
+ if (video is null) return Results.NotFound();
44
+
45
+ // Delete all related records and files
46
+ var sql = $@"
47
+ DELETE FROM ""PublishJobs"" WHERE ""VideoAssetId"" = '{id}';
48
+ DELETE FROM ""CaptionAssets"" WHERE ""VideoAssetId"" = '{id}';
49
+ DELETE FROM ""VoiceAssets"" WHERE ""VideoScriptId"" = '{video.VideoScriptId}';
50
+ DELETE FROM ""VideoAssets"" WHERE ""Id"" = '{id}';
51
+ DELETE FROM ""VideoScripts"" WHERE ""Id"" = '{video.VideoScriptId}';
52
+ ";
53
+ await db.Database.ExecuteSqlRawAsync(sql);
54
+
55
+ // Delete files from disk
56
+ try
57
+ {
58
+ if (File.Exists(video.FilePath)) File.Delete(video.FilePath);
59
+ if (File.Exists(video.ThumbnailPath)) File.Delete(video.ThumbnailPath);
60
+ }
61
+ catch { /* ignore file errors */ }
62
+
63
+ return Results.Ok(new { Message = "Video deleted" });
64
+ });
65
+
66
  group.MapGet("/{id:guid}/download", async (Guid id, IVideoAssetRepository repository, IWebHostEnvironment env) =>
67
  {
68
  var video = await repository.GetByIdAsync(id);
src/ClipForge.Api/wwwroot/index.html CHANGED
@@ -106,6 +106,17 @@
106
  white-space: nowrap;
107
  }
108
  .btn-download:hover { opacity: 0.8; }
 
 
 
 
 
 
 
 
 
 
 
109
  .empty { text-align: center; color: #555; padding: 20px; }
110
  .hidden { display: none; }
111
  .login-card { text-align: center; margin-top: 20vh; }
@@ -185,6 +196,15 @@
185
  loadVideos();
186
  }
187
 
 
 
 
 
 
 
 
 
 
188
  async function generate() {
189
  const niche = document.getElementById('niche').value.trim();
190
  if (!niche) { alert('Digite um tema!'); return; }
@@ -240,6 +260,7 @@
240
  <div class="meta">${Math.round(v.durationSeconds)}s • ${(v.fileSizeBytes / 1024 / 1024).toFixed(1)} MB • ${new Date(v.createdAt).toLocaleString('pt-BR')}</div>
241
  </div>
242
  <a class="btn-download" href="${API}/api/videos/${v.id}/download" download>⬇ Baixar</a>
 
243
  </div>
244
  `).join('');
245
  } catch (e) {
 
106
  white-space: nowrap;
107
  }
108
  .btn-download:hover { opacity: 0.8; }
109
+ .btn-delete {
110
+ padding: 10px 12px;
111
+ border-radius: 8px;
112
+ background: #dc2626;
113
+ color: #fff;
114
+ border: none;
115
+ font-size: 0.85rem;
116
+ cursor: pointer;
117
+ white-space: nowrap;
118
+ }
119
+ .btn-delete:hover { opacity: 0.8; }
120
  .empty { text-align: center; color: #555; padding: 20px; }
121
  .hidden { display: none; }
122
  .login-card { text-align: center; margin-top: 20vh; }
 
196
  loadVideos();
197
  }
198
 
199
+ async function deleteVideo(id) {
200
+ if (!confirm('Apagar este vídeo e todos os dados relacionados?')) return;
201
+ try {
202
+ const res = await fetch(`${API}/api/videos/${id}`, { method: 'DELETE' });
203
+ if (res.ok) { loadVideos(); }
204
+ else { alert('Erro ao apagar'); }
205
+ } catch (e) { alert('Erro: ' + e.message); }
206
+ }
207
+
208
  async function generate() {
209
  const niche = document.getElementById('niche').value.trim();
210
  if (!niche) { alert('Digite um tema!'); return; }
 
260
  <div class="meta">${Math.round(v.durationSeconds)}s • ${(v.fileSizeBytes / 1024 / 1024).toFixed(1)} MB • ${new Date(v.createdAt).toLocaleString('pt-BR')}</div>
261
  </div>
262
  <a class="btn-download" href="${API}/api/videos/${v.id}/download" download>⬇ Baixar</a>
263
+ <button class="btn-delete" onclick="deleteVideo('${v.id}')">🗑</button>
264
  </div>
265
  `).join('');
266
  } catch (e) {