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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -9,12 +9,12 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
- uses: actions/setup-node@56899e050abffc08c2b3b61f3ec6a79a9dc3223d
- uses: actions/checkout@e2f20e631ae6d7dd3b768f56a5d2af784dd54791
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516
with:
node-version: 12
- uses: actions/cache@0781355a23dac32fd3bac414512f4b903437991a
- uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7
id: cache
with:
path: ~/.npm

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 }];
}