Skip to content

Commit

Permalink
chore: fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied committed Jul 18, 2024
1 parent 7ff10b3 commit 279e129
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ const retryDelay = 1000; // 1 second delay before retrying
const throttledPostForCreate = pThrottle({ limit: 10, interval: 30_500 })(got.post) as any as Got['post'];

// There's a limit of 30 requests each 30 seconds by the same user, so we need to throttle the API calls in that case too.
const throttledPutForUpdate = pThrottle({ limit: 30, interval: 30_500 })(
async (url: string, options: any) => got.put(url, options)
const throttledPutForUpdate = pThrottle({ limit: 30, interval: 30_500 })(async (url: string, options: any) =>
got.put(url, options)
) as any as Got['put'];

async function delay(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}

async function retryRequest(fn: () => Promise<RemoteArticleData>, retries: number): Promise<RemoteArticleData> {
Expand All @@ -31,6 +33,7 @@ async function retryRequest(fn: () => Promise<RemoteArticleData>, retries: numbe
if (retries === 0 || !(error instanceof RequestError && error.response?.statusCode === 429)) {
throw error;
}

debug('Rate limited, retrying in %s ms', retryDelay);
await delay(retryDelay);
return retryRequest(fn, retries - 1);
Expand Down
2 changes: 1 addition & 1 deletion src/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const defaultArticlesFolder = 'posts';
export async function getArticlesFromFiles(filesGlob: string[]): Promise<Article[]> {
const files: string[] = await globby(filesGlob);
const articles = await Promise.all(files.map(getArticleFromFile));
return articles.filter((article) => article !== null) as Article[];
return articles.filter((article) => article !== null);
}

async function getArticleFromFile(file: string): Promise<Article | null> {
Expand Down

0 comments on commit 279e129

Please sign in to comment.