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
GitLab 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
9b098212
Unverified
Commit
9b098212
authored
3 months ago
by
Andreas Hubel
Browse files
Options
Downloads
Patches
Plain Diff
chore: cleanup & format
parent
3ff05281
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/server.ts
+90
-119
90 additions, 119 deletions
src/server.ts
with
90 additions
and
119 deletions
src/server.ts
+
90
−
119
View file @
9b098212
...
@@ -7,17 +7,26 @@ import { transformEpisode, transformEpisodeList } from './mappings';
...
@@ -7,17 +7,26 @@ 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
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
'
,
exchanges
:
[
cacheExchange
,
fetchExchange
],
exchanges
:
[
cacheExchange
,
fetchExchange
],
});
});
async
function
fetchData
<
R
>
(
query
:
any
,
variables
:
any
)
{
const
result
=
await
audiothekApi
.
query
<
R
>
(
query
,
variables
).
toPromise
();
if
(
result
.
error
)
{
throw
result
.
error
;
}
// console.log(JSON.stringify(result.data, null, 2));
return
result
.
data
;
}
app
.
get
(
'
/:actor/episodes/:id
'
,
async
(
req
,
res
)
=>
{
const
query
=
gql
`
const
query
=
gql
`
query Item {
query Item
($id: String!)
{
item(id:
"14278953"
) {
item(id:
$id
) {
show {
show {
coreId
coreId
externalId
externalId
...
@@ -34,7 +43,6 @@ const query = gql`
...
@@ -34,7 +43,6 @@ const query = gql`
url
url
}
}
}
}
coreDocument
}
}
assetId
assetId
url: sharingUrl
url: sharingUrl
...
@@ -46,7 +54,7 @@ const query = gql`
...
@@ -46,7 +54,7 @@ const query = gql`
url
url
title
title
}
}
coreDocument
#
coreDocument
audioList {
audioList {
title
title
audioCodec
audioCodec
...
@@ -56,32 +64,6 @@ const query = gql`
...
@@ -56,32 +64,6 @@ const query = gql`
}
}
`
;
`
;
async
function
fetchData
<
R
>
(
query
:
any
,
variables
:
any
)
{
const
result
=
await
audiothekApi
.
query
<
R
>
(
query
,
variables
).
toPromise
();
if
(
result
.
error
)
{
throw
result
.
error
;
}
// console.log(JSON.stringify(result.data, null, 2));
return
result
.
data
;
}
async
function
main
()
{
const
response
=
await
fetchData
<
EpisodeResponse
>
(
query
,
{
id
:
'
14278953
'
});
if
(
response
)
{
const
activityPubEpisode
=
transformEpisode
(
response
);
console
.
log
(
JSON
.
stringify
(
activityPubEpisode
,
null
,
2
));
}
}
// main();
app
.
get
(
'
/:actor/episodes/:id
'
,
async
(
req
,
res
)
=>
{
try
{
const
data
=
await
fetchData
<
EpisodeResponse
>
(
query
,
{
id
:
req
.
params
.
id
});
const
data
=
await
fetchData
<
EpisodeResponse
>
(
query
,
{
id
:
req
.
params
.
id
});
if
(
!
data
)
{
if
(
!
data
)
{
res
.
status
(
404
).
json
({
error
:
'
Episode not found
'
});
res
.
status
(
404
).
json
({
error
:
'
Episode not found
'
});
...
@@ -92,9 +74,6 @@ app.get('/:actor/episodes/:id', async (req, res) => {
...
@@ -92,9 +74,6 @@ app.get('/:actor/episodes/:id', async (req, res) => {
const
activityPubDocument
=
transformEpisode
(
data
);
const
activityPubDocument
=
transformEpisode
(
data
);
res
.
json
(
activityPubDocument
);
res
.
json
(
activityPubDocument
);
}
catch
(
error
)
{
res
.
status
(
500
).
json
({
error
:
'
Failed to fetch episode data
'
});
}
});
});
app
.
get
(
'
/:actor/episodes
'
,
async
(
req
,
res
)
=>
{
app
.
get
(
'
/:actor/episodes
'
,
async
(
req
,
res
)
=>
{
...
@@ -108,9 +87,7 @@ app.get('/:actor/episodes', async (req, res) => {
...
@@ -108,9 +87,7 @@ app.get('/:actor/episodes', async (req, res) => {
title
title
url
url
items(first: $first, orderBy: PUBLISH_DATE_DESC, offset: $offset, condition: {
items(first: $first, orderBy: PUBLISH_DATE_DESC, offset: $offset, condition: { isPublished: true }) {
isPublished: true
}) {
nodes {
nodes {
assetId
assetId
title
title
...
@@ -132,19 +109,15 @@ app.get('/:actor/episodes', async (req, res) => {
...
@@ -132,19 +109,15 @@ app.get('/:actor/episodes', async (req, res) => {
}
}
`
;
`
;
try
{
try
{
// 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
'
,
offset
});
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
;
}
}
const
activityPubDocument
=
transformEpisodeList
(
data
);
const
activityPubDocument
=
transformEpisodeList
(
data
);
res
.
json
(
activityPubDocument
);
res
.
json
(
activityPubDocument
);
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -165,10 +138,10 @@ app.get('/:actor/outbox', async (req, res) => {
...
@@ -165,10 +138,10 @@ app.get('/:actor/outbox', async (req, res) => {
totalCount
totalCount
}
}
}
}
}`
;
}
`
;
const
data
=
await
fetchData
<
any
>
(
query
,
{
showId
:
"
urn:ard:show:a42d1ea0b4a07053
"
});
const
data
=
await
fetchData
<
any
>
(
query
,
{
showId
:
'
urn:ard:show:a42d1ea0b4a07053
'
});
if
(
!
data
)
{
if
(
!
data
)
{
res
.
status
(
404
).
json
({
error
:
'
Show not found
'
});
res
.
status
(
404
).
json
({
error
:
'
Show not found
'
});
return
;
return
;
...
@@ -177,37 +150,35 @@ app.get('/:actor/outbox', async (req, res) => {
...
@@ -177,37 +150,35 @@ app.get('/:actor/outbox', async (req, res) => {
const
{
totalCount
}
=
data
.
show
.
items
;
const
{
totalCount
}
=
data
.
show
.
items
;
res
.
json
({
res
.
json
({
"
@context
"
:
"
https://www.w3.org/ns/activitystreams
"
,
'
@context
'
:
'
https://www.w3.org/ns/activitystreams
'
,
"
id
"
:
`
${
root
}
/outbox`
,
id
:
`
${
root
}
/outbox`
,
"
type
"
:
"
OrderedCollection
"
,
type
:
'
OrderedCollection
'
,
"
to
"
:
[
to
:
[
'
https://www.w3.org/ns/activitystreams#Public
'
],
"
https://www.w3.org/ns/activitystreams#Public
"
totalItems
:
totalCount
,
],
first
:
`
${
root
}
/episodes?page=1`
,
"
totalItems
"
:
totalCount
,
current
:
`
${
root
}
/outbox`
,
"
first
"
:
`
${
root
}
/episodes?page=1`
,
last
:
`
${
root
}
/episodes?page=
${
Math
.
floor
(
totalCount
/
10
)}
`
,
"
current
"
:
`
${
root
}
/outbox`
,
"
last
"
:
`
${
root
}
/episodes?page=
${
Math
.
floor
(
totalCount
/
10
)}
`
});
});
});
});
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
'
,
"
id
"
:
"
urn:ard:show:a42d1ea0b4a07053
"
,
id
:
'
urn:ard:show:a42d1ea0b4a07053
'
,
"
type
"
:
"
Service
"
,
type
:
'
Service
'
,
"
name
"
:
"
Blaue Couch
"
,
name
:
'
Blaue Couch
'
,
"
externalId
"
:
"
https://feeds.br.de/blaue-couch/feed.xml
"
,
externalId
:
'
https://feeds.br.de/blaue-couch/feed.xml
'
,
"
attributedTo
"
:
"
urn:ard:publisher:c4a9cee041835529
"
,
attributedTo
:
'
urn:ard:publisher:c4a9cee041835529
'
,
"
publisher
"
:
{
publisher
:
{
"
type
"
:
"
BroadcastService
"
,
type
:
'
BroadcastService
'
,
"
name
"
:
"
BAYERN 1
"
,
name
:
'
BAYERN 1
'
,
"
url
"
:
"
https://www.ardaudiothek.de/radio/br/bayern-1/
"
,
url
:
'
https://www.ardaudiothek.de/radio/br/bayern-1/
'
,
"
organization
"
:
{
organization
:
{
"
type
"
:
"
Organization
"
,
type
:
'
Organization
'
,
"
name
"
:
"
BR
"
,
name
:
'
BR
'
,
"
url
"
:
"
https://www.ardaudiothek.de/radio/br/
"
url
:
'
https://www.ardaudiothek.de/radio/br/
'
,
}
}
,
}
}
,
});
});
});
});
...
...
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