Created
November 27, 2024 15:14
-
-
Save akku1139/5355e46b54982ba868dfa1175388eb72 to your computer and use it in GitHub Desktop.
LKML reader for NullStudio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://gist.github.com/akku1139/5355e46b54982ba868dfa1175388eb72 | |
| /** 最小実装 | |
| * https://developers.cloudflare.com/email-routing/email-workers/runtime-api/ | |
| * @typedef EmailMessage | |
| * @property {string} from | |
| * @property {string} to | |
| * @property {Headers} headers | |
| * @property {ReadableStream} raw | |
| * @property {number} rawSize | |
| */ | |
| export default { | |
| /** | |
| * @param {EmailMessage} m | |
| * @param {ExecutionContext} ctx | |
| */ | |
| async email(m, env, ctx) { | |
| //const raw = new TextDecoder().decode((await m.raw.getReader().read()).value); | |
| // m.raw.getReader().read().then((v) => console.log( | |
| // new TextDecoder().decode((v).value) | |
| // )); | |
| //const body = /\r\n\r\n(.*)$/s.exec(raw)[1]; | |
| const res = await fetch(env.WEBHOOK_URL, { | |
| method: "post", | |
| headers: { | |
| "Content-type": "application/json", | |
| }, | |
| body: JSON.stringify({ | |
| //username: "Linux kernel mailing list", | |
| //avatar_url: "https://isc.tamu.edu/~lewing/linux/sit3-shine.7.gif", | |
| embeds: [{ | |
| color: 0x5fbe86, | |
| timestamp: new Date(m.headers.get("Date")), | |
| url: `https://lore.kernel.org/lkml/${m.headers.get("Message-Id").slice(1, -1)}`, | |
| author: { | |
| name: m.headers.get("From").slice(0, 256), | |
| icon_url: `` | |
| }, | |
| title: m.headers.get("Subject").slice(0, 256), | |
| //description: .slice(0, 4096), | |
| }] | |
| }) | |
| }) | |
| console.log(res.status, res.text()) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment