Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed Dec 5, 2023
1 parent 160f702 commit ee41263
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 30 deletions.
11 changes: 6 additions & 5 deletions bin/newest-adobe.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,16 @@ async function main() {

console.log(`${task.resource.source}: Checking`);

const response = await fetch(task.resource.source, {
const {status: statusE, source: url} = task.resource;
const response = await fetch(url, {
method: 'HEAD',
redirect: 'manual'
});
const {status, headers} = response;

const {status} = task.resource;
if (response.status !== status) {
if (status !== statusE) {
throw new Error(
`Unexpected status code: ${response.status} != ${status}`
`Status code: ${status} != ${statusE}: ${url}`
);
}

Expand All @@ -164,7 +165,7 @@ async function main() {
if (typeof expected === 'undefined') {
continue;
}
const actual = response.headers.get(header);
const actual = headers.get(header);
const actualValue = typeof expected === 'number' ?
+actual : actual;

Expand Down
10 changes: 6 additions & 4 deletions bin/newest-cn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,25 @@ async function main() {
continue;
}

const url = `${source}?_=${Date.now()}`;
// eslint-disable-next-line no-await-in-loop
const response = await fetch(`${source}?_=${Date.now()}`, {
const response = await fetch(url, {
method: 'HEAD',
headers: {
'User-Agent': userAgent,
Referer: referer
}
});

if (response.status !== 200) {
const {status, headers} = response;
if (status !== 200) {
failed.add(name);
console.log(`Error: Status code: ${response.status}`);
console.log(`Error: Status code: ${status}: ${url}`);
console.log('');
continue;
}

const size = +response.headers.get('content-length');
const size = +headers.get('content-length');
const sized = pkg.size;
if (size !== sized) {
failed.add(name);
Expand Down
7 changes: 4 additions & 3 deletions bin/newest-harman-air-runtime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ async function main() {
const response = await fetch(source, {
'User-Agent': userAgent
});
if (response.status !== 200) {
const {status, headers} = response;
if (status !== 200) {
failed.add(name);
console.log(`Error: Status code: ${response.status}`);
console.log(`Error: Status code: ${status}: ${source}`);
console.log('');
continue;
}

const size = +response.headers.get('content-length');
const size = +headers.get('content-length');
if (size !== sized) {
failed.add(name);
console.log(`Error: Unexpected size: ${size} != ${sized}`);
Expand Down
7 changes: 4 additions & 3 deletions bin/newest-harman-air-sdk.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ async function main() {
Cookie: cookie
}
});
if (response.status !== 200) {
const {status, headers} = response;
if (status !== 200) {
failed.add(name);
console.log(`Error: Status code: ${response.status}`);
console.log(`Error: Status code: ${status}: ${source}`);
console.log('');
continue;
}

const size = +response.headers.get('content-length');
const size = +headers.get('content-length');
console.log(`Size: ${size}`);
if (!expected.has(name)) {
failed.add(name);
Expand Down
13 changes: 6 additions & 7 deletions bin/verify.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ function archiveOrgParse(url) {
const archiveOrgMetadataCache = {};
function archiveOrgMetadata(item) {
if (!archiveOrgMetadataCache[item]) {
archiveOrgMetadataCache[item] = fetch(
`https://archive.org/metadata/${encodeURI(item)}/`
).then(async response => {
const url = `https://archive.org/metadata/${encodeURI(item)}/`;
archiveOrgMetadataCache[item] = fetch(url).then(async response => {
const {status} = response;
if (status !== 200) {
throw new Error(`Unexpected status code: ${status}`);
throw new Error(`Status code: ${status}: ${url}`);
}
const body = await response.text();
const files = new Map();
Expand Down Expand Up @@ -75,12 +74,12 @@ async function getMetadataForUrl(url) {
}

const response = await fetch(url);
const {status} = response;
const {status, headers} = response;
if (status !== 200) {
throw new Error(`Unexpected status code: ${status}`);
throw new Error(`Status code: ${status}: ${url}`);
}
return {
size: +response.headers.get('content-length')
size: +headers.get('content-length')
};
}

Expand Down
9 changes: 5 additions & 4 deletions util/flashcn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async function listRelease() {
}
});
if (jsRes.status !== 200) {
throw new Error(`Unexpected status: ${jsRes.status}`);
throw new Error(`Status code: ${jsRes.status}: ${htmlUrl}`);
}
const versions = parseJsonP(await jsRes.text());
const r = [];
Expand Down Expand Up @@ -151,17 +151,18 @@ async function listDebug() {
}
});
if (htmlRes.status !== 200) {
throw new Error(`Unexpected status: ${htmlRes.status}`);
throw new Error(`Status code: ${htmlRes.status}: ${htmlUrl}`);
}
const html = await htmlRes.text();
const jsRes = await fetch('https://api.flash.cn/config/debugFlashVersion', {
const jsUrl = 'https://api.flash.cn/config/debugFlashVersion';
const jsRes = await fetch(jsUrl, {
headers: {
'User-Agent': userAgent,
Referer: htmlUrl
}
});
if (jsRes.status !== 200) {
throw new Error(`Unexpected status: ${jsRes.status}`);
throw new Error(`Status code: ${jsRes.status}: ${jsUrl}`);
}
const js = await jsRes.text();
const {version, date} = parseJsonV(js);
Expand Down
7 changes: 4 additions & 3 deletions util/gencache.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ export async function download(name, url, onprogress = null, headers = {}) {
let recievedLength = 0;

const response = await fetch(url, {headers});
if (response.status !== 200) {
throw new Error(`Bad status code: ${response.status}`);
const {status, headers: rheads} = response;
if (status !== 200) {
throw new Error(`Status code: ${status}: ${url}`);
}

onprogress(0);
const contentLength = +response.headers.get('content-length');
const contentLength = +rheads.get('content-length');
const body = Readable.fromWeb(response.body);
const p = pipe(body, createWriteStream(fileCacheTmp));
body.on('data', data => {
Expand Down
2 changes: 1 addition & 1 deletion util/harman-airsdk.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function list() {
'User-Agent': userAgent
});
if (response.status !== 200) {
throw new Error(`Unexpected status code: ${response.status}`);
throw new Error(`Status code: ${response.status}: ${apiUrl}`);
}
const data = JSON.parse(await response.text());
const cookies = [...response.headers]
Expand Down

0 comments on commit ee41263

Please sign in to comment.