diff --git a/src/handlers/serverUtils/user.utils.ts b/src/handlers/serverUtils/user.utils.ts index a47eed2..1a97283 100644 --- a/src/handlers/serverUtils/user.utils.ts +++ b/src/handlers/serverUtils/user.utils.ts @@ -40,6 +40,7 @@ export const getCurrentUser = async (req: NextApiRequest) => { if (session) { const user = await getCurrentUserFromAccessToken(session) + if (!user) return null return { ...user, accessToken: session, diff --git a/src/pages/api/albums/potential-albums-assets.ts b/src/pages/api/albums/potential-albums-assets.ts index 6dbbd5f..0cd9bfe 100644 --- a/src/pages/api/albums/potential-albums-assets.ts +++ b/src/pages/api/albums/potential-albums-assets.ts @@ -36,6 +36,7 @@ const SELECT_ORPHAN_PHOTOS = (date: string, ownerId: string) => aaa."albumsId" IS NULL AND a."ownerId" = '${ownerId}' AND a."localDateTime"::date = '${date}' + AND a."isVisible" = true `); export default async function handler( diff --git a/src/pages/api/albums/potential-albums-dates.ts b/src/pages/api/albums/potential-albums-dates.ts index 45af737..cb2c751 100644 --- a/src/pages/api/albums/potential-albums-dates.ts +++ b/src/pages/api/albums/potential-albums-dates.ts @@ -17,6 +17,7 @@ LEFT JOIN WHERE aaa."albumsId" IS NULL AND a."ownerId" = ${ownerId} + AND a."isVisible" = true GROUP BY DATE(a."localDateTime") ORDER BY diff --git a/src/pages/api/assets/missing-location-assets.ts b/src/pages/api/assets/missing-location-assets.ts index 67f1c8e..2d6d16a 100644 --- a/src/pages/api/assets/missing-location-assets.ts +++ b/src/pages/api/assets/missing-location-assets.ts @@ -53,6 +53,7 @@ export default async function handler( lte(exif.dateTimeOriginal, endDateDate), eq(assets.type, "VIDEO"), eq(assets.ownerId, currentUser.id), + eq(assets.isVisible, true), )); return res.status(200).json(rows); diff --git a/src/pages/api/assets/missing-location-dates.ts b/src/pages/api/assets/missing-location-dates.ts index 01eea33..86af049 100644 --- a/src/pages/api/assets/missing-location-dates.ts +++ b/src/pages/api/assets/missing-location-dates.ts @@ -23,6 +23,7 @@ export default async function handler( isNull(exif.latitude), eq(assets.type, "VIDEO"), eq(assets.ownerId, currentUser.id), + eq(assets.isVisible, true), )) .groupBy(sql`DATE(${exif.dateTimeOriginal})`) .orderBy(desc(count(assets.id))); diff --git a/src/pages/api/immich-proxy/asset/thumbnail/[id].ts b/src/pages/api/immich-proxy/asset/thumbnail/[id].ts index 5a73569..d130d41 100644 --- a/src/pages/api/immich-proxy/asset/thumbnail/[id].ts +++ b/src/pages/api/immich-proxy/asset/thumbnail/[id].ts @@ -1,6 +1,7 @@ // pages/api/proxy.js import { ENV } from '@/config/environment'; +import { getCurrentUser } from '@/handlers/serverUtils/user.utils'; import { NextApiRequest, NextApiResponse } from 'next' export const config = { @@ -17,13 +18,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const { id, size } = req.query; const targetUrl = `${ENV.IMMICH_URL}/api/assets/${id}/thumbnail?size=${size || 'thumbnail'}`; + const user = await getCurrentUser(req); + if (!user) { + return res.status(403).json({ message: 'Unauthorized' }) + } try { // Forward the request to the target API const response = await fetch(targetUrl, { method: 'GET', headers: { 'Content-Type': 'application/octet-stream', - 'x-api-key': ENV.IMMICH_API_KEY, + 'Authorization': `Bearer ${user.accessToken}`, }, }) @@ -42,7 +47,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) // Send the image data res.send(Buffer.from(imageBuffer)) } catch (error) { - console.error('Error:', error) res.status(500).json({ message: 'Internal Server Error' }) } } \ No newline at end of file diff --git a/src/pages/api/users/me.ts b/src/pages/api/users/me.ts index 38b8496..10f8169 100644 --- a/src/pages/api/users/me.ts +++ b/src/pages/api/users/me.ts @@ -17,7 +17,8 @@ export default async function handler( return res.status(405).json({ message: "Method Not Allowed" }); - const user = getCurrentUser(req); + const user = await getCurrentUser(req); + console.log("currentUser.accessToken:", user); if (user) return res.status(200).json(user);