Skip to content

Commit

Permalink
Proper decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed May 4, 2024
1 parent cca2510 commit fcbbfa1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
3 changes: 2 additions & 1 deletion util/flashcn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ async function listDebug() {
}

const html = await htmlRes.text();
const dom = new DOMParser().parseFromString(html, 'text/html');
const domParser = new DOMParser({errorHandler: {}});
const dom = domParser.parseFromString(html, 'text/html');
const hrefs = list(dom.getElementsByTagName('a'))
.map(a => new URL(a.getAttribute('href') || '', htmlUrl))
.filter(u => u.pathname.startsWith('/cdm/'));
Expand Down
22 changes: 9 additions & 13 deletions util/harman.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {retry} from './util.mjs';
import {DOMParser} from '@xmldom/xmldom';

import {list, retry} from './util.mjs';

// The API this page loads download list from.
// https://airsdk.harman.com/download
Expand Down Expand Up @@ -35,15 +37,6 @@ export function cookies(list) {
return list.map(c => c.split(';')[0]).join('; ');
}

function attrs(tag) {
const reg = /\s([a-z0-9-]+)(=("([^"]*)"|'([^']*)'|(\S*)))?/gi;
const attrs = {};
for (let m; (m = reg.exec(tag)); ) {
attrs[m[1]] = m[4] ?? m[5] ?? m[6] ?? null;
}
return attrs;
}

export async function sdks() {
const response = await retry(() =>
fetch(apiUrl, {
Expand Down Expand Up @@ -127,14 +120,17 @@ export async function runtimes() {
}

const html = await response.text();
const scripts = html.match(/<script[^>]*>/gi);
if (!scripts) {
const domParser = new DOMParser({errorHandler: {}});
const dom = domParser.parseFromString(html, 'text/html');
const scripts = list(dom.getElementsByTagName('script'));
if (!scripts.length) {
throw new Error(`No script tags: ${runtimeUrl}`);
}

let version = '';
let hashes = null;
for (const {src} of [...scripts].map(attrs).reverse()) {
for (const script of [...scripts].reverse()) {
const src = script.getAttribute('src');
if (!src) {
continue;
}
Expand Down

0 comments on commit fcbbfa1

Please sign in to comment.