Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

adding that deletion of album removes its items

Marek Maslowski2baf407809eb
diff --git a/server/src/routes/memories/immich.ts b/server/src/routes/memories/immich.ts
index af9b4d0ec..fa892584b 100644
--- a/server/src/routes/memories/immich.ts
+++ b/server/src/routes/memories/immich.ts
@@ -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) => {
const authReq = req as AuthRequest;
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 });
res.json({ success: true, added: result.added, total: result.total });
if (result.added! > 0) {
diff --git a/server/src/routes/memories/synology.ts b/server/src/routes/memories/synology.ts
index 94ddd8865..1c7eb4c25 100644
--- a/server/src/routes/memories/synology.ts
+++ b/server/src/routes/memories/synology.ts
@@ -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) => {
const authReq = req as AuthRequest;
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) => {
diff --git a/server/src/services/memories/immichService.ts b/server/src/services/memories/immichService.ts
index da0dca0e6..5f8138dfd 100644
--- a/server/src/services/memories/immichService.ts
+++ b/server/src/services/memories/immichService.ts
@@ -343,7 +343,8 @@ export function deleteAlbumLink(linkId: string, tripId: string, userId: number)
export async function syncAlbumAssets(
tripId: string,
linkId: string,
- userId: number
+ userId: number,
+ sid: string,
): Promise<{ success?: boolean; added?: number; total?: number; error?: string; status?: number }> {
const response = getAlbumIdFromLink(tripId, linkId, userId);
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),
};
- 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 };
updateSyncTimeForAlbumLink(linkId);
diff --git a/server/src/services/memories/synologyService.ts b/server/src/services/memories/synologyService.ts
index 76b89163d..b9bdff25c 100644
--- a/server/src/services/memories/synologyService.ts
+++ b/server/src/services/memories/synologyService.ts
@@ -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);
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),
};
- updateSyncTimeForAlbumLink(linkId);
-
- const result = await addTripPhotos(tripId, userId, true, [selection]);
+
+ const result = await addTripPhotos(tripId, userId, true, [selection], sid, linkId);
if (!result.success) return result as ServiceResult<SyncAlbumResult>;
-
+
+ updateSyncTimeForAlbumLink(linkId);
+
return success({ added: result.data.added, total: allItems.length });
}
diff --git a/server/src/services/memories/unifiedService.ts b/server/src/services/memories/unifiedService.ts
index 35d47ebd3..b3918b813 100644
--- a/server/src/services/memories/unifiedService.ts
+++ b/server/src/services/memories/unifiedService.ts
@@ -67,10 +67,10 @@ export function listTripAlbumLinks(tripId: string, userId: number): ServiceResul
//-----------------------------------------------
// 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(
- 'INSERT OR IGNORE INTO trip_photos (trip_id, user_id, asset_id, provider, shared) VALUES (?, ?, ?, ?, ?)'
- ).run(tripId, userId, assetId, provider, shared ? 1 : 0);
+ '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, albumLinkId || null);
return result.changes > 0;
}
@@ -79,7 +79,8 @@ export async function addTripPhotos(
userId: number,
shared: boolean,
selections: Selection[],
- sid?: string,
+ sid: string,
+ albumLinkId?: string,
): Promise<ServiceResult<{ added: number; shared: boolean }>> {
const access = canAccessTrip(tripId, userId);
if (!access) {
@@ -96,7 +97,7 @@ export async function addTripPhotos(
for (const raw of selection.asset_ids) {
const assetId = String(raw || '').trim();
if (!assetId) continue;
- if (_addTripPhoto(tripId, userId, selection.provider, assetId, shared)) {
+ if (_addTripPhoto(tripId, userId, selection.provider, assetId, shared, albumLinkId)) {
added++;
}
}
@@ -213,9 +214,10 @@ export function removeAlbumLink(tripId: string, linkId: string, userId: number):
}
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 = ?')
.run(linkId, tripId, userId);
-
return success(true);
} catch (error) {
return mapDbError(error, 'Failed to remove album link');