-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add context retrieval for reads via books-mf2
Using the service books-mf2, we can retrieve the context for read data. As it's a Heroku-based app, there's the risk that this can timeout, so we need to increase the timeouts available for context retrieval events.
- Loading branch information
1 parent
4c0e8ce
commit 2748f2b
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const fetch = require('node-fetch') | ||
const logger = require('@architect/shared/logger') | ||
|
||
function name () { | ||
return 'Books-MF2' | ||
} | ||
|
||
function isBooksMf2Url (url) { | ||
return (url.indexOf('https://books-mf2.herokuapp.com/') > -1) | ||
} | ||
|
||
async function fetchContext (url) { | ||
if (!isBooksMf2Url(url)) { | ||
return | ||
} | ||
const response = await fetch(url) | ||
if (!response.ok) { | ||
const text = await response.text() | ||
logger.warn('Failed to fetch context from Books-MF2', `${url}\n${text}`) | ||
return | ||
} | ||
const mf2 = await response.json() | ||
if (!('items' in mf2) || !mf2.items.length) return | ||
return mf2.items[0].properties | ||
} | ||
|
||
module.exports = { | ||
name, | ||
isBooksMf2Url, | ||
fetchContext | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@aws | ||
timeout 15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters