mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-23 07:11:46 +00:00
fixing routes for asset details
This commit is contained in:
@@ -12,19 +12,13 @@ import {
|
|||||||
getConnectionStatus,
|
getConnectionStatus,
|
||||||
browseTimeline,
|
browseTimeline,
|
||||||
searchPhotos,
|
searchPhotos,
|
||||||
listTripPhotos,
|
|
||||||
addTripPhotos,
|
|
||||||
removeTripPhoto,
|
|
||||||
togglePhotoSharing,
|
|
||||||
getAssetInfo,
|
|
||||||
proxyThumbnail,
|
proxyThumbnail,
|
||||||
proxyOriginal,
|
proxyOriginal,
|
||||||
isValidAssetId,
|
isValidAssetId,
|
||||||
listAlbums,
|
listAlbums,
|
||||||
listAlbumLinks,
|
|
||||||
createAlbumLink,
|
createAlbumLink,
|
||||||
deleteAlbumLink,
|
|
||||||
syncAlbumAssets,
|
syncAlbumAssets,
|
||||||
|
getAssetInfo,
|
||||||
} from '../services/immichService';
|
} from '../services/immichService';
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
@@ -89,11 +83,13 @@ router.post('/search', authenticate, async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
// ── Asset Details ──────────────────────────────────────────────────────────
|
// ── Asset Details ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
router.get('/trips/:tripId/photos', authenticate, (req: Request, res: Response) => {
|
router.get('/assets/:assetId/info', authenticate, async (req: Request, res: Response) => {
|
||||||
const authReq = req as AuthRequest;
|
const authReq = req as AuthRequest;
|
||||||
const { tripId } = req.params;
|
const { assetId } = req.params;
|
||||||
if (!canAccessTrip(tripId, authReq.user.id)) return res.status(404).json({ error: 'Trip not found' });
|
if (!isValidAssetId(assetId)) return res.status(400).json({ error: 'Invalid asset ID' });
|
||||||
res.json({ photos: listTripPhotos(tripId, authReq.user.id) });
|
const result = await getAssetInfo(authReq.user.id, assetId);
|
||||||
|
if (result.error) return res.status(result.status!).json({ error: result.error });
|
||||||
|
res.json(result.data);
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Proxy Immich Assets ────────────────────────────────────────────────────
|
// ── Proxy Immich Assets ────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { db, canAccessTrip } from '../db/database';
|
import { db } from '../db/database';
|
||||||
import { maybe_encrypt_api_key, decrypt_api_key } from './apiKeyCrypto';
|
import { maybe_encrypt_api_key, decrypt_api_key } from './apiKeyCrypto';
|
||||||
import { checkSsrf } from '../utils/ssrfGuard';
|
import { checkSsrf } from '../utils/ssrfGuard';
|
||||||
import { writeAudit } from './auditLog';
|
import { writeAudit } from './auditLog';
|
||||||
@@ -171,45 +171,6 @@ export async function searchPhotos(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Trip Photos ────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export function listTripPhotos(tripId: string, userId: number) {
|
|
||||||
return db.prepare(`
|
|
||||||
SELECT tp.asset_id AS immich_asset_id, tp.user_id, tp.shared, tp.added_at,
|
|
||||||
u.username, u.avatar, u.immich_url
|
|
||||||
FROM trip_photos tp
|
|
||||||
JOIN users u ON tp.user_id = u.id
|
|
||||||
WHERE tp.trip_id = ?
|
|
||||||
AND tp.provider = 'immich'
|
|
||||||
AND (tp.user_id = ? OR tp.shared = 1)
|
|
||||||
ORDER BY tp.added_at ASC
|
|
||||||
`).all(tripId, userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function addTripPhotos(
|
|
||||||
tripId: string,
|
|
||||||
userId: number,
|
|
||||||
assetIds: string[],
|
|
||||||
shared: boolean
|
|
||||||
): number {
|
|
||||||
const insert = db.prepare('INSERT OR IGNORE INTO trip_photos (trip_id, user_id, asset_id, provider, shared) VALUES (?, ?, ?, ?, ?)');
|
|
||||||
let added = 0;
|
|
||||||
for (const assetId of assetIds) {
|
|
||||||
const result = insert.run(tripId, userId, assetId, 'immich', shared ? 1 : 0);
|
|
||||||
if (result.changes > 0) added++;
|
|
||||||
}
|
|
||||||
return added;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function removeTripPhoto(tripId: string, userId: number, assetId: string) {
|
|
||||||
db.prepare('DELETE FROM trip_photos WHERE trip_id = ? AND user_id = ? AND asset_id = ? AND provider = ?')
|
|
||||||
.run(tripId, userId, assetId, 'immich');
|
|
||||||
}
|
|
||||||
|
|
||||||
export function togglePhotoSharing(tripId: string, userId: number, assetId: string, shared: boolean) {
|
|
||||||
db.prepare('UPDATE trip_photos SET shared = ? WHERE trip_id = ? AND user_id = ? AND asset_id = ? AND provider = ?')
|
|
||||||
.run(shared ? 1 : 0, tripId, userId, assetId, 'immich');
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Asset Info / Proxy ─────────────────────────────────────────────────────
|
// ── Asset Info / Proxy ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -323,15 +284,6 @@ export async function listAlbums(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listAlbumLinks(tripId: string) {
|
|
||||||
return db.prepare(`
|
|
||||||
SELECT tal.*, u.username
|
|
||||||
FROM trip_album_links tal
|
|
||||||
JOIN users u ON tal.user_id = u.id
|
|
||||||
WHERE tal.trip_id = ? AND tal.provider = 'immich'
|
|
||||||
ORDER BY tal.created_at ASC
|
|
||||||
`).all(tripId);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createAlbumLink(
|
export function createAlbumLink(
|
||||||
tripId: string,
|
tripId: string,
|
||||||
@@ -349,11 +301,6 @@ export function createAlbumLink(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteAlbumLink(linkId: string, tripId: string, userId: number) {
|
|
||||||
db.prepare('DELETE FROM trip_album_links WHERE id = ? AND trip_id = ? AND user_id = ?')
|
|
||||||
.run(linkId, tripId, userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function syncAlbumAssets(
|
export async function syncAlbumAssets(
|
||||||
tripId: string,
|
tripId: string,
|
||||||
linkId: string,
|
linkId: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user