Skip to content

Commit

Permalink
Fix subscribing some more.
Browse files Browse the repository at this point in the history
  • Loading branch information
lwindolf committed Jun 17, 2024
1 parent 65477e7 commit d934aec
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
9 changes: 2 additions & 7 deletions tests/autodiscovery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,9 @@ test("Link auto discover: slashdot", () => {
<html lang="en">
<head>
<!-- Render IE9 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="top" title="News for nerds, stuff that matters" href="//slashdot.org/" >
<link rel="search" title="Search Slashdot" href="//slashdot.org/search.pl">
<body>
<link rel="alternate" title="Slashdot RSS" href="https://rss.slashdot.org/Slashdot/slashdotMain" type="application/rss+xml">
</head>
</body>
</html>`;

let links = linkAutoDiscover(str, 'https://slashdot.org');
Expand Down
2 changes: 2 additions & 0 deletions www/assets/js/dialogs/simpleSubscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class SimpleSubscriptionDialog extends Dialog {
if(-1 == result.url.indexOf('://'))
result.url = 'https://' + result.url;

console.info(`Trying to subscribe to ${result.url}`);

// Fetch content the URL points to
try {
str = await fetch(result.url).then((response) => response.text());
Expand Down
11 changes: 2 additions & 9 deletions www/assets/js/feedupdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,12 @@ import { parserAutoDiscover } from './parsers/autodiscover.js';
import { Favicon } from './parsers/favicon.js';
import { Feed } from './feed.js';

// FIXME: drop this hard-coded proxy
const proxy = 'https://corsproxy-1516.lars-windolf.workers.dev/corsproxy/?apiurl=';

export class FeedUpdater {
// returns a feed properties or at least error code (e.g. "{ error: Feed.ERROR_XML }")
// result should be merged into the feed being updated
static async fetch(url) {
// Inject proxy on non-Phonegap environment
let fetchURL = url;
if(document.location.protocol !== 'file:')
fetchURL = proxy + url;

var feed = await fetch(fetchURL)
console.info(`Updating ${url}`);
var feed = await fetch(url)
.then((response) => {
// FIXME: proper network state handling
return response.text()
Expand Down
4 changes: 2 additions & 2 deletions www/assets/js/itemview.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class ItemView {
{{#each item.media}}
{{#contains 'audio' this.type }}
<audio controls preload='none' src='{{ this.url }}'></audio>
{{/end}}
{{/end}}
{{/contains}}
{{/each}}
`);

// load content of a single item
Expand Down
8 changes: 6 additions & 2 deletions www/assets/js/parsers/autodiscover.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ function parserAutoDiscover(str) {
const parser = new DOMParser();
const doc = parser.parseFromString(str, 'application/xml');

console.info(`auto discover`)
for (let i = 0; i < parsers.length; i++) {
for (let j = 0; j < parsers[i].autoDiscover.length; j++) {
try {
if (XPath.lookup(doc.firstChild, parsers[i].autoDiscover[j]))
if (XPath.lookup(doc.firstChild, parsers[i].autoDiscover[j])) {
console.info(`... discovered to be ${parsers[i].id}!`);
return parsers[i];
}
} catch(e) {
// ignore
}
console.info(`... is not ${parsers[i].id}`);
}
}
return undefined;
Expand Down Expand Up @@ -52,7 +56,7 @@ function linkAutoDiscover(str, baseURL) {

let results = [];
XPath.foreach(root,
"/html/head/link[@rel='alternate'][@type='application/atom+xml' or @type='application/rss+xml' or @type='application/rdf+xml' or @type='text/xml']",
"//link[@rel='alternate'][@type='application/atom+xml' or @type='application/rss+xml' or @type='application/rdf+xml' or @type='text/xml']",
(node) => {
let href = XPath.lookup(node, '@href');
if (!href.includes("://")) {
Expand Down

0 comments on commit d934aec

Please sign in to comment.