some improvements (#1030)

* update GitHub Actions

> Node.js 12 actions are deprecated. For more information see:
> https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/.
> Please update the following actions to use Node.js 16: actions/checkout,
> actions/setup-node, actions/cache, actions/checkout

* show location in output if URL is redirected
This commit is contained in:
Andreas Gebhardt
2022-11-02 20:37:11 +01:00
committed by GitHub
parent ea0cc3c85c
commit 2193ea5da1
2 changed files with 8 additions and 6 deletions

View File

@@ -1,8 +1,9 @@
import fetch from 'node-fetch';
import { isRedirect } from 'node-fetch';
import {readFileSync} from 'fs';
const LINKS_OPTIONS = {
redirect: 'error',
redirect: 'manual',
headers: {
'Content-Type': 'application/json',
'user-agent':
@@ -56,8 +57,9 @@ const partition = (arr, func) => {
async function fetch_link(url) {
try {
const { ok, statusText, redirected } = await fetch(url, LINKS_OPTIONS);
return [url, { ok, status: statusText, redirected }];
const { headers, ok, status, statusText } = await fetch(url, LINKS_OPTIONS);
const redirect = isRedirect(status) ? { redirect: { src: url, dst: headers.get("location") } } : {};
return [url, { ok, status: statusText, ...redirect }];
} catch (error) {
return [url, { ok: false, status: error.message }];
}