Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit eadb1de

Browse files
committed
2.0-beta.1
1 parent 27f851a commit eadb1de

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Cache {
4949
}, 1800);
5050
}
5151

52-
wrap(func: (params: any[]) => Promise<any>): (...params: any[]) => Promise<any> {
52+
wrap(func: (...params: any[]) => Promise<any>): (...params: any[]) => Promise<any> {
5353
/**
5454
* Async Function Cache.
5555
*/

utils.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const axios = require("axios");
22
const conf = require("./config");
3+
const cache = require("./cache").cache;
4+
35
axios.defaults.baseURL = "https://api.github.com";
46

57
export function sort(arr: number[]): number[] {
@@ -66,9 +68,25 @@ export function getLicense(license: object | undefined | null): string {
6668
return license ? license['spdx_id'] : "Empty";
6769
}
6870

69-
export async function isAuthenticated(user): Promise<boolean> {
71+
async function _isAuthenticated(user): Promise<boolean> {
7072
user = user.trim();
71-
return (!! user.length) &&
72-
(conf.requires.includes("*") || conf.requires.includes(user)) &&
73-
((await requestUser(user))['message'] !== "Not Found");
74-
}
73+
try {
74+
return (!!user.length) &&
75+
(conf.requires.includes("*") || conf.requires.includes(user)) &&
76+
((await requestUser(user))['message'] !== "Not Found");
77+
} catch {
78+
return false;
79+
}
80+
}
81+
export const isAuthenticated = cache.wrap(_isAuthenticated);
82+
83+
async function _isExistRepo(user, repo): Promise<boolean> {
84+
user = user.trim(); repo = repo.trim();
85+
try {
86+
return await isAuthenticated(user) &&
87+
((await requestRepo(user, repo))['message'] !== "Not Found");
88+
} catch {
89+
return false;
90+
}
91+
}
92+
export const isExistRepo = cache.wrap(_isExistRepo);

0 commit comments

Comments
 (0)