This repository has been archived by the owner on Apr 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
63 lines (55 loc) · 1.78 KB
/
main.ts
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { TypeErr } from "./g-utils/errors"
export { OwnedUser as Me} from "./g-classes/Owned/OwnedUser"
import { Project } from "./g-classes/Public/Project"
import axios from "axios"
import { User } from "./g-classes/Public/User"
interface AnonResponse {
persistentToken: string;
}
interface EmailResponse {
status: number,
message: string
}
export function emailTempCode(email: string): Promise<EmailResponse> {
return new Promise<EmailResponse>(async (res, rej) => {
if(typeof email != "string") throw TypeErr("email", "string", typeof email);
axios.post<AnonResponse>("https://api.glitch.com/v1/users/anon").then(anon => {
axios.post("https://api.glitch.com/email/sendLoginEmail", {
emailAddress: email
}, {
headers: {
Authorization: anon.data.persistentToken
}
})
.then(d => res({
status: d.status,
message: d.statusText
}))
.catch(d => rej({
status: d.response.status,
message: d.response.statusText
}))
}).catch(d => rej({
status: d.response.status,
message: d.response.statusText
}));
})
}
export function getProject(type: "id" | "domain", value: string) {
return new Promise<Project>((res, rej) => {
const proj = new Project();
proj.on("ready", () => {
res(proj);
});
proj.find(type, value).catch(rej);
})
}
export function getUser(type: "id" | "login", value: string) {
return new Promise<User>((res, rej) => {
const usr = new User();
usr.on("ready", () => {
res(usr);
})
usr.find(type, value).catch(rej);
})
}