Skip to content

Commit 13b01f4

Browse files
committed
feat: add getConfig to sanity-distribute webhook
- Fetch distribution_config singleton at start of runDistribution() - Pass resendFromEmail + notificationEmails to notifySubscribers()
1 parent 13f7337 commit 13b01f4

File tree

1 file changed

+7
-1
lines changed
  • app/api/webhooks/sanity-distribute

1 file changed

+7
-1
lines changed

app/api/webhooks/sanity-distribute/route.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { generateWithGemini } from "@/lib/gemini";
55
import { uploadVideo, uploadShort, generateShortsMetadata } from "@/lib/youtube-upload";
66
import { notifySubscribers } from "@/lib/resend-notify";
77
import { postVideoAnnouncement } from "@/lib/x-social";
8+
import { getConfig } from "@/lib/config";
89

910
const WEBHOOK_SECRET = process.env.SANITY_WEBHOOK_SECRET;
1011

@@ -140,6 +141,9 @@ async function appendDistributionLog(docId: string, entries: DistributionLogEntr
140141
async function runDistribution(docId: string, doc: AutomatedVideoDoc): Promise<void> {
141142
const log: DistributionLogEntry[] = [];
142143

144+
// Fetch distribution config from Sanity singleton
145+
const distConfig = await getConfig("distribution_config");
146+
143147
try {
144148
await updateStatus(docId, "uploading");
145149

@@ -197,7 +201,7 @@ async function runDistribution(docId: string, doc: AutomatedVideoDoc): Promise<v
197201
log.push(logEntry("youtube-short", "skipped", { error: "No shortUrl" }));
198202
}
199203

200-
// Step 4: Email notification (non-fatal)
204+
// Step 4: Email notification (non-fatal) — uses distribution config
201205
console.log("[sanity-distribute] Step 4/6 - Sending email");
202206
const ytUrl = youtubeVideoId ? `https://www.youtube.com/watch?v=${youtubeVideoId}` : doc.videoUrl || "";
203207
try {
@@ -206,6 +210,8 @@ async function runDistribution(docId: string, doc: AutomatedVideoDoc): Promise<v
206210
videoTitle: metadata.title,
207211
videoUrl: ytUrl,
208212
description: metadata.description.slice(0, 280),
213+
fromEmail: distConfig.resendFromEmail,
214+
notificationEmails: distConfig.notificationEmails,
209215
});
210216
log.push(logEntry("email", "success"));
211217
} catch (e) {

0 commit comments

Comments
 (0)