From 24ce07220cede14952a9999de61265cf9213474a Mon Sep 17 00:00:00 2001
From: "wolfgang.preussger@br.de" <wolfgang.preussger@br.de>
Date: Thu, 13 Mar 2025 15:41:16 +0100
Subject: [PATCH] add allshows

---
 src/mappings.ts | 17 +++++++++++++++++
 src/server.ts   | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/src/mappings.ts b/src/mappings.ts
index db90fd8..59897c1 100644
--- a/src/mappings.ts
+++ b/src/mappings.ts
@@ -66,4 +66,21 @@ export function transformEpisodeList(input: any): ActivityPubOutbox {
       type: "OrderedCollection",
       orderedItems,
     };
+  }
+
+  export function transformShows(nodes: any) {
+    const items: ActivityPubNote[] = nodes.map((show: any) => ({
+      id: show.coreId,
+      type: "Service",
+      actor: 'TODO',
+      to: ["https://www.w3.org/ns/activitystreams#Public"],
+      name: show.title,
+      url: show.url,
+    }));
+    
+    return {
+      type: "Collection",
+      items,
+      "@context": "https://www.w3.org/ns/activitystreams",
+    };
   }
\ No newline at end of file
diff --git a/src/server.ts b/src/server.ts
index 5a3b8b1..29df752 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -2,7 +2,7 @@ import express from 'express';
 
 import { Client, cacheExchange, fetchExchange, gql } from '@urql/core';
 import { EpisodeResponse } from './types';
-import { transformEpisode, transformEpisodeList } from './mappings';
+import { transformEpisode, transformEpisodeList, transformShows } from './mappings';
 
 const app = express();
 const PORT = 3000;
@@ -161,6 +161,48 @@ app.get('/:actor/outbox', async (req, res) => {
 	});
 });
 
+app.get('/shows', async (req, res) => {
+	const query = gql`
+		query AllShows {
+  shows: programSets(orderBy: LAST_ITEM_MODIFIED_DESC, filter: {numberOfElements: {notEqualTo: 0}}) {
+    totalCount
+    nodes {
+      coreId
+      title
+      lastItemAdded
+      lastItemModified
+      url: sharingUrl
+      publicationService {
+        title
+        dvbServiceId
+        organization {
+          name
+        }
+      }
+    }
+  }
+}
+	`;
+
+	const data = await fetchData<any>(query, {  });
+	if (!data) {
+		res.status(404).json({ error: 'Shows not found' });
+		return;
+	}
+
+	const { nodes, totalCount } = data.shows;
+
+	res.json({
+		id: `${root}/TODO`,
+		to: ['https://www.w3.org/ns/activitystreams#Public'],
+		totalItems: totalCount,
+		first: `${root}/shows?page=1`,
+		current: `${root}/outbox`,
+		last: `${root}/shows?page=${Math.floor(totalCount / 10)}`,
+    ...transformShows(nodes)
+	});
+});
+
 app.get('/:actor', async (req, res) => {
 	res.json({
 		'@context': 'https://www.w3.org/ns/activitystreams',
@@ -184,6 +226,9 @@ app.get('/:actor', async (req, res) => {
 
 app.get('/', (req, res) => res.redirect('/@blaue-couch'));
 
+
 app.listen(PORT, () => {
 	console.log(`Server running at http://localhost:${PORT}`);
 });
+
+
-- 
GitLab