Error handling via notification
This commit is contained in:
parent
7f08db6aa8
commit
b3bfe116c2
1 changed files with 23 additions and 15 deletions
38
index.js
38
index.js
|
@ -186,15 +186,10 @@ async function uploadToNextcloud({ fileStream, url, name, channelName, tags, alb
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
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();
|
const video = await getVideo();
|
||||||
|
|
||||||
if (video == null) return dismantle(socket);
|
if (video == null) return dismantle();
|
||||||
|
|
||||||
const nextcloudClient = createClient(
|
const nextcloudClient = createClient(
|
||||||
`https://${process.env.NEXTCLOUD_INSTANCE}/remote.php/dav/files/${process.env.NEXTCLOUD_USERNAME}/`,
|
`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', {
|
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
|
password: process.env.NOTIFICATION_SERVER_PASSWORD
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -217,14 +212,14 @@ async function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.emit('nodeMessage', {
|
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
|
password: process.env.NOTIFICATION_SERVER_PASSWORD
|
||||||
})
|
})
|
||||||
|
|
||||||
const cobalt = await downloadFromCobalt(video);
|
const cobalt = await downloadFromCobalt(video);
|
||||||
|
|
||||||
socket.emit('nodeMessage', {
|
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
|
password: process.env.NOTIFICATION_SERVER_PASSWORD
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -234,7 +229,7 @@ async function main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.emit('nodeMessage', {
|
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
|
password: process.env.NOTIFICATION_SERVER_PASSWORD
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -248,16 +243,29 @@ async function main() {
|
||||||
);
|
);
|
||||||
|
|
||||||
socket.emit('nodeMessage', {
|
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
|
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();
|
socket.disconnect();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
Loading…
Reference in a new issue