Forráskód Böngészése

Make scrape endpoint function async

Tati 7 éve
szülő
commit
172bc488fe
1 módosított fájl, 4 hozzáadás és 5 törlés
  1. 4 5
      ktchn/src/recipes/scrape/index.ts

+ 4 - 5
ktchn/src/recipes/scrape/index.ts

@@ -21,17 +21,16 @@ export const parseIngredients = (rawIngredient: string): Ingredient => {
   };
 };
 
-function scrape(url:string) {
+async function scrape(url:string) {
   const options = {
     uri: url,
     transform: (body: any) => Cheerio.load(body, {
       normalizeWhitespace: true
     }),
   };
-  return RequestPromise(options).then(($) => {
-    let source = selectSource(url);
-    return source ? source.scrapeRecipe($) : new Error('source not found');
-  });
+  const $ = await RequestPromise(options);
+  let source = selectSource(url);
+  return source ? source.scrapeRecipe($) : new Error('source not found');
 
 }