Skip to content

Commit

Permalink
added enclosures
Browse files Browse the repository at this point in the history
  • Loading branch information
TBosak committed Jan 10, 2025
1 parent e4bc226 commit 643a647
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 366 deletions.
2 changes: 1 addition & 1 deletion adapters/adapter.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import ApiConfig from "../models/apiconfig.model";
export default interface IAdapter {
config: ApiConfig;
fetchData(param?: string): Promise<string>;
buildRSS(res: string): string;
buildRSS(res: string): Promise<string>;
}
2 changes: 1 addition & 1 deletion adapters/base.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export abstract class BaseAdapter implements IAdapter {
}

abstract fetchData(param?: string): Promise<string>;
abstract buildRSS(res: string): string;
abstract buildRSS(res: string): Promise<string>;
}
14 changes: 3 additions & 11 deletions adapters/scraping.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class WebScrapingAdapter extends BaseAdapter {
description?: CSSTarget;
link?: CSSTarget;
date?: CSSTarget;
enclosure?: CSSTarget;
};
timestamp?: boolean;
reverse?: boolean;
Expand Down Expand Up @@ -40,16 +41,7 @@ export class WebScrapingAdapter extends BaseAdapter {
}
}

buildRSS(res: string): string {
return buildRSS(
res,
this.article,
undefined,
undefined,
undefined,
undefined,
this.timestamp,
this.reverse
);
buildRSS(res: string): Promise<string> {
return buildRSS(res, this.config, this.article, this.reverse);
}
}
Binary file modified bun.lockb
Binary file not shown.
28 changes: 23 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ app.post("/", async (ctx) => {
false,
extractValue("linkIterator")
);
const enclosureTarget = new CSSTarget(
extractValue("enclosureSelector"),
extractValue("enclosureAttribute") || undefined,
false,
extractValue("enclosureBaseUrl"),
extractValue("enclosureRelativeLink") === "on" ||
extractValue("enclosureRelativeLink") === true,
false,
extractValue("enclosureIterator")
);
const dateTarget = new CSSTarget(
extractValue("dateSelector"),
extractValue("dateAttribute") || undefined,
Expand All @@ -188,6 +198,7 @@ app.post("/", async (ctx) => {
title: titleTarget,
description: descriptionTarget,
link: linkTarget,
enclosure: enclosureTarget,
date: dateTarget,
headers: headers,
};
Expand Down Expand Up @@ -318,6 +329,16 @@ app.post("/preview", async (ctx) => {
false,
extractValue("linkIterator")
);
const enclosureTarget = new CSSTarget(
extractValue("enclosureSelector"),
extractValue("enclosureAttribute") || undefined,
false,
extractValue("enclosureBaseUrl"),
extractValue("enclosureRelativeLink") === "on" ||
extractValue("enclosureRelativeLink") === true,
false,
extractValue("enclosureIterator")
);
const dateTarget = new CSSTarget(
extractValue("dateSelector"),
extractValue("dateAttribute") || undefined,
Expand Down Expand Up @@ -347,6 +368,7 @@ app.post("/preview", async (ctx) => {
link: linkTarget,
author: authorTarget,
date: dateTarget,
enclosure: enclosureTarget,
};
} else if (feedType === "api") {
// API configuration
Expand Down Expand Up @@ -669,14 +691,10 @@ async function generatePreview(feedConfig: any) {
: await axios.get(feedConfig.config.baseUrl);
const html = response.data;
// Generate the RSS feed using your buildRSS function
rssXml = buildRSS(
rssXml = await buildRSS(
html,
feedConfig.config,
feedConfig.article,
undefined,
undefined,
undefined,
undefined,
feedConfig.reverse
);
} else if (feedConfig.feedType === "api") {
Expand Down
13 changes: 10 additions & 3 deletions models/csstarget.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
export default class CSSTarget {
constructor(public selector: string, public attribute?: string, public stripHtml?: boolean,
public rootUrl?: string, public relativeLink?: boolean, public titleCase?: boolean, public iterator?: string) { }
}
constructor(
public selector: string,
public attribute?: string,
public stripHtml?: boolean,
public rootUrl?: string,
public relativeLink?: boolean,
public titleCase?: boolean,
public iterator?: string
) {}
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
"start": "bun run index.ts --watch --passkey=admin123 --cookieSecret=a18c1fd2211edd76"
},
"dependencies": {
"@types/bun": "^1.1.12",
"@types/cheerio": "0.22.31",
"@types/xml": "1.0.8",
"axios": "^1.7.7",
"bun": "^1.1.33",
"bun-types": "^0.1.0",
Expand All @@ -22,5 +19,10 @@
"rss": "1.2.2",
"uuid": "^11.0.2",
"xmldom": "^0.6.0"
},
"devDependencies": {
"@types/bun": "^1.1.12",
"@types/cheerio": "0.22.31",
"@types/xml": "1.0.8"
}
}
55 changes: 55 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,45 @@ <h3>CSS Selectors for RSS Feed Items</h3>
id="linkBaseUrl" />
</details>
<br /><br />
<details>
<summary>Enclosure (Image, Video, Etc.)</summary>
<label for="enclosureSelector">Enclosure Selector:</label>
<input
type="text"
name="enclosureSelector"
id="enclosureSelector" /><br /><br />
<label for="enclosureAttribute">Enclosure Attribute:</label>
<input
type="text"
name="enclosureAttribute"
id="enclosureAttribute" /><br /><br />
<label for="enclosureIterator"
>Enclosure Parent Iterator (optional):</label
>
<input
type="text"
name="enclosureIterator"
id="enclosureIterator" /><br /><br />
<label>
<input
type="checkbox"
name="enclosureRelativeLink"
id="enclosureRelativeLink" />
Relative Link? </label
><br /><br />
<label
style="display: none"
id="enclosureBaseUrlLabel"
for="enclosureBaseUrl"
>Base URL:</label
>
<input
style="display: none"
type="text"
name="enclosureBaseUrl"
id="enclosureBaseUrl" />
</details>
<br /><br />
<details>
<summary>Author</summary>
<label for="authorSelector">Author Selector:</label>
Expand Down Expand Up @@ -387,6 +426,22 @@ <h3>API Response Mapping</h3>
}
});

document
.getElementById("enclosureRelativeLink")
.addEventListener("change", function () {
if (this.checked) {
document.getElementById("enclosureBaseUrl").style.display =
"block";
document.getElementById("enclosureBaseUrlLabel").style.display =
"block";
} else {
document.getElementById("enclosureBaseUrl").style.display =
"none";
document.getElementById("enclosureBaseUrlLabel").style.display =
"none";
}
});

feedTypeSelect.addEventListener("change", function () {
if (this.value === "webScraping") {
webScrapingFields.style.display = "block";
Expand Down
Loading

0 comments on commit 643a647

Please sign in to comment.