Support album-based photo lookup & routing
This commit is contained in:
@@ -5,18 +5,22 @@ import md5 from "md5";
|
|||||||
|
|
||||||
export async function getPhotoFromHash(albumUrl: string, hash: string): Promise<PhotoAlbumPhoto | null> {
|
export async function getPhotoFromHash(albumUrl: string, hash: string): Promise<PhotoAlbumPhoto | null> {
|
||||||
const client = await createDirectusConnection();
|
const client = await createDirectusConnection();
|
||||||
const result = await client.query(print(getPhotos));
|
const result = await client.query(print(getPhotos), {
|
||||||
|
albumUrl: albumUrl
|
||||||
|
});
|
||||||
|
|
||||||
|
let object: PhotoAlbumPhoto | null = null;
|
||||||
|
|
||||||
result["Photo_Albums"][0]["photos"].forEach((photo: any) => {
|
result["Photo_Albums"][0]["photos"].forEach((photo: any) => {
|
||||||
const hashObject = md5(JSON.stringify({
|
const hashObject = md5(JSON.stringify({
|
||||||
id: photo.id,
|
id: photo.id,
|
||||||
url: photo.photo.url,
|
url: photo.photo.filename_disk,
|
||||||
width: photo.photo.width,
|
width: photo.photo.width,
|
||||||
height: photo.photo.height
|
height: photo.photo.height
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (hash.substring(hash.length - 10) === hash) {
|
if (hashObject.substring(hashObject.length - 10) === hash) {
|
||||||
return {
|
object = {
|
||||||
id: photo.id,
|
id: photo.id,
|
||||||
text: photo.text,
|
text: photo.text,
|
||||||
photo: {
|
photo: {
|
||||||
@@ -27,4 +31,6 @@ export async function getPhotoFromHash(albumUrl: string, hash: string): Promise<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return object;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
query getPhotos {
|
query getPhotos($albumUrl: String!) {
|
||||||
Photo_Albums(sort: ["-start_date", "-date_created"], filter: { status: { _eq: "published" }, url: { _eq: "/mirai-nexus-2026" }, category: { Photo_Categories_id: { status: { _eq: "published" } } } }) {
|
Photo_Albums(sort: ["-start_date", "-date_created"], filter: { status: { _eq: "published" }, url: { _eq: $albumUrl }, category: { Photo_Categories_id: { status: { _eq: "published" } } } }) {
|
||||||
id,
|
id,
|
||||||
date_created,
|
date_created,
|
||||||
date_updated,
|
date_updated,
|
||||||
|
|||||||
@@ -148,7 +148,6 @@ export async function getPage(settings: GlobalSettings, route: string): Promise<
|
|||||||
params[key] = match[i + 1];
|
params[key] = match[i + 1];
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(params);
|
|
||||||
const photo = await getPhotoFromHash(`/${params["R"]}`, params["H"]);
|
const photo = await getPhotoFromHash(`/${params["R"]}`, params["H"]);
|
||||||
|
|
||||||
if (photo === null) {}
|
if (photo === null) {}
|
||||||
|
|||||||
@@ -4,11 +4,24 @@ import { getPage } from "@/lib/pages";
|
|||||||
import { getSettings } from "@/content/settings/settings"
|
import { getSettings } from "@/content/settings/settings"
|
||||||
import WebpageLayout from "@/layouts/WebpageLayout.astro";
|
import WebpageLayout from "@/layouts/WebpageLayout.astro";
|
||||||
|
|
||||||
|
export async function getStaticPaths() {
|
||||||
|
const settings = await getSettings();
|
||||||
|
const pages = await getAllRoutesList(settings);
|
||||||
|
|
||||||
|
console.log(pages);
|
||||||
|
|
||||||
|
let routes: any[] = [];
|
||||||
|
|
||||||
|
pages.forEach((page) => {
|
||||||
|
routes.push({ params: { route: page } });
|
||||||
|
})
|
||||||
|
|
||||||
|
return routes;
|
||||||
|
}
|
||||||
|
|
||||||
const settings = await getSettings();
|
const settings = await getSettings();
|
||||||
const routes = await getAllRoutesList(settings);
|
const routes = await getAllRoutesList(settings);
|
||||||
console.log(routes);
|
|
||||||
const page = await getPage(settings, "/album/2026/mirai-nexus-2026/6c0e4453ab");
|
const page = await getPage(settings, "/album/2026/mirai-nexus-2026/6c0e4453ab");
|
||||||
console.log(page);
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<WebpageLayout>
|
<WebpageLayout>
|
||||||
Reference in New Issue
Block a user