|
1 | 1 | import type { NextRequest } from "next/server";
|
2 | 2 | import { db } from "@cap/database";
|
3 |
| -import { s3Buckets, videos, users, emailNotifications } from "@cap/database/schema"; |
| 3 | +import { s3Buckets, videos, users } from "@cap/database/schema"; |
4 | 4 | import { getCurrentUser } from "@cap/database/auth/session";
|
5 | 5 | import { nanoId } from "@cap/database/helpers";
|
6 | 6 | import { cookies } from "next/headers";
|
@@ -206,49 +206,26 @@ export async function GET(req: NextRequest) {
|
206 | 206 | .where(eq(videos.ownerId, user.id));
|
207 | 207 |
|
208 | 208 | if (videoCount && videoCount[0] && videoCount[0].count === 1 && user.email) {
|
209 |
| - // Check if we've already sent this email |
210 |
| - const existingNotifications = await db |
211 |
| - .select({ id: emailNotifications.id }) |
212 |
| - .from(emailNotifications) |
213 |
| - .where( |
214 |
| - and( |
215 |
| - eq(emailNotifications.userId, user.id), |
216 |
| - eq(emailNotifications.type, "first_shareable_link") |
217 |
| - ) |
218 |
| - ) |
219 |
| - .limit(1); |
| 209 | + console.log("[SendFirstShareableLinkEmail] Sending first shareable link email with 5-minute delay"); |
220 | 210 |
|
221 |
| - // If we've already sent this email, don't send it again |
222 |
| - if (!existingNotifications || existingNotifications.length === 0) { |
223 |
| - console.log("[SendFirstShareableLinkEmail] Sending first shareable link email with 5-minute delay"); |
| 211 | + const videoUrl = clientEnv.NEXT_PUBLIC_IS_CAP |
| 212 | + ? `https://cap.link/${id}` |
| 213 | + : `${clientEnv.NEXT_PUBLIC_WEB_URL}/s/${id}`; |
224 | 214 |
|
225 |
| - const videoUrl = clientEnv.NEXT_PUBLIC_IS_CAP |
226 |
| - ? `https://cap.link/${id}` |
227 |
| - : `${clientEnv.NEXT_PUBLIC_WEB_URL}/s/${id}`; |
228 |
| - |
229 |
| - // Record that we're sending this email |
230 |
| - const shortId = nanoId().substring(0, 15); |
231 |
| - await db.insert(emailNotifications).values({ |
232 |
| - id: shortId, |
233 |
| - userId: user.id, |
234 |
| - type: "first_shareable_link", |
235 |
| - }); |
236 |
| - |
237 |
| - // Send email with 5-minute delay using Resend's scheduling feature |
238 |
| - await sendEmail({ |
| 215 | + // Send email with 5-minute delay using Resend's scheduling feature |
| 216 | + await sendEmail({ |
| 217 | + email: user.email, |
| 218 | + subject: "You created your first Cap! 🥳", |
| 219 | + react: FirstShareableLink({ |
239 | 220 | email: user.email,
|
240 |
| - subject: "You created your first Cap! 🥳", |
241 |
| - react: FirstShareableLink({ |
242 |
| - email: user.email, |
243 |
| - url: videoUrl, |
244 |
| - videoName: videoData.name, |
245 |
| - }), |
246 |
| - marketing: true, |
247 |
| - scheduledAt: "in 5 min" |
248 |
| - }); |
| 221 | + url: videoUrl, |
| 222 | + videoName: videoData.name, |
| 223 | + }), |
| 224 | + marketing: true, |
| 225 | + scheduledAt: "in 5 min" |
| 226 | + }); |
249 | 227 |
|
250 |
| - console.log("[SendFirstShareableLinkEmail] First shareable link email scheduled to be sent in 5 minutes"); |
251 |
| - } |
| 228 | + console.log("[SendFirstShareableLinkEmail] First shareable link email scheduled to be sent in 5 minutes"); |
252 | 229 | }
|
253 | 230 | } catch (error) {
|
254 | 231 | console.error("Error checking for first video or sending email:", error);
|
|
0 commit comments