AI Newsletter Digest improvements: fixed QP soft line break decoding, URL extraction, and content cleaning

This commit is contained in:
Krilly
2026-03-04 13:29:22 +00:00
parent 29a98137a7
commit 57dd294675
13706 changed files with 2114953 additions and 237629 deletions

View File

@@ -0,0 +1,24 @@
'use client';
const STORAGE_KEY = 'eggbrt-anonymous-id';
export function getAnonymousUserId(): string {
if (typeof window === 'undefined') return '';
let id = localStorage.getItem(STORAGE_KEY);
if (!id) {
id = crypto.randomUUID();
localStorage.setItem(STORAGE_KEY, id);
}
return id;
}
export function getDisplayName(): string {
return localStorage.getItem('eggbrt-display-name') || '';
}
export function setDisplayName(name: string): void {
localStorage.setItem('eggbrt-display-name', name);
}

View File

@@ -0,0 +1,45 @@
/**
* Email utility using AWS SES SMTP
*/
import nodemailer from 'nodemailer';
// Create reusable transporter
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: parseInt(process.env.SMTP_PORT || '587'),
secure: false, // Use STARTTLS
auth: {
user: process.env.SMTP_USERNAME,
pass: process.env.SMTP_PASSWORD
}
});
interface EmailOptions {
to: string;
subject: string;
html: string;
from?: string;
}
/**
* Send an email via AWS SES
*/
export async function sendEmail(options: EmailOptions) {
const from = options.from || process.env.FROM_EMAIL || 'noreply@viralguru.app';
try {
const info = await transporter.sendMail({
from,
to: options.to,
subject: options.subject,
html: options.html
});
console.log('Email sent:', info.messageId);
return { success: true, messageId: info.messageId };
} catch (error) {
console.error('Email send failed:', error);
throw error;
}
}

View File

@@ -0,0 +1,27 @@
import { PrismaClient } from '@prisma/client';
// PrismaClient singleton to avoid multiple instances in serverless
// This is critical for Vercel edge functions to avoid cold start timeouts
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined;
};
export const prisma =
globalForPrisma.prisma ??
new PrismaClient({
log: process.env.NODE_ENV === 'development' ? ['error', 'warn'] : ['error'],
// Add connection pool settings optimized for serverless
datasources: {
db: {
url: process.env.DATABASE_URL,
},
},
});
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;
// Graceful shutdown
export async function disconnect() {
await prisma.$disconnect();
}

View File

@@ -0,0 +1,128 @@
/**
* Vercel API integration for subdomain management
*/
const VERCEL_API_URL = 'https://api.vercel.com';
const BASE_DOMAIN = 'eggbrt.com';
interface VercelDomainResponse {
name: string;
apexName: string;
projectId: string;
verified: boolean;
createdAt: number;
gitBranch: string | null;
}
/**
* Add a subdomain to the Vercel project
*/
export async function addSubdomain(slug: string): Promise<{ success: boolean; domain?: string; error?: string }> {
const vercelToken = process.env.VERCEL_TOKEN;
const projectId = process.env.VERCEL_PROJECT_ID;
if (!vercelToken) {
console.error('VERCEL_TOKEN environment variable is not set');
return { success: false, error: 'Vercel integration not configured' };
}
if (!projectId) {
console.error('VERCEL_PROJECT_ID environment variable is not set');
return { success: false, error: 'Vercel project not configured' };
}
const subdomain = `${slug}.${BASE_DOMAIN}`;
try {
const response = await fetch(
`${VERCEL_API_URL}/v10/projects/${projectId}/domains`,
{
method: 'POST',
headers: {
Authorization: `Bearer ${vercelToken}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: subdomain,
}),
}
);
if (!response.ok) {
const error = await response.json();
console.error('Vercel API error:', error);
// Domain might already exist
if (response.status === 409) {
return { success: true, domain: subdomain };
}
return {
success: false,
error: error.error?.message || 'Failed to create subdomain'
};
}
const data: VercelDomainResponse = await response.json();
console.log('Subdomain created:', data.name);
return { success: true, domain: subdomain };
} catch (error) {
console.error('Failed to create subdomain:', error);
return {
success: false,
error: error instanceof Error ? error.message : 'Unknown error'
};
}
}
/**
* Remove a subdomain from the Vercel project
*/
export async function removeSubdomain(slug: string): Promise<{ success: boolean; error?: string }> {
const vercelToken = process.env.VERCEL_TOKEN;
const projectId = process.env.VERCEL_PROJECT_ID;
if (!vercelToken || !projectId) {
return { success: false, error: 'Vercel integration not configured' };
}
const subdomain = `${slug}.${BASE_DOMAIN}`;
try {
const response = await fetch(
`${VERCEL_API_URL}/v9/projects/${projectId}/domains/${subdomain}`,
{
method: 'DELETE',
headers: {
Authorization: `Bearer ${vercelToken}`,
},
}
);
if (!response.ok) {
const error = await response.json();
console.error('Vercel API error:', error);
return {
success: false,
error: error.error?.message || 'Failed to remove subdomain'
};
}
console.log('Subdomain removed:', subdomain);
return { success: true };
} catch (error) {
console.error('Failed to remove subdomain:', error);
return {
success: false,
error: error instanceof Error ? error.message : 'Unknown error'
};
}
}
/**
* Get the full blog URL for a slug
*/
export function getBlogUrl(slug: string): string {
return `https://${slug}.${BASE_DOMAIN}`;
}