瀏覽代碼

Make scrape endpoint function async

Tati 7 年之前
父節點
當前提交
172bc488fe
共有 1 個文件被更改,包括 4 次插入5 次删除
  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');
 
 }