diff --git a/nuxt.config.ts b/nuxt.config.ts index 36a4bf6f..0716279a 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -32,6 +32,9 @@ export default defineNuxtConfig({ clientId: '', clientSecret: '', }, + typefully: { + apiKey: '', + }, github: { // my GH ID id: 'MDQ6VXNlcjI4NzA2Mzcy', diff --git a/server/api/question.ts b/server/api/question.ts index 9ba427ab..ae57795b 100644 --- a/server/api/question.ts +++ b/server/api/question.ts @@ -4,7 +4,7 @@ export default defineEventHandler(async event => { assertMethod(event, 'POST') const { question } = await readBody(event) if (!question) throw createError({ statusCode: 422 }) - - await sendEmail('Anonymous question', question) + event.waitUntil(sendEmail('Anonymous question', question)) + event.waitUntil(createTypefullyDraft(event, question)) return null }) diff --git a/server/utils/typefully.ts b/server/utils/typefully.ts new file mode 100644 index 00000000..c35f0ce6 --- /dev/null +++ b/server/utils/typefully.ts @@ -0,0 +1,26 @@ +import type { H3Event } from 'h3' + +export async function createTypefullyDraft (event: H3Event, text: string) { + const content = ` +${text} + +https://roe.dev/ama + +#ama + +https://ray.so/#code=${btoa(text)}&language=markdown&theme=breeze&width=520` + return await $fetch('/drafts', { + baseURL: 'https://api.typefully.com/v1', + method: 'POST', + headers: { + 'X-API-KEY': useRuntimeConfig(event).typefully.apiKey, + }, + body: { + content, + media: { + type: 'image', + url: 'https://example.com/image.jpg', + }, + }, + }) +}