-
- {config.selectedIds.length} Selected
-
-
- {config.selectedIds.length && config.selectedIds.length > 0 ? (
-
- ) : (
-
- )}
-
-
-
+ {selectedAssets.length &&
+
+
+
+ {config.selectedIds.length} Selected
+
+
+
+
+
+
+
+
+
+
+
+ Delete
+
+
+
-
-
+
+ }
);
diff --git a/src/pages/api/albums/potential-albums-dates.ts b/src/pages/api/albums/potential-albums-dates.ts
index 041cb27..ebbd867 100644
--- a/src/pages/api/albums/potential-albums-dates.ts
+++ b/src/pages/api/albums/potential-albums-dates.ts
@@ -3,52 +3,49 @@ import { db } from "@/config/db";
import { IPotentialAlbumsDatesResponse } from "@/handlers/api/album.handler";
import { getCurrentUser } from "@/handlers/serverUtils/user.utils";
import { parseDate } from "@/helpers/date.helper";
-import { sql } from "drizzle-orm";
+import { albumsAssetsAssets } from "@/schema/albumAssetsAssets.schema";
+import { albums } from "@/schema/albums.schema";
+import { assets } from "@/schema/assets.schema";
+import { exif } from "@/schema/exif.schema";
+import { and, count, desc, eq, gte, isNotNull, isNull, sql } from "drizzle-orm";
import type { NextApiRequest, NextApiResponse } from "next";
+import { number } from "zod";
-const SELECT_ORPHAN_PHOTOS = (ownerId: string) => sql`
-SELECT
- DATE(e."dateTimeOriginal") AS "date",
- COUNT(a."id") AS "asset_count"
-FROM
- "assets" a
-LEFT JOIN
- "albums_assets_assets" aaa ON a."id" = aaa."assetsId"
-LEFT JOIN
- "exif" e ON a."id" = e."assetId"
-WHERE
- aaa."albumsId" IS NULL
- AND a."ownerId" = ${ownerId}
- AND a."isVisible" = true
- AND e."dateTimeOriginal" IS NOT NULL
-GROUP BY
- DATE(e."dateTimeOriginal")
-ORDER BY
- "asset_count" DESC;
-`;
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
try {
- const { sortBy = "date", sortOrder = "desc" } = req.query;
+ const { sortBy = "date", sortOrder = "desc", minAssets = 1 } = req.query as any;
const currentUser = await getCurrentUser(req)
- const data = await db.execute(SELECT_ORPHAN_PHOTOS(currentUser.id)) as any;
- const rows = data.rows as IPotentialAlbumsDatesResponse[];
+ const rows = await db.select({
+ date: sql`DATE(${exif.dateTimeOriginal})`,
+ asset_count: desc(count(assets.id)),
+ }).from(assets)
+ .leftJoin(albumsAssetsAssets, eq(assets.id, albumsAssetsAssets.assetsId))
+ .leftJoin(exif, eq(assets.id, exif.assetId))
+ .where(and (
+ eq(assets.ownerId, currentUser.id),
+ eq(assets.isVisible, true),
+ isNull(albumsAssetsAssets.albumsId),
+ isNotNull(exif.dateTimeOriginal),
+
+ ))
+ .groupBy(sql`DATE(${exif.dateTimeOriginal})`) as IPotentialAlbumsDatesResponse[];
+
+ const filteredRows = rows.filter((row) => Number(row.asset_count) >= Number(minAssets));
if (sortBy === "date") {
- rows.sort((a, b) => {
- const aDate = parseDate(a.date, "yyyy-MM-dd");
- const bDate = parseDate(b.date, "yyyy-MM-dd");
+ filteredRows.sort((a, b) => {
+ const aDate = parseDate(a.date as string, "yyyy-MM-dd");
+ const bDate = parseDate(b.date as string, "yyyy-MM-dd");
return sortOrder === "asc" ? aDate.getTime() - bDate.getTime() : bDate.getTime() - aDate.getTime();
});
} else if (sortBy === "asset_count") {
- rows.sort((a, b) => {
- return sortOrder === "asc" ? a.asset_count - b.asset_count : b.asset_count - a.asset_count;
- });
+ filteredRows.sort((a, b) => sortOrder === "asc" ? a.asset_count - b.asset_count : b.asset_count - a.asset_count);
}
- return res.status(200).json(rows);
+ return res.status(200).json(filteredRows);
} catch (error: any) {
res.status(500).json({
error: error?.message,
diff --git a/src/pages/api/assets/geo-heatmap.ts b/src/pages/api/assets/geo-heatmap.ts
index ba5870a..e3d6eb0 100644
--- a/src/pages/api/assets/geo-heatmap.ts
+++ b/src/pages/api/assets/geo-heatmap.ts
@@ -3,26 +3,34 @@ import { NextApiResponse } from "next";
import { db } from "@/config/db";
import { getCurrentUser } from "@/handlers/serverUtils/user.utils";
import { NextApiRequest } from "next";
-import { assets, exif } from "@/schema";
-import { and, eq, isNotNull } from "drizzle-orm";
+import { assetFaces, assets, exif, person } from "@/schema";
+import { and, eq, inArray, isNotNull } from "drizzle-orm";
+import { albumsAssetsAssets } from "@/schema/albumAssetsAssets.schema";
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const currentUser = await getCurrentUser(req);
+ const { albumIds, peopleIds } = req.query as { albumIds: string, peopleIds: string };
if (!currentUser) {
return res.status(401).json({ message: 'Unauthorized' });
}
+
const dbAssets = await db.select({
assetId: assets.id,
latitude: exif.latitude,
longitude: exif.longitude,
}).from(assets)
.innerJoin(exif, eq(assets.id, exif.assetId))
+ .innerJoin(albumsAssetsAssets, eq(assets.id, albumsAssetsAssets.assetsId))
+ .innerJoin(assetFaces, eq(albumsAssetsAssets.assetsId, assetFaces.assetId))
+ .innerJoin(person, eq(assetFaces.personId, person.id))
.where(
and(
eq(assets.ownerId, currentUser.id),
isNotNull(exif.latitude),
- isNotNull(exif.longitude)
+ isNotNull(exif.longitude),
+ albumIds?.length > 0 ? inArray(albumsAssetsAssets.albumsId, [albumIds]) : undefined,
+ peopleIds?.length > 0 ? inArray(person.id, [peopleIds]) : undefined
)
);
const heatmapData = dbAssets.map((asset) => [
diff --git a/src/pages/api/people/list.ts b/src/pages/api/people/list.ts
index 4dabcd0..8789d5f 100644
--- a/src/pages/api/people/list.ts
+++ b/src/pages/api/people/list.ts
@@ -29,6 +29,7 @@ interface IQuery {
sort: ISortField;
sortOrder: "asc" | "desc";
query: string;
+ visibility: "all" | "visible" | "hidden";
}
export default async function handler(
req: NextApiRequest,
@@ -43,19 +44,21 @@ export default async function handler(
sortOrder = "desc",
type = "all",
query = "",
+ visibility = "all",
} = req.query as any as IQuery;
const currentUser = await getCurrentUser(req);
const maximumAssetCount = !maxValue || maxValue <= 0 ? 1000000 : maxValue;
+
const whereClause = and(
- eq(person.isHidden, false),
isNull(assets.duplicateId),
eq(assets.isVisible, true),
eq(assets.isArchived, false),
eq(assets.ownerId, currentUser.id),
type === "all" ? undefined : (type === "nameless" ? eq(person.name, "") : ne(person.name, "")),
- query && query.length > 0 ? ilike(person.name, `%${query}%`) : undefined
+ query && query.length > 0 ? ilike(person.name, `%${query}%`) : undefined,
+ visibility === "visible" ? eq(person.isHidden, false) : visibility === "hidden" ? eq(person.isHidden, true) : undefined
);
let dbQuery = db
diff --git a/src/pages/assets/geo-heatmap.tsx b/src/pages/assets/geo-heatmap.tsx
index fc1339c..94b376b 100644
--- a/src/pages/assets/geo-heatmap.tsx
+++ b/src/pages/assets/geo-heatmap.tsx
@@ -4,13 +4,19 @@ import React, { useEffect, useMemo, useState } from 'react'
import { useMap, useMapsLibrary } from '@vis.gl/react-google-maps';
import { APIProvider, Map } from '@vis.gl/react-google-maps';
import PageLayout from '@/components/layouts/PageLayout';
-import { getAssetGeoHeatmap } from '@/handlers/api/asset.handler';
+import { getAssetGeoHeatmap, IHeatMapParams } from '@/handlers/api/asset.handler';
import { useTheme } from 'next-themes';
-import { MapPinX } from 'lucide-react';
+import { MapPinX, X } from 'lucide-react';
+import AlbumDropdown from '@/components/shared/AlbumDropdown';
+import PeopleDropdown from '@/components/shared/PeopleDropdown';
+import { Button } from '@/components/ui/button';
+interface IHeatMapProps {
+ filters: IHeatMapParams;
+}
+
+const HeatMap = ({ filters }: IHeatMapProps) => {
-const HeatMap = () => {
-
const map = useMap();
const visualization = useMapsLibrary('visualization');
@@ -27,14 +33,15 @@ const HeatMap = () => {
useEffect(() => {
if (!heatmap) return;
- getAssetGeoHeatmap().then((data) => {
+ getAssetGeoHeatmap(filters).then((data) => {
+ heatmap.setData([]);
heatmap.setData(data.map(([lng, lat]: [number, number]) => ({
location: new google.maps.LatLng(lat, lng),
weight: 10
})));
});
- }, [heatmap]);
+ }, [heatmap, filters]);
useEffect(() => {
if (!heatmap) return;
@@ -53,6 +60,10 @@ export default function GeoHeatmap() {
const { googleMapsApiKey } = useConfig();
const { theme } = useTheme();
const [mapId, setMapId] = useState('7a9e2ebecd32a903');
+ const [filters, setFilters] = useState<{
+ albumIds?: string
+ peopleIds?: string
+ }>({ });
useEffect(() => {
if (theme === 'light') {
@@ -65,21 +76,42 @@ export default function GeoHeatmap() {
return (
-
+
+ {
+ setFilters({
+ ...filters,
+ albumIds: albumIds?.[0]
+ })
+ }} />
+ {
+ setFilters({
+ ...filters,
+ peopleIds: peopleIds?.[0]
+ })
+ }} />
+ setFilters({})}>
+ Clear
+
+ >
+ } />
{googleMapsApiKey ? (
-
+
-
-
+
+
) : (
diff --git a/src/pages/assets/missing-locations.tsx b/src/pages/assets/missing-locations.tsx
index cbdc167..2105088 100644
--- a/src/pages/assets/missing-locations.tsx
+++ b/src/pages/assets/missing-locations.tsx
@@ -13,6 +13,7 @@ import { deleteAssets, updateAssets } from "@/handlers/api/asset.handler";
import { IPlace } from "@/types/common";
import { SortDesc, SortAsc } from "lucide-react";
+import { isSameDay } from "date-fns";
import { useRouter } from "next/router";
import React, { useMemo } from "react";
import FloatingBar from "@/components/shared/FloatingBar";
@@ -29,21 +30,41 @@ export default function MissingLocations() {
assets: [],
sort: "fileOriginalDate",
sortOrder: "asc",
+ dates: []
});
const selectedAssets = useMemo(() => config.assets.filter((a) => config.selectedIds.includes(a.id)), [config.assets, config.selectedIds]);
- const handleSubmit = (place: IPlace) => {
- return updateAssets({
+ const handleSubmit = async (place: IPlace) => {
+ await updateAssets({
ids: config.selectedIds,
- latitude: place.latitude,
- longitude: place.longitude,
- }).then(() => {
- setConfig({
- ...config,
- selectedIds: [],
- });
- })
+ latitude: Number(place.latitude),
+ longitude: Number(place.longitude),
+ });
+
+ const newAssets = config.assets.filter(asset => !config.selectedIds.includes(asset.id));
+
+ if (config.startDate) {
+ const dayRecord = config.dates.filter(f => isSameDay(new Date(f.value), new Date(config.startDate!)));
+
+ if (dayRecord.length === 1) {
+ if (newAssets.length > 0)
+ dayRecord[0].asset_count = newAssets.length;
+ else {
+ const indexToRemove = config.dates.findIndex(v=>isSameDay(v.value, dayRecord[0].value));
+
+ if (indexToRemove !== -1) {
+ config.dates.splice(indexToRemove, 1);
+ }
+ }
+ }
+ }
+
+ setConfig({
+ ...config,
+ selectedIds: [],
+ assets: newAssets
+ });
};
const handleDelete = () => {
@@ -110,57 +131,58 @@ export default function MissingLocations() {
-
-
-
- {config.selectedIds.length} Selected
-
-
- {config.selectedIds.length === config.assets.length ? (
-
- setConfig({
- ...config,
- selectedIds: [],
- })
- }
+ {selectedAssets.length &&
+
+
+
+ {config.selectedIds.length} Selected
+
+
+ {config.selectedIds.length === config.assets.length ? (
+
+ setConfig({
+ ...config,
+ selectedIds: [],
+ })
+ }
+ >
+ Unselect all
+
+ ) : (
+
+ setConfig({
+ ...config,
+ selectedIds: config.assets.map((a) => a.id),
+ })
+ }
+ >
+ Select all
+
+ )}
+ {/* Seperator */}
+
+
+
+
- Unselect all
-
- ) : (
-
- setConfig({
- ...config,
- selectedIds: config.assets.map((a) => a.id),
- })
- }
- >
- Select all
-
- )}
- {/* Seperator */}
-
-
-
-
-
-
- Delete
-
-
+
+ Delete
+
+
+
-
-
+
+ }
);
diff --git a/src/styles/globals.scss b/src/styles/globals.scss
index fc4c145..afc4d8c 100644
--- a/src/styles/globals.scss
+++ b/src/styles/globals.scss
@@ -92,4 +92,10 @@
#ReactGridGallery img {
max-width: none !important;
height: none !important;
+}
+
+.dark {
+ .ReactGridGallery_tile {
+ @apply bg-zinc-800 !important;
+ }
}
\ No newline at end of file