Skip to content

armgit / my-yt

Public Imported from GitHub
0

A clean and minimal youtube frontend, without all the ads and whistles

JavaScript

feat: delete video, updates sse

Christian Fei077af0c9b805
diff --git a/client/main.js b/client/main.js
index 1f115d9..cb2eb7b 100644
--- a/client/main.js
+++ b/client/main.js
@@ -52,11 +52,11 @@ eventSource.onmessage = (message) => {
})
return
}
- if (data.type === 'downloaded' && data.videoId) {
+ if (data.type === 'downloaded' && data.videoId && data.downloaded !== undefined) {
;[...document.querySelectorAll(`[data-video-id="${data.videoId}"]`)].forEach($video => {
if (!$video.dataset['data']) return
const videoData = JSON.parse($video.dataset['data'])
- videoData.downloaded = true
+ videoData.downloaded = data.downloaded
$video.dataset['data'] = JSON.stringify(videoData)
})
return
diff --git a/lib/server.js b/lib/server.js
index 055500c..d3e3f34 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -133,7 +133,7 @@ export function createServer ({repo, connections = []}) {
downloadVideo(id, repo, (line) =>
broadcastSSE(JSON.stringify({type: 'download-log-line', line}), connections))
.then(() => {
- broadcastSSE(JSON.stringify({type: 'downloaded', videoId: id}), connections)
+ broadcastSSE(JSON.stringify({type: 'downloaded', videoId: id, downloaded: true}), connections)
if (external) broadcastSSE(JSON.stringify({type: 'new-videos', videos: [repo.getVideo(id)]}), connections)
})
.catch((error) =>
@@ -173,14 +173,10 @@ export function createServer ({repo, connections = []}) {
async function deleteVideoHandler(req, res, repo, connections = []) {
const body = await getBody(req)
let { id } = JSON.parse(body)
- try {
- repo.deleteVideo(id)
- res.writeHead(200)
- res.end()
- } catch (err) {
- res.writeHead(500)
- res.end()
- }
+ repo.deleteVideo(id)
+ broadcastSSE(JSON.stringify({type: 'downloaded', videoId: id, downloaded: false}), connections)
+ res.writeHead(200)
+ res.end()
}
function watchVideoHandler(req, res) {