Skip to content

Commit b0dc958

Browse files
committed
fix: actively retrieve the feed
1 parent 9257869 commit b0dc958

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

src/data/index.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const exitWithError = (message) => {
2222
process.exit(1)
2323
}
2424

25-
const download = async () => {
25+
const getARDFeed = async () => {
2626
// download ard feed
2727
const response = await undici.fetch(ARD_FEED_URL)
2828
const feed = await response.json()
@@ -76,13 +76,8 @@ const download = async () => {
7676
}
7777
}
7878

79-
// save to local storage
80-
await Bun.write(
81-
`${__dirname}/../data/ard-core-livestreams.json`,
82-
JSON.stringify(feed, null, '\t')
83-
)
8479
console.log('ARD feed downloaded successfully')
85-
return null
80+
return feed
8681
}
8782

88-
download()
83+
module.exports = getARDFeed

src/ingest/subscriptions/post.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,18 @@ const response = require('../../utils/response')
1717
const config = require('../../../config')
1818

1919
// load api feed
20-
const feed = require('../../data')
20+
const getArdFeed = require('../../data')
2121

2222
const source = 'ingest/subscriptions/post'
2323

2424
module.exports = async (req, res) => {
25-
// check if env was set
26-
if (!process.env.ARD_FEED_URL)
27-
console.log('Feed-URL was not set')
28-
29-
const coreApi = require('../../data/ard-core-livestreams.json')
30-
3125
try {
3226
// generate subscription name
3327
const prefix = `${config.pubSubPrefix}subscription.`
3428

3529
// check existence of user institution
36-
const institutionExists = coreApi.items.some((entry) => {
30+
const ardFeed = await getArdFeed()
31+
const institutionExists = ardFeed.items.some((entry) => {
3732
return req.user.institutionId === entry.publisher.institution.id
3833
})
3934

src/utils/core/getPublisher.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
by SWR Audio Lab
55
66
*/
7-
const feed = require('../../data')
7+
const getArdFeed = require('../../data')
88

99
module.exports = async (publisherId) => {
10-
const coreApi = require('../../data/ard-core-livestreams.json')
1110

12-
const publisher = coreApi.items.find((entry) => {
11+
const ardFeed = await getArdFeed()
12+
const publisher = ardFeed.items.find((entry) => {
1313
return publisherId === entry.publisher.id ? entry.publisher : null
1414
})
1515

0 commit comments

Comments
 (0)