drop usage of async

This commit is contained in:
Niko Storni 2020-03-12 21:54:51 +01:00
parent 167b591d21
commit 2b2607df61

View file

@ -1,19 +1,28 @@
const { Lbryio } = require('lbryinc'); const { Lbryio } = require('lbryinc');
const { URL, LBRY_TV_STREAMING_API } = require('../../config'); const { URL, LBRY_TV_STREAMING_API } = require('../../config');
async function generateStreamUrl(claimName, claimId, apiUrl) { function generateStreamUrl(claimName, claimId, apiUrl) {
let prefix = LBRY_TV_STREAMING_API || apiUrl; let prefix = LBRY_TV_STREAMING_API || apiUrl;
try { if (prefix.includes('localhost')) {
let localeResponse = await Lbryio.call('locale', 'get', {}, 'post');
if (prefix.split('//').length > 1) {
prefix = prefix.replace('//', '//' + localeResponse.continent + '.');
}
} catch (err) {
console.error(err.stack || err);
}
console.log(`${prefix}/content/claims/${claimName}/${claimId}/stream`);
return `${prefix}/content/claims/${claimName}/${claimId}/stream`; return `${prefix}/content/claims/${claimName}/${claimId}/stream`;
} }
new Promise((resolve, reject) => {
Lbryio.call('locale', 'get', {}, 'post').then(result => {
if (prefix.split('//').length > 1) {
prefix = prefix.replace('//', '//' + result.continent + '.');
}
resolve(prefix);
});
})
.then(p => {
console.log(`${p}/content/claims/${claimName}/${claimId}/stream`);
return `${p}/content/claims/${claimName}/${claimId}/stream`;
})
.catch(err => {
console.error(err.stack || err);
return `${prefix}/content/claims/${claimName}/${claimId}/stream`;
});
}
function generateEmbedUrl(claimName, claimId) { function generateEmbedUrl(claimName, claimId) {
return `${URL}/$/embed/${claimName}/${claimId}`; return `${URL}/$/embed/${claimName}/${claimId}`;