Skip to content

armgit / my-yt

Public Imported from GitHub
0

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

JavaScript

refactor: move patchVideo to repo

Christian Fei14d456da1ab2
diff --git a/lib/repository.js b/lib/repository.js
index 979f1a2..a7be119 100644
--- a/lib/repository.js
+++ b/lib/repository.js
@@ -86,4 +86,10 @@ export default class Repository {
})
this.saveVideos()
}
+ patchVideo(video) {
+ const savedVideo = this.getVideo(video.id)
+ if (!savedVideo) return Object.assign(video, {addedAt: Date.now()})
+ Object.assign(savedVideo, video)
+ return savedVideo
+ }
}
\ No newline at end of file
diff --git a/lib/server.js b/lib/server.js
index 280ce9b..af8792c 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -254,16 +254,9 @@ async function updateAndPersistVideosForChannel(name, repo, callback = () => {})
let videos = await getVideosFor(name)
console.log('received videos for ', name, videos?.length)
if (videos) {
- videos = videos.map(v => patchVideo(v, repo))
+ videos = videos.map(v => repo.patchVideo(v))
repo.upsertVideos(videos)
callback({name, videos})
}
return videos
}
-
-function patchVideo(video, repo) {
- const savedVideo = repo.getVideo(video.id)
- if (!savedVideo) return Object.assign(video, {addedAt: Date.now()})
- Object.assign(savedVideo, video)
- return savedVideo
-}
\ No newline at end of file