feat: support per-gallery password toggle
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
import { api } from '../config/api';
|
||||
import type { LoginResponse, GalleryAuthResponse } from '../types';
|
||||
import { normalizeRequirePassword } from '../utils/accessControl';
|
||||
|
||||
const normalizeGalleryResponse = (response: GalleryAuthResponse): GalleryAuthResponse => ({
|
||||
...response,
|
||||
event: response.event
|
||||
? {
|
||||
...response.event,
|
||||
require_password: normalizeRequirePassword((response.event as any)?.require_password, true),
|
||||
}
|
||||
: response.event,
|
||||
});
|
||||
|
||||
export const authService = {
|
||||
// Admin authentication
|
||||
@@ -24,7 +35,7 @@ export const authService = {
|
||||
},
|
||||
|
||||
// Gallery authentication
|
||||
async verifyGalleryPassword(slug: string, password: string, recaptchaToken?: string | null): Promise<GalleryAuthResponse> {
|
||||
async verifyGalleryPassword(slug: string, password?: string, recaptchaToken?: string | null): Promise<GalleryAuthResponse> {
|
||||
const response = await api.post<GalleryAuthResponse>('/auth/gallery/verify', {
|
||||
slug,
|
||||
password,
|
||||
@@ -32,7 +43,7 @@ export const authService = {
|
||||
});
|
||||
|
||||
// Token is now handled by GalleryAuthContext with slug-specific storage
|
||||
return response.data;
|
||||
return normalizeGalleryResponse(response.data);
|
||||
},
|
||||
|
||||
async shareLinkLogin(slug: string, token: string): Promise<GalleryAuthResponse> {
|
||||
@@ -40,7 +51,7 @@ export const authService = {
|
||||
slug,
|
||||
token,
|
||||
});
|
||||
return response.data;
|
||||
return normalizeGalleryResponse(response.data);
|
||||
},
|
||||
|
||||
async galleryLogout(slug?: string | null) {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { api } from '../config/api';
|
||||
import type { Event } from '../types';
|
||||
import { normalizeRequirePassword } from '../utils/accessControl';
|
||||
|
||||
const normalizeEvent = (event: Event): Event => ({
|
||||
...event,
|
||||
require_password: normalizeRequirePassword((event as any)?.require_password, true),
|
||||
});
|
||||
|
||||
interface CreateEventData {
|
||||
event_type: string;
|
||||
@@ -7,6 +13,7 @@ interface CreateEventData {
|
||||
event_date: string;
|
||||
host_email: string;
|
||||
admin_email: string;
|
||||
require_password?: boolean;
|
||||
password: string;
|
||||
welcome_message?: string;
|
||||
color_theme?: string;
|
||||
@@ -28,6 +35,7 @@ interface UpdateEventData {
|
||||
event_date?: string;
|
||||
host_email?: string;
|
||||
admin_email?: string;
|
||||
require_password?: boolean;
|
||||
password?: string;
|
||||
welcome_message?: string;
|
||||
color_theme?: string;
|
||||
@@ -64,19 +72,25 @@ export const eventsService = {
|
||||
}
|
||||
|
||||
const response = await api.get<EventsListResponse>(`/admin/events?${params}`);
|
||||
return response.data;
|
||||
const data: any = response.data;
|
||||
if (Array.isArray(data?.events)) {
|
||||
data.events = data.events.map((event: Event) => normalizeEvent(event));
|
||||
} else if (Array.isArray(data)) {
|
||||
return data.map((event: Event) => normalizeEvent(event)) as any;
|
||||
}
|
||||
return data;
|
||||
},
|
||||
|
||||
// Get single event details (admin)
|
||||
async getEvent(id: number): Promise<Event> {
|
||||
const response = await api.get<Event>(`/admin/events/${id}`);
|
||||
return response.data;
|
||||
return normalizeEvent(response.data as Event);
|
||||
},
|
||||
|
||||
// Create new event (admin)
|
||||
async createEvent(data: CreateEventData): Promise<Event> {
|
||||
const response = await api.post<Event>('/admin/events', data);
|
||||
return response.data;
|
||||
return normalizeEvent(response.data as Event);
|
||||
},
|
||||
|
||||
// Update event (admin)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { api } from '../config/api';
|
||||
import type { GalleryInfo, GalleryData, GalleryStats } from '../types';
|
||||
import { normalizeRequirePassword } from '../utils/accessControl';
|
||||
|
||||
export const galleryService = {
|
||||
// Verify share token
|
||||
@@ -12,7 +13,11 @@ export const galleryService = {
|
||||
async getGalleryInfo(slug: string, token?: string): Promise<GalleryInfo> {
|
||||
const params = token ? { token } : {};
|
||||
const response = await api.get<GalleryInfo>(`/gallery/${slug}/info`, { params });
|
||||
return response.data;
|
||||
const data = response.data;
|
||||
return {
|
||||
...data,
|
||||
requires_password: normalizeRequirePassword((data as any)?.requires_password, true),
|
||||
};
|
||||
},
|
||||
|
||||
// Get gallery photos (requires auth)
|
||||
@@ -29,7 +34,17 @@ export const galleryService = {
|
||||
}
|
||||
}
|
||||
const response = await api.get<GalleryData>(`/gallery/${slug}/photos`, { params });
|
||||
return response.data;
|
||||
const data = response.data;
|
||||
const normalizedEvent = data?.event
|
||||
? {
|
||||
...data.event,
|
||||
require_password: normalizeRequirePassword((data.event as any)?.require_password, true),
|
||||
}
|
||||
: data.event;
|
||||
return {
|
||||
...data,
|
||||
event: normalizedEvent,
|
||||
};
|
||||
},
|
||||
|
||||
// Download single photo
|
||||
|
||||
Reference in New Issue
Block a user