Skip to content

Commit

Permalink
Merge pull request xiangsx#48 from xiaoyao20084321/free-email
Browse files Browse the repository at this point in the history
add free email
  • Loading branch information
xiangsx authored Jun 8, 2023
2 parents 53f6eab + d34f049 commit d35333d
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions utils/emailFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export enum TempEmailType {
TempEmail = 'temp-email',
// not need credit card , hard limit 100/day https://rapidapi.com/calvinloveland335703-0p6BxLYIH8f/api/temp-mail44
TempEmail44 = 'temp-email44',
// not need credit card and not need credit rapid_api_key
TempMailLOL = 'tempmail-lol',
}

export function CreateEmail(tempMailType: TempEmailType, options?: BaseOptions): BaseEmail {
Expand All @@ -15,6 +17,8 @@ export function CreateEmail(tempMailType: TempEmailType, options?: BaseOptions):
return new TempMail44(options);
case TempEmailType.TempEmail:
return new TempMail(options);
case TempEmailType.TempMailLOL:
return new TempMailLOL(options);
default:
throw new Error('not support TempEmailType')
}
Expand Down Expand Up @@ -170,3 +174,44 @@ class TempMail44 extends BaseEmail {
});
}
}

class TempMailLOL extends BaseEmail {
private readonly client: AxiosInstance;
private address: string = '';
private token: string = '';

constructor(options?: TempMailOptions) {
super(options)
this.client = CreateAxiosProxy({
baseURL: 'https://api.tempmail.lol'
} as CreateAxiosDefaults);
}

public async getMailAddress(): Promise<string> {
const response = await this.client.get('/generate');
this.address = response.data.address;
this.token = response.data.token;
return this.address;
}

public async waitMails(): Promise<TempMailMessage[]> {
return new Promise(resolve => {
let time = 0;
const itl = setInterval(async () => {
const response = await this.client.get(`/auth/${this.token}`);

if (response.data && response.data.email.length > 0) {
resolve(response.data.email.map((item: any) => ({...item, content: item.html})));
clearInterval(itl);
return;
}
if (time > 5) {
resolve([]);
clearInterval(itl);
return;
}
time++;
}, 5000);
});
}
}

0 comments on commit d35333d

Please sign in to comment.