Skip to content
Snippets Groups Projects
Commit 3ff05281 authored by Benedikt Hermann's avatar Benedikt Hermann
Browse files

add outbox route + pagination

parent 9b9314a7
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,8 @@ import { transformEpisode, transformEpisodeList } from './mappings'; ...@@ -7,6 +7,8 @@ import { transformEpisode, transformEpisodeList } from './mappings';
const app = express(); const app = express();
const PORT = 3000; const PORT = 3000;
const root = "https://social.audiothek.de/@blaue-couch"
const audiothekApi = new Client({ const audiothekApi = new Client({
url: 'https://api.ardaudiothek.de/graphql', url: 'https://api.ardaudiothek.de/graphql',
...@@ -96,6 +98,8 @@ app.get('/:actor/episodes/:id', async (req, res) => { ...@@ -96,6 +98,8 @@ app.get('/:actor/episodes/:id', async (req, res) => {
}); });
app.get('/:actor/episodes', async (req, res) => { app.get('/:actor/episodes', async (req, res) => {
const offset = 10 * ((+req.query.page! || 1) - 1);
const query = gql` const query = gql`
query ShowWithEpisodes($showId: ID!, $first: Int = 10, $offset: Int) { query ShowWithEpisodes($showId: ID!, $first: Int = 10, $offset: Int) {
show(id: $showId) { show(id: $showId) {
...@@ -134,7 +138,7 @@ app.get('/:actor/episodes', async (req, res) => { ...@@ -134,7 +138,7 @@ app.get('/:actor/episodes', async (req, res) => {
// TODO: verifiy that the actor is the same as the attributedTo field // 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) { if (!data) {
res.status(404).json({ error: 'Episode not found' }); res.status(404).json({ error: 'Episode not found' });
return; return;
...@@ -148,8 +152,45 @@ app.get('/:actor/episodes', async (req, res) => { ...@@ -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({ res.json({
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
"id": "urn:ard:show:a42d1ea0b4a07053", "id": "urn:ard:show:a42d1ea0b4a07053",
......
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