Switch to async/await

This commit is contained in:
Jonathan Cremin 2018-04-14 00:18:48 +01:00
parent 87459b2acc
commit 18021e0ef8
10 changed files with 53 additions and 8837 deletions

View file

@ -13,9 +13,9 @@ const client = amazon.createClient({
awsTag: process.env.AWS_TAG,
});
export function* lookupId(id, type) {
export async function lookupId(id, type) {
try {
const results = yield client.itemLookup({
const results = await client.itemLookup({
itemId: id,
responseGroup: 'ItemAttributes,Images,ItemIds',
});
@ -63,15 +63,15 @@ export function* lookupId(id, type) {
};
}
} catch (err) {
debug(inspect(err, { depth: 4 }));
debug(inspect(err, { depth: null }));
}
return { service: 'amazon' };
}
export function* search(data) {
export async function search(data) {
try {
const type = data.type;
const results = yield client.itemSearch({
const results = await client.itemSearch({
author: data.artist.name.replace(':', ' '),
title: data.name.replace(':', ' '),
searchIndex: 'MP3Downloads',
@ -130,7 +130,7 @@ export function* search(data) {
return { service: 'amazon' };
}
export function* parseUrl(url) {
export function parseUrl(url) {
const matches = parse(url).path.match(/\/(albums|tracks)[/]+([^?]+)/);
if (matches && matches[2]) {