forked from DebaucheryLibrarian/traxxx
Refactored Arch Angel, split off The Flourish. Added try URL util to simplify trying multiple actor URLs.
This commit is contained in:
20
src/utils/try-urls.js
Normal file
20
src/utils/try-urls.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const unprint = require('unprint');
|
||||
|
||||
async function tryUrls(urls, options) {
|
||||
return urls.filter(Boolean).reduce(async (chain, url) => {
|
||||
const acc = await chain;
|
||||
|
||||
if (acc?.res.ok) {
|
||||
return acc;
|
||||
}
|
||||
|
||||
const res = await unprint.get(url, options);
|
||||
|
||||
return {
|
||||
res,
|
||||
url,
|
||||
};
|
||||
}, Promise.resolve());
|
||||
}
|
||||
|
||||
module.exports = tryUrls;
|
||||
Reference in New Issue
Block a user