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: repository cleanup

Christian Fei418c8e7b4158
diff --git a/lib/repository.js b/lib/repository.js
index eabcf48..68c0d98 100644
--- a/lib/repository.js
+++ b/lib/repository.js
@@ -76,8 +76,8 @@ export default class Repository {
if (index !== -1) {
Object.assign(this.videos[index], update)
this.saveVideos()
+ return this.videos[index]
}
- return this.videos[index]
}
deleteVideo(id) {
const files = fs.readdirSync(`${this.basePath}/videos`)
@@ -105,30 +105,16 @@ export default class Repository {
return ignored
}
setVideoTranscript(id, transcript = '') {
- this.videos = this.videos.map(v => {
- if (v.id === id) return Object.assign(v, {transcript})
- return v
- })
- this.saveVideos()
+ return this.updateVideo(id, {transcript})
}
setVideoSummary(id, summary = '') {
- this.videos = this.videos.map(v => {
- if (v.id === id) return Object.assign(v, {summary})
- return v
- })
- this.saveVideos()
+ return this.updateVideo(id, {summary})
}
setVideoDownloaded(id, downloaded = true) {
- this.videos = this.videos.map(v => {
- if (v.id === id) return Object.assign(v, {downloaded})
- return v
- })
- this.saveVideos()
+ return this.updateVideo(id, {downloaded})
}
patchVideo(video) {
- const savedVideo = this.getVideo(video.id)
- if (!savedVideo) return Object.assign(video, {addedAt: Date.now()})
- Object.assign(savedVideo, video)
- return savedVideo
+ if (this.getVideo(video.id)) return video
+ return Object.assign(video, {addedAt: Date.now()})
}
}
\ No newline at end of file