From c5f65fda787e5535adc8269f988fcf5c43f485c2 Mon Sep 17 00:00:00 2001 From: MeowcaTheoRange Date: Wed, 21 Feb 2024 10:43:48 -0600 Subject: [PATCH] Oops, committed broken code check for album cover existing --- index.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 3ec3929..5614f26 100644 --- a/index.js +++ b/index.js @@ -99,7 +99,11 @@ async function getVideo() { async function checkNextcloud({ url, name, channelName }, nextcloudClient) { const fileName = pathGenerator({ url, name, channelName }); - return await nextcloudClient.exists(fileName); + return await nextcloudClient.exists(path.join(process.env.NEXTCLOUD_FOLDER, fileName)); +} + +async function checkNextcloudAlbum({ tags }, nextcloudClient) { + return await nextcloudClient.exists(path.join(process.env.NEXTCLOUD_FOLDER, tags, "cover.png")); } async function downloadFromCobalt({ url }) { @@ -167,13 +171,16 @@ async function uploadToNextcloud({ fileStream, url, name, channelName, tags, alb const fileBufferStream = new PassThrough().end(fileStream); - const albumBufferStream = new PassThrough().end(albumCover); - const fileName = pathGenerator({ url, name, channelName }); - await finished(fileBufferStream.pipe(nextcloudClient.createWriteStream(path.join(process.env.NEXTCLOUD_FOLDER, fileName)))); + await finished(fileBufferStream.pipe(nextcloudClient.createWriteStream(path.join(process.env.NEXTCLOUD_FOLDER, tags.album, fileName)))); + + if (albumCover) { + const albumBufferStream = new PassThrough().end(albumCover); + + await finished(albumBufferStream.pipe(nextcloudClient.createWriteStream(path.join(process.env.NEXTCLOUD_FOLDER, tags.album, "cover.png")))); + } - await finished(albumBufferStream.pipe(nextcloudClient.createWriteStream(path.join(process.env.NEXTCLOUD_FOLDER, "cover.png")))); return fileName; } @@ -204,7 +211,10 @@ async function main() { password: process.env.NOTIFICATION_SERVER_PASSWORD }) - const albumCover = await downloadAlbumCover(video); + let albumCover; + if (!(await checkNextcloudAlbum({ ...video }, nextcloudClient))) { + albumCover = await downloadAlbumCover(video); + } socket.emit('nodeMessage', { message: `Cobalt download starting - ${video.name} from ${video.channelName}`, @@ -238,7 +248,7 @@ async function main() { ); socket.emit('nodeMessage', { - message: `Nextcloud upload finished - ${tags.name} from ${tags.channelName}`, + message: `Nextcloud upload finished - ${video.name} from ${video.channelName}`, password: process.env.NOTIFICATION_SERVER_PASSWORD })