Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HackITM ActivityPub Fediverse Experimente
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Hubel
HackITM ActivityPub Fediverse Experimente
Commits
3ff05281
Commit
3ff05281
authored
2 months ago
by
Benedikt Hermann
Browse files
Options
Downloads
Patches
Plain Diff
add outbox route + pagination
parent
9b9314a7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/server.ts
+43
-2
43 additions, 2 deletions
src/server.ts
with
43 additions
and
2 deletions
src/server.ts
+
43
−
2
View file @
3ff05281
...
@@ -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
"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment