adding that deletion of album removes its items
This commit is contained in:
@@ -136,7 +136,8 @@ router.get('/albums', authenticate, async (req: Request, res: Response) => {
|
|||||||
router.post('/trips/:tripId/album-links/:linkId/sync', authenticate, async (req: Request, res: Response) => {
|
router.post('/trips/:tripId/album-links/:linkId/sync', authenticate, async (req: Request, res: Response) => {
|
||||||
const authReq = req as AuthRequest;
|
const authReq = req as AuthRequest;
|
||||||
const { tripId, linkId } = req.params;
|
const { tripId, linkId } = req.params;
|
||||||
const result = await syncAlbumAssets(tripId, linkId, authReq.user.id);
|
const sid = req.headers['x-socket-id'] as string;
|
||||||
|
const result = await syncAlbumAssets(tripId, linkId, authReq.user.id, sid);
|
||||||
if (result.error) return res.status(result.status!).json({ error: result.error });
|
if (result.error) return res.status(result.status!).json({ error: result.error });
|
||||||
res.json({ success: true, added: result.added, total: result.total });
|
res.json({ success: true, added: result.added, total: result.total });
|
||||||
if (result.added! > 0) {
|
if (result.added! > 0) {
|
||||||
|
|||||||
@@ -72,8 +72,9 @@ router.get('/albums', authenticate, async (req: Request, res: Response) => {
|
|||||||
router.post('/trips/:tripId/album-links/:linkId/sync', authenticate, async (req: Request, res: Response) => {
|
router.post('/trips/:tripId/album-links/:linkId/sync', authenticate, async (req: Request, res: Response) => {
|
||||||
const authReq = req as AuthRequest;
|
const authReq = req as AuthRequest;
|
||||||
const { tripId, linkId } = req.params;
|
const { tripId, linkId } = req.params;
|
||||||
|
const sid = req.headers['x-socket-id'] as string;
|
||||||
|
|
||||||
handleServiceResult(res, await syncSynologyAlbumLink(authReq.user.id, tripId, linkId));
|
handleServiceResult(res, await syncSynologyAlbumLink(authReq.user.id, tripId, sid, linkId));
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/search', authenticate, async (req: Request, res: Response) => {
|
router.post('/search', authenticate, async (req: Request, res: Response) => {
|
||||||
|
|||||||
@@ -343,7 +343,8 @@ export function deleteAlbumLink(linkId: string, tripId: string, userId: number)
|
|||||||
export async function syncAlbumAssets(
|
export async function syncAlbumAssets(
|
||||||
tripId: string,
|
tripId: string,
|
||||||
linkId: string,
|
linkId: string,
|
||||||
userId: number
|
userId: number,
|
||||||
|
sid: string,
|
||||||
): Promise<{ success?: boolean; added?: number; total?: number; error?: string; status?: number }> {
|
): Promise<{ success?: boolean; added?: number; total?: number; error?: string; status?: number }> {
|
||||||
const response = getAlbumIdFromLink(tripId, linkId, userId);
|
const response = getAlbumIdFromLink(tripId, linkId, userId);
|
||||||
if (!response.success) return { error: 'Album link not found', status: 404 };
|
if (!response.success) return { error: 'Album link not found', status: 404 };
|
||||||
@@ -365,7 +366,7 @@ export async function syncAlbumAssets(
|
|||||||
asset_ids: assets.map((a: any) => a.id),
|
asset_ids: assets.map((a: any) => a.id),
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await addTripPhotos(tripId, userId, true, [selection]);
|
const result = await addTripPhotos(tripId, userId, true, [selection], sid, linkId);
|
||||||
if ('error' in result) return { error: result.error.message, status: result.error.status };
|
if ('error' in result) return { error: result.error.message, status: result.error.status };
|
||||||
|
|
||||||
updateSyncTimeForAlbumLink(linkId);
|
updateSyncTimeForAlbumLink(linkId);
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ export async function listSynologyAlbums(userId: number): Promise<ServiceResult<
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function syncSynologyAlbumLink(userId: number, tripId: string, linkId: string): Promise<ServiceResult<SyncAlbumResult>> {
|
export async function syncSynologyAlbumLink(userId: number, tripId: string, linkId: string, sid: string): Promise<ServiceResult<SyncAlbumResult>> {
|
||||||
const response = getAlbumIdFromLink(tripId, linkId, userId);
|
const response = getAlbumIdFromLink(tripId, linkId, userId);
|
||||||
if (!response.success) return response as ServiceResult<SyncAlbumResult>;
|
if (!response.success) return response as ServiceResult<SyncAlbumResult>;
|
||||||
|
|
||||||
@@ -380,11 +380,12 @@ export async function syncSynologyAlbumLink(userId: number, tripId: string, link
|
|||||||
asset_ids: allItems.map(item => String(item.additional?.thumbnail?.cache_key || '')).filter(id => id),
|
asset_ids: allItems.map(item => String(item.additional?.thumbnail?.cache_key || '')).filter(id => id),
|
||||||
};
|
};
|
||||||
|
|
||||||
updateSyncTimeForAlbumLink(linkId);
|
|
||||||
|
const result = await addTripPhotos(tripId, userId, true, [selection], sid, linkId);
|
||||||
const result = await addTripPhotos(tripId, userId, true, [selection]);
|
|
||||||
if (!result.success) return result as ServiceResult<SyncAlbumResult>;
|
if (!result.success) return result as ServiceResult<SyncAlbumResult>;
|
||||||
|
|
||||||
|
updateSyncTimeForAlbumLink(linkId);
|
||||||
|
|
||||||
return success({ added: result.data.added, total: allItems.length });
|
return success({ added: result.data.added, total: allItems.length });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,10 +67,10 @@ export function listTripAlbumLinks(tripId: string, userId: number): ServiceResul
|
|||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
// managing photos in trip
|
// managing photos in trip
|
||||||
|
|
||||||
function _addTripPhoto(tripId: string, userId: number, provider: string, assetId: string, shared: boolean): boolean {
|
function _addTripPhoto(tripId: string, userId: number, provider: string, assetId: string, shared: boolean, albumLinkId?: string): boolean {
|
||||||
const result = db.prepare(
|
const result = db.prepare(
|
||||||
'INSERT OR IGNORE INTO trip_photos (trip_id, user_id, asset_id, provider, shared) VALUES (?, ?, ?, ?, ?)'
|
'INSERT OR IGNORE INTO trip_photos (trip_id, user_id, asset_id, provider, shared, album_link_id) VALUES (?, ?, ?, ?, ?, ?)'
|
||||||
).run(tripId, userId, assetId, provider, shared ? 1 : 0);
|
).run(tripId, userId, assetId, provider, shared ? 1 : 0, albumLinkId || null);
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,8 @@ export async function addTripPhotos(
|
|||||||
userId: number,
|
userId: number,
|
||||||
shared: boolean,
|
shared: boolean,
|
||||||
selections: Selection[],
|
selections: Selection[],
|
||||||
sid?: string,
|
sid: string,
|
||||||
|
albumLinkId?: string,
|
||||||
): Promise<ServiceResult<{ added: number; shared: boolean }>> {
|
): Promise<ServiceResult<{ added: number; shared: boolean }>> {
|
||||||
const access = canAccessTrip(tripId, userId);
|
const access = canAccessTrip(tripId, userId);
|
||||||
if (!access) {
|
if (!access) {
|
||||||
@@ -96,7 +97,7 @@ export async function addTripPhotos(
|
|||||||
for (const raw of selection.asset_ids) {
|
for (const raw of selection.asset_ids) {
|
||||||
const assetId = String(raw || '').trim();
|
const assetId = String(raw || '').trim();
|
||||||
if (!assetId) continue;
|
if (!assetId) continue;
|
||||||
if (_addTripPhoto(tripId, userId, selection.provider, assetId, shared)) {
|
if (_addTripPhoto(tripId, userId, selection.provider, assetId, shared, albumLinkId)) {
|
||||||
added++;
|
added++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,9 +214,10 @@ export function removeAlbumLink(tripId: string, linkId: string, userId: number):
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
db.prepare('DELETE FROM trip_photos WHERE trip_id = ? AND album_link_id = ?')
|
||||||
|
.run(tripId, linkId);
|
||||||
db.prepare('DELETE FROM trip_album_links WHERE id = ? AND trip_id = ? AND user_id = ?')
|
db.prepare('DELETE FROM trip_album_links WHERE id = ? AND trip_id = ? AND user_id = ?')
|
||||||
.run(linkId, tripId, userId);
|
.run(linkId, tripId, userId);
|
||||||
|
|
||||||
return success(true);
|
return success(true);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return mapDbError(error, 'Failed to remove album link');
|
return mapDbError(error, 'Failed to remove album link');
|
||||||
|
|||||||
Reference in New Issue
Block a user