-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_api_credentials.ts
More file actions
41 lines (36 loc) · 956 Bytes
/
find_api_credentials.ts
File metadata and controls
41 lines (36 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { isApiHashValid } from "./is_api_hash_valid.ts";
export function findApiCredentials() {
let apiIdKey = TELEGRAM_API_ID;
let apiId = Deno.env.get(apiIdKey);
if (apiId === undefined) {
apiIdKey = API_ID;
apiId = Deno.env.get(API_ID);
}
let apiHashKey = TELEGRAM_API_HASH;
let apiHash = Deno.env.get(apiHashKey);
if (apiHash === undefined) {
apiHashKey = API_HASH;
apiHash = Deno.env.get(API_HASH);
}
const apiIdNumber = apiId === undefined ? 0 : parseInt(apiId);
if (
!isNaN(apiIdNumber) && apiIdNumber > 0 && apiHash && isApiHashValid(apiHash)
) {
return {
apiId: {
envVar: apiIdKey,
value: apiIdNumber,
},
apiHash: {
envVar: apiHashKey,
value: apiHash,
},
};
} else {
return null;
}
}
const API_ID = "API_ID";
const TELEGRAM_API_ID = "TELEGRAM_API_ID";
const API_HASH = "API_HASH";
const TELEGRAM_API_HASH = "TELEGRAM_API_HASH";