refactor: Update email and webhook configurations in deploy workflow

This commit is contained in:
beilunyang
2024-12-23 22:11:58 +08:00
parent 963ad03feb
commit d8aa3062c8
5 changed files with 26 additions and 17 deletions

View File

@@ -106,22 +106,26 @@ jobs:
if: github.event_name == 'push'
run: |
if [ -z "${{ steps.previoustag.outputs.tag }}" ]; then
if git ls-files | grep -q "workers/email-receiver.ts"; then
# Check email worker and its dependencies
if git ls-files | grep -q -E "workers/email-receiver.ts|app/lib/schema.ts|app/lib/webhook.ts|app/config/webhook.ts"; then
echo "email_worker_changed=true" >> $GITHUB_OUTPUT
else
echo "email_worker_changed=false" >> $GITHUB_OUTPUT
fi
# Check cleanup worker
if git ls-files | grep -q "workers/cleanup.ts"; then
echo "cleanup_worker_changed=true" >> $GITHUB_OUTPUT
else
echo "cleanup_worker_changed=false" >> $GITHUB_OUTPUT
fi
else
if git diff ${{ steps.previoustag.outputs.tag }}..HEAD --name-only | grep -q "workers/email-receiver.ts"; then
# Check email worker and its dependencies changes
if git diff ${{ steps.previoustag.outputs.tag }}..HEAD --name-only | grep -q -E "workers/email-receiver.ts|app/lib/schema.ts|app/lib/webhook.ts|app/config/webhook.ts"; then
echo "email_worker_changed=true" >> $GITHUB_OUTPUT
else
echo "email_worker_changed=false" >> $GITHUB_OUTPUT
fi
# Check cleanup worker changes
if git diff ${{ steps.previoustag.outputs.tag }}..HEAD --name-only | grep -q "workers/cleanup.ts"; then
echo "cleanup_worker_changed=true" >> $GITHUB_OUTPUT
else

7
app/config/email.ts Normal file
View File

@@ -0,0 +1,7 @@
export const EMAIL_CONFIG = {
MAX_ACTIVE_EMAILS: 30, // Maximum number of active emails
POLL_INTERVAL: 10_000, // Polling interval in milliseconds
DOMAIN: process.env.NEXT_PUBLIC_EMAIL_DOMAIN || 'moemail.app', // Email domain
} as const
export type EmailConfig = typeof EMAIL_CONFIG

View File

@@ -1,14 +1,2 @@
export const EMAIL_CONFIG = {
MAX_ACTIVE_EMAILS: 30, // Maximum number of active emails
POLL_INTERVAL: 10_000, // Polling interval in milliseconds
DOMAIN: process.env.NEXT_PUBLIC_EMAIL_DOMAIN || 'moemail.app', // Email domain
} as const
export const WEBHOOK_CONFIG = {
MAX_RETRIES: 3, // Maximum retry count
TIMEOUT: 10_000, // Timeout time (milliseconds)
RETRY_DELAY: 1000, // Retry delay (milliseconds)
EVENTS: {
NEW_MESSAGE: 'new_message',
}
} as const
export * from './email'
export * from './webhook'

10
app/config/webhook.ts Normal file
View File

@@ -0,0 +1,10 @@
export const WEBHOOK_CONFIG = {
MAX_RETRIES: 3, // Maximum retry count
TIMEOUT: 10_000, // Timeout time (milliseconds)
RETRY_DELAY: 1000, // Retry delay (milliseconds)
EVENTS: {
NEW_MESSAGE: 'new_message',
}
} as const
export type WebhookConfig = typeof WEBHOOK_CONFIG

View File

@@ -3,7 +3,7 @@ import { drizzle } from 'drizzle-orm/d1'
import { messages, emails, webhooks } from '../app/lib/schema'
import { eq } from 'drizzle-orm'
import PostalMime from 'postal-mime'
import { WEBHOOK_CONFIG } from '../app/config'
import { WEBHOOK_CONFIG } from '../app/config/webhook'
import { EmailMessage } from '../app/lib/webhook'
const handleEmail = async (message: ForwardableEmailMessage, env: Env) => {