diff --git a/src/server.ts b/src/server.ts index ad8ca99113a3d267d15d2099f33c31812d046ce1..2f5a5c41d8699af950998f909d153cf3b12c527d 100644 --- a/src/server.ts +++ b/src/server.ts @@ -7,6 +7,8 @@ import { transformEpisode, transformEpisodeList } from './mappings'; const app = express(); const PORT = 3000; +const root = "https://social.audiothek.de/@blaue-couch" + const audiothekApi = new Client({ url: 'https://api.ardaudiothek.de/graphql', @@ -96,6 +98,8 @@ app.get('/:actor/episodes/:id', async (req, res) => { }); app.get('/:actor/episodes', async (req, res) => { + const offset = 10 * ((+req.query.page! || 1) - 1); + const query = gql` query ShowWithEpisodes($showId: ID!, $first: Int = 10, $offset: Int) { show(id: $showId) { @@ -134,7 +138,7 @@ app.get('/:actor/episodes', async (req, res) => { // TODO: verifiy that the actor is the same as the attributedTo field - const data = await fetchData<any>(query, { showId: "urn:ard:show:a42d1ea0b4a07053" }); + const data = await fetchData<any>(query, { showId: "urn:ard:show:a42d1ea0b4a07053", offset }); if (!data) { res.status(404).json({ error: 'Episode not found' }); return; @@ -148,8 +152,45 @@ app.get('/:actor/episodes', async (req, res) => { } }); +app.get('/:actor/outbox', async (req, res) => { + const query = gql` + query ShowEpisodeTotal($showId: ID!) { + show(id: $showId) { + coreId + externalId + title + url + + items(condition: { isPublished: true }) { + totalCount + } + } +}`; + + + const data = await fetchData<any>(query, { showId: "urn:ard:show:a42d1ea0b4a07053" }); + if (!data) { + res.status(404).json({ error: 'Show not found' }); + return; + } + + const { totalCount } = data.show.items; + + res.json({ + "@context": "https://www.w3.org/ns/activitystreams", + "id": `${root}/outbox`, + "type": "OrderedCollection", + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "totalItems": totalCount, + "first": `${root}/episodes?page=1`, + "current": `${root}/outbox`, + "last": `${root}/episodes?page=${Math.floor(totalCount/10)}` + }); +}); -app.get('/@blaue-couch', async (req, res) => { +app.get('/:actor', async (req, res) => { res.json({ "@context": "https://www.w3.org/ns/activitystreams", "id": "urn:ard:show:a42d1ea0b4a07053",