Spaces:
Runtime error
Runtime error
Download tempmail.js from FarelDeveloper/fmailtemp: direct link, hf CLI and curl.
- Browser
- Download file 1.93 kB
-
https://huggingface.co/spaces/FarelDeveloper/fmailtemp/resolve/main/tempmail.js
- Command line
-
hf download hf://spaces/FarelDeveloper/fmailtemp/tempmail.js
-
curl -L -o tempmail.js https://huggingface.co/spaces/FarelDeveloper/fmailtemp/resolve/main/tempmail.js
1.93 kB
| // tempmail.js | |
| const fetch = require('node-fetch'); | |
| class TempMailCore { | |
| constructor(baseUrl = 'https://api.internal.temp-mail.io/api/v3') { | |
| this.baseUrl = baseUrl; | |
| } | |
| // ambil domain | |
| async listDomains() { | |
| try { | |
| const response = await fetch(`${this.baseUrl}/domains`); | |
| if (!response.ok) throw new Error(`HTTP ${response.status}`); | |
| const data = await response.json(); | |
| return { success: true, domains: data.domains }; | |
| } catch (e) { | |
| return { success: false, error: e.message }; | |
| } | |
| } | |
| // buat email | |
| async generateEmail(username, domain) { | |
| try { | |
| const response = await fetch(`${this.baseUrl}/email/new`, { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify({ name: username, domain }) | |
| }); | |
| if (!response.ok) throw new Error(`HTTP ${response.status}`); | |
| const data = await response.json(); | |
| return { | |
| success: true, | |
| email: data.email, | |
| token: data.token | |
| }; | |
| } catch (e) { | |
| return { success: false, error: e.message }; | |
| } | |
| } | |
| // cek inbox | |
| async checkEmail(emailAddress) { | |
| try { | |
| const response = await fetch( | |
| `${this.baseUrl}/email/${emailAddress}/messages` | |
| ); | |
| if (!response.ok) throw new Error(`HTTP ${response.status}`); | |
| const messages = await response.json(); | |
| return { | |
| success: true, | |
| email: emailAddress, | |
| messages | |
| }; | |
| } catch (e) { | |
| return { | |
| success: false, | |
| email: emailAddress, | |
| error: e.message | |
| }; | |
| } | |
| } | |
| } | |
| module.exports = TempMailCore; |