Switch to async/await
This commit is contained in:
parent
87459b2acc
commit
18021e0ef8
10 changed files with 53 additions and 8837 deletions
|
@ -45,10 +45,10 @@ function looseMatch(needle, haystack, type, various) {
|
|||
}
|
||||
|
||||
|
||||
export function* lookupId(id, type) {
|
||||
export async function lookupId(id, type) {
|
||||
const path = `/${type}/${id}?size=xl`;
|
||||
|
||||
const { body } = yield request.get(apiRoot + path);
|
||||
const { body } = await request.get(apiRoot + path);
|
||||
if (!body || body.error) {
|
||||
const error = new Error('Not Found');
|
||||
error.status = 404;
|
||||
|
@ -94,7 +94,7 @@ export function* lookupId(id, type) {
|
|||
return Promise.reject(new Error());
|
||||
}
|
||||
|
||||
export function* search(data, original = {}) {
|
||||
export async function search(data, original = {}) {
|
||||
function cleanParam(str) {
|
||||
return str.replace(/[:?&]+/, '');
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ export function* search(data, original = {}) {
|
|||
|
||||
const path = `/search/${type}?q=${encodeURIComponent(query)}`;
|
||||
|
||||
const response = yield request.get(apiRoot + path);
|
||||
const response = await request.get(apiRoot + path);
|
||||
|
||||
const name = original.name || data.name;
|
||||
|
||||
|
@ -129,7 +129,7 @@ export function* search(data, original = {}) {
|
|||
match = looseMatch(name, response.body.data, data.type, various);
|
||||
}
|
||||
|
||||
return yield module.exports.lookupId(response.body.data[0].id, type);
|
||||
return await module.exports.lookupId(response.body.data[0].id, type);
|
||||
}
|
||||
const matches = album.match(/^[^([]+/);
|
||||
if (matches && matches[0] && matches[0] !== album) {
|
||||
|
@ -139,7 +139,7 @@ export function* search(data, original = {}) {
|
|||
} else if (type === 'track') {
|
||||
cleanedData.albumName = matches[0].trim();
|
||||
}
|
||||
return yield module.exports.search(cleanedData, data);
|
||||
return await module.exports.search(cleanedData, data);
|
||||
}
|
||||
return Promise.resolve({ service: 'deezer' });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue