Skip to content
Snippets Groups Projects
Commit 24ce0722 authored by Wolfgang Preussger's avatar Wolfgang Preussger
Browse files

add allshows

parent 9b098212
No related branches found
No related tags found
No related merge requests found
...@@ -66,4 +66,21 @@ export function transformEpisodeList(input: any): ActivityPubOutbox { ...@@ -66,4 +66,21 @@ export function transformEpisodeList(input: any): ActivityPubOutbox {
type: "OrderedCollection", type: "OrderedCollection",
orderedItems, 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
...@@ -2,7 +2,7 @@ import express from 'express'; ...@@ -2,7 +2,7 @@ import express from 'express';
import { Client, cacheExchange, fetchExchange, gql } from '@urql/core'; import { Client, cacheExchange, fetchExchange, gql } from '@urql/core';
import { EpisodeResponse } from './types'; import { EpisodeResponse } from './types';
import { transformEpisode, transformEpisodeList } from './mappings'; import { transformEpisode, transformEpisodeList, transformShows } from './mappings';
const app = express(); const app = express();
const PORT = 3000; const PORT = 3000;
...@@ -161,6 +161,48 @@ app.get('/:actor/outbox', async (req, res) => { ...@@ -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) => { app.get('/:actor', async (req, res) => {
res.json({ res.json({
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',
...@@ -184,6 +226,9 @@ app.get('/:actor', async (req, res) => { ...@@ -184,6 +226,9 @@ app.get('/:actor', async (req, res) => {
app.get('/', (req, res) => res.redirect('/@blaue-couch')); app.get('/', (req, res) => res.redirect('/@blaue-couch'));
app.listen(PORT, () => { app.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`); console.log(`Server running at http://localhost:${PORT}`);
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment