Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • Andreas.Hubel/hackitm-activity-pub
1 result
Show changes
Commits on Source (2)
...@@ -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',
...@@ -66,7 +68,7 @@ async function fetchData<R>(query: any, variables: any) { ...@@ -66,7 +68,7 @@ async function fetchData<R>(query: any, variables: any) {
async function main() { async function main() {
const response = await fetchData(query, { id: '14278953' }); const response = await fetchData<EpisodeResponse>(query, { id: '14278953' });
if (response) { if (response) {
const activityPubEpisode = transformEpisode(response); const activityPubEpisode = transformEpisode(response);
...@@ -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",
......