⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
bug fix
daniel31x135bf90c56de94
diff --git a/components/Preservation/ReadableView.tsx b/components/Preservation/ReadableView.tsxindex 3c378dde..fd8eb701 100644--- a/components/Preservation/ReadableView.tsx+++ b/components/Preservation/ReadableView.tsx@@ -274,7 +274,15 @@ export default function ReadableView({ link }: Props) {selectionMenu.highlightId)}- className={`w-5 h-5 rounded-full bg-${color}-500 hover:opacity-70 duration-100 relative`}+ className={`w-5 h-5 rounded-full ${+ color === "yellow"+ ? "bg-yellow-300"+ : color === "red"+ ? "bg-red-500"+ : color === "blue"+ ? "bg-blue-500"+ : "bg-green-500"+ } hover:opacity-70 duration-100 relative`}title={`${color.charAt(0).toUpperCase() + color.slice(1)} Highlight`}diff --git a/lib/api/rssHandler.ts b/lib/api/rssHandler.tsnew file mode 100644index 00000000..2a8a71b6--- /dev/null+++ b/lib/api/rssHandler.ts@@ -0,0 +1,88 @@+import { RssSubscription } from "@prisma/client";+import { hasPassedLimit } from "./verifyCapacity";+import Parser from "rss-parser";+import { prisma } from "./db";++const rssHandler = async (rssSubscription: RssSubscription, parser: Parser) => {+ try {+ const feed = await parser.parseURL(rssSubscription.url);++ const feedLastPubDate =+ feed.lastBuildDate ??+ feed.items.reduce((acc, item) => {+ const itemPubDate = item.pubDate ? new Date(item.pubDate) : null;+ return itemPubDate && itemPubDate > acc ? itemPubDate : acc;+ }, new Date(0));++ if (!feedLastPubDate)+ throw new Error(+ `No lastBuildDate or pubDate found in the following RSS feed: ${rssSubscription.url}`+ );++ if (+ !rssSubscription.lastBuildDate ||+ (rssSubscription.lastBuildDate &&+ new Date(rssSubscription.lastBuildDate) < new Date(feedLastPubDate))+ ) {+ console.log(+ "\x1b[34m%s\x1b[0m",+ `Processing new RSS feed items for ${rssSubscription.name}`+ );++ const newItems = feed.items.filter((item) => {+ const itemPubDate = item.pubDate ? new Date(item.pubDate) : null;+ return itemPubDate && itemPubDate > rssSubscription.lastBuildDate!;+ });++ const hasTooManyLinks = await hasPassedLimit(+ rssSubscription.ownerId,+ newItems.length+ );++ if (hasTooManyLinks) {+ console.log(+ "\x1b[34m%s\x1b[0m",+ `User ${rssSubscription.ownerId} has too many links. Skipping new RSS feed items.`+ );+ return;+ }++ // Create all links concurrently+ await Promise.all(+ newItems.map(async (item) => {+ return prisma.link.create({+ data: {+ name: item.title,+ url: item.link,+ type: "link",+ createdBy: {+ connect: {+ id: rssSubscription.ownerId,+ },+ },+ collection: {+ connect: {+ id: rssSubscription.collectionId,+ },+ },+ },+ });+ })+ );++ // Update the lastBuildDate in the database+ await prisma.rssSubscription.update({+ where: { id: rssSubscription.id },+ data: { lastBuildDate: new Date(feedLastPubDate) },+ });+ }+ } catch (error) {+ console.error(+ "\x1b[34m%s\x1b[0m",+ `Error processing RSS feed ${rssSubscription.url}:`,+ error+ );+ }+};++export default rssHandler;diff --git a/pages/api/v1/rss/index.ts b/pages/api/v1/rss/index.tsindex 1a4ea6fe..f4efa10f 100644--- a/pages/api/v1/rss/index.ts+++ b/pages/api/v1/rss/index.ts@@ -1,8 +1,10 @@import { prisma } from "@/lib/api/db";+import rssHandler from "@/lib/api/rssHandler";import setCollection from "@/lib/api/setCollection";import verifyUser from "@/lib/api/verifyUser";import { PostRssSubscriptionSchema } from "@/lib/shared/schemaValidation";import { NextApiRequest, NextApiResponse } from "next";+import Parser from "rss-parser";export default async function handler(req: NextApiRequest,@@ -76,10 +78,9 @@ export default async function handler(});if (existingRssSubscription) {- return {- response: "RSS Subscription with that name already exists.",- status: 400,- };+ return res+ .status(400)+ .json({ response: "RSS Subscription with that name already exists" });}const response = await prisma.rssSubscription.create({@@ -87,7 +88,6 @@ export default async function handler(name,url,ownerId: user.id,- lastBuildDate: new Date(),collection: {connect: {id: linkCollection.id,@@ -96,6 +96,10 @@ export default async function handler(},});+ const parser = new Parser();++ await rssHandler(response, parser);+return res.status(200).json({ response });}}diff --git a/scripts/worker.ts b/scripts/worker.tsindex b14e4b18..c0087777 100644--- a/scripts/worker.ts+++ b/scripts/worker.ts@@ -6,6 +6,7 @@ import { hasPassedLimit } from "../lib/api/verifyCapacity";import { LinkWithCollectionOwnerAndTags } from "../types/global";import getLinkBatch from "../lib/api/getLinkBatch";import { meiliClient } from "../lib/api/meilisearchClient";+import rssHandler from "../lib/api/rssHandler";const archiveTakeCount = Number(process.env.ARCHIVE_TAKE_COUNT || "") || 5;const indexTakeCount = Number(process.env.INDEX_TAKE_COUNT || "") || 50;@@ -21,79 +22,12 @@ async function startRSSPolling() {console.log("\x1b[34m%s\x1b[0m", "Starting RSS polling...");while (true) {const rssSubscriptions = await prisma.rssSubscription.findMany({});+const parser = new Parser();await Promise.all(rssSubscriptions.map(async (rssSubscription) => {- try {- const feed = await parser.parseURL(rssSubscription.url);-- if (- rssSubscription.lastBuildDate &&- new Date(rssSubscription.lastBuildDate) <- new Date(feed.lastBuildDate)- ) {- console.log(- "\x1b[34m%s\x1b[0m",- `Processing new RSS feed items for ${rssSubscription.name}`- );-- const newItems = feed.items.filter((item) => {- const itemPubDate = item.pubDate ? new Date(item.pubDate) : null;- return (- itemPubDate && itemPubDate > rssSubscription.lastBuildDate!- );- });-- const hasTooManyLinks = await hasPassedLimit(- rssSubscription.ownerId,- newItems.length- );-- if (hasTooManyLinks) {- console.log(- "\x1b[34m%s\x1b[0m",- `User ${rssSubscription.ownerId} has too many links. Skipping new RSS feed items.`- );- return;- }-- // Create all links concurrently- await Promise.all(- newItems.map(async (item) => {- return prisma.link.create({- data: {- name: item.title,- url: item.link,- type: "link",- createdBy: {- connect: {- id: rssSubscription.ownerId,- },- },- collection: {- connect: {- id: rssSubscription.collectionId,- },- },- },- });- })- );-- // Update the lastBuildDate in the database- await prisma.rssSubscription.update({- where: { id: rssSubscription.id },- data: { lastBuildDate: new Date(feed.lastBuildDate) },- });- }- } catch (error) {- console.error(- "\x1b[34m%s\x1b[0m",- `Error processing RSS feed ${rssSubscription.url}:`,- error- );- }+ rssHandler(rssSubscription, parser);}));await delay(pollingIntervalInSeconds);