mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
feat: Implement notification settings and logic for new video versions.
This commit is contained in:
@@ -26,6 +26,7 @@ interface NotificationSettings {
|
||||
telegramEnabled: boolean;
|
||||
emailEnabled: boolean;
|
||||
onNewVideo: boolean;
|
||||
onNewVersion: boolean;
|
||||
onNewComment: boolean;
|
||||
onNewReply: boolean;
|
||||
timezone: string;
|
||||
@@ -83,6 +84,7 @@ export default function SettingsPage() {
|
||||
telegramEnabled: false,
|
||||
emailEnabled: false,
|
||||
onNewVideo: true,
|
||||
onNewVersion: true,
|
||||
onNewComment: true,
|
||||
onNewReply: true,
|
||||
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC',
|
||||
@@ -257,6 +259,14 @@ export default function SettingsPage() {
|
||||
label="New Video Added"
|
||||
description="When a new video is added to one of your projects"
|
||||
/>
|
||||
<ToggleButton
|
||||
enabled={settings.onNewVersion}
|
||||
onToggle={() =>
|
||||
setSettings((s) => ({ ...s, onNewVersion: !s.onNewVersion }))
|
||||
}
|
||||
label="New Version Added"
|
||||
description="When a new version is added to an existing video"
|
||||
/>
|
||||
<ToggleButton
|
||||
enabled={settings.onNewComment}
|
||||
onToggle={() =>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { auth } from '@/lib/auth';
|
||||
import { ProjectMemberRole, WorkspaceMemberRole } from '@prisma/client';
|
||||
import { validateUrl, validateOptionalUrl } from '@/lib/validation';
|
||||
import { rateLimit } from '@/lib/rate-limit';
|
||||
import { notifyProjectOwner } from '@/lib/notifications';
|
||||
import { apiErrors, successResponse, withCacheControl } from '@/lib/api-response';
|
||||
|
||||
type RouteParams = { params: Promise<{ projectId: string; videoId: string }> };
|
||||
@@ -145,6 +146,19 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
|
||||
});
|
||||
});
|
||||
|
||||
// Notify project owner (fire-and-forget, skip if they added it themselves)
|
||||
if (video.project.ownerId !== session.user.id) {
|
||||
const baseUrl = process.env.NEXTAUTH_URL || '';
|
||||
notifyProjectOwner(video.project.ownerId, {
|
||||
type: 'new_version',
|
||||
projectName: video.project.name,
|
||||
videoTitle: video.title,
|
||||
versionLabel: version.versionLabel || `Version ${version.versionNumber}`,
|
||||
addedBy: session.user.name || 'A team member',
|
||||
url: `${baseUrl}/watch/${video.id}`,
|
||||
}).catch((err) => console.error('Notification failed:', err));
|
||||
}
|
||||
|
||||
const response = successResponse(version, 201);
|
||||
return withCacheControl(response, 'private, no-store');
|
||||
} catch (error) {
|
||||
|
||||
@@ -26,6 +26,7 @@ export async function GET() {
|
||||
telegramEnabled: false,
|
||||
emailEnabled: false,
|
||||
onNewVideo: true,
|
||||
onNewVersion: true,
|
||||
onNewComment: true,
|
||||
onNewReply: true,
|
||||
timezone: 'UTC',
|
||||
@@ -57,6 +58,7 @@ export async function PUT(request: NextRequest) {
|
||||
telegramEnabled,
|
||||
emailEnabled,
|
||||
onNewVideo,
|
||||
onNewVersion,
|
||||
onNewComment,
|
||||
onNewReply,
|
||||
timezone,
|
||||
@@ -76,6 +78,7 @@ export async function PUT(request: NextRequest) {
|
||||
telegramEnabled: !!telegramEnabled,
|
||||
emailEnabled: !!emailEnabled,
|
||||
onNewVideo: onNewVideo ?? true,
|
||||
onNewVersion: onNewVersion ?? true,
|
||||
onNewComment: onNewComment ?? true,
|
||||
onNewReply: onNewReply ?? true,
|
||||
timezone: timezone || 'UTC',
|
||||
@@ -86,6 +89,7 @@ export async function PUT(request: NextRequest) {
|
||||
telegramEnabled: !!telegramEnabled,
|
||||
emailEnabled: !!emailEnabled,
|
||||
onNewVideo: onNewVideo ?? true,
|
||||
onNewVersion: onNewVersion ?? true,
|
||||
onNewComment: onNewComment ?? true,
|
||||
onNewReply: onNewReply ?? true,
|
||||
timezone: timezone || 'UTC',
|
||||
|
||||
Reference in New Issue
Block a user