Error handling via notification

This commit is contained in:
MeowcaTheoRange 2024-02-21 16:19:09 -06:00
parent 7f08db6aa8
commit b3bfe116c2

View file

@ -186,15 +186,10 @@ async function uploadToNextcloud({ fileStream, url, name, channelName, tags, alb
}
async function main() {
const socket = io.connect(`http://localhost:${process.env.NOTIFICATION_SERVER_PORT}`, {reconnect: true});
socket.on('connect', function (s) {
console.log('Successfully connected to notification server');
});
const video = await getVideo();
if (video == null) return dismantle(socket);
if (video == null) return dismantle();
const nextcloudClient = createClient(
`https://${process.env.NEXTCLOUD_INSTANCE}/remote.php/dav/files/${process.env.NEXTCLOUD_USERNAME}/`,
@ -204,10 +199,10 @@ async function main() {
}
);
if (await checkNextcloud(video, nextcloudClient)) return dismantle(socket);
if (await checkNextcloud(video, nextcloudClient)) return dismantle();
socket.emit('nodeMessage', {
message: `New song found - ${video.name} from ${video.channelName}`,
message: `New song found - ${video.tags.title} by ${video.tags.artist}`,
password: process.env.NOTIFICATION_SERVER_PASSWORD
})
@ -217,14 +212,14 @@ async function main() {
}
socket.emit('nodeMessage', {
message: `Cobalt download starting - ${video.name} from ${video.channelName}`,
message: `Cobalt download starting - ${video.tags.title} by ${video.tags.artist}`,
password: process.env.NOTIFICATION_SERVER_PASSWORD
})
const cobalt = await downloadFromCobalt(video);
socket.emit('nodeMessage', {
message: `Cobalt download finished - ${video.name} from ${video.channelName}`,
message: `Cobalt download finished - ${video.tags.title} by ${video.tags.artist}`,
password: process.env.NOTIFICATION_SERVER_PASSWORD
});
@ -234,7 +229,7 @@ async function main() {
});
socket.emit('nodeMessage', {
message: `Nextcloud upload running - ${video.name} from ${video.channelName}`,
message: `Nextcloud upload running - ${video.tags.title} by ${video.tags.artist}`,
password: process.env.NOTIFICATION_SERVER_PASSWORD
});
@ -248,16 +243,29 @@ async function main() {
);
socket.emit('nodeMessage', {
message: `Nextcloud upload finished - ${video.name} from ${video.channelName}`,
message: `Nextcloud upload finished - ${video.tags.title} by ${video.tags.artist}`,
password: process.env.NOTIFICATION_SERVER_PASSWORD
})
return dismantle(socket);
return dismantle();
}
main();
const socket = io.connect(`http://localhost:${process.env.NOTIFICATION_SERVER_PORT}`, {reconnect: true});
function dismantle(socket) {
socket.on('connect', function (s) {
console.log('Successfully connected to notification server');
try {
main();
} catch (err) {
socket.emit('nodeMessage', {
message: `LastFMDownloader error - ${err}`,
password: process.env.NOTIFICATION_SERVER_PASSWORD
})
throw err;
}
});
function dismantle() {
socket.disconnect();
return null;
}