⚡️⚡️⚡️ 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
improvements
daniel31x13c148c2b953cb
diff --git a/.env.sample b/.env.sampleindex b8f21664..94b93e51 100644--- a/.env.sample+++ b/.env.sample@@ -37,6 +37,8 @@ IMPORT_LIMIT=PLAYWRIGHT_LAUNCH_OPTIONS_EXECUTABLE_PATH=MAX_WORKERS=DISABLE_PRESERVATION=+NEXT_PUBLIC_RSS_POLLING_INTERVAL_MINUTES=+RSS_SUBSCRIPTION_LIMIT_PER_USER=# AWS S3 SettingsSPACES_KEY=diff --git a/components/ModalContent/NewRssSubscriptionModal.tsx b/components/ModalContent/NewRssSubscriptionModal.tsxindex 45df8065..90e8a280 100644--- a/components/ModalContent/NewRssSubscriptionModal.tsx+++ b/components/ModalContent/NewRssSubscriptionModal.tsx@@ -25,6 +25,10 @@ export default function NewRssSubscriptionModal({ onClose }: Props) {const submit = async () => {if (submitLoader) return;+ if (!form.name || !form.url || !form.collectionId) {+ return toast.error(t("fill_all_fields"));+ }+setSubmitLoader(true);const load = toast.loading(t("creating"));@@ -55,33 +59,35 @@ export default function NewRssSubscriptionModal({ onClose }: Props) {<label>{t("name")}</label><TextInputtype="text"+ placeholder="Sample RSS"className="bg-base-200 mt-2"value={form.name}onChange={(e) => setForm({ ...form, name: e.target.value })}/></div><div className="w-full">- <label>{t("link")}</label>- <TextInput- type="text"- className="bg-base-200 mt-2"- value={form.url}- onChange={(e) => setForm({ ...form, url: e.target.value })}+ <label>{t("collection")}</label>+ <CollectionSelection+ className="mt-2"+ onChange={(e: any) => {+ if (e?.__isNew__) e.value = undefined;+ setForm({+ ...form,+ collectionId: e?.value,+ collectionName: e?.label,+ });+ }}/></div></div><div className="w-full mt-3">- <label>{t("collection")}</label>- <CollectionSelection- className="mt-2"- onChange={(e: any) => {- if (e?.__isNew__) e.value = undefined;- setForm({- ...form,- collectionId: e?.value,- collectionName: e?.label,- });- }}+ <label>{t("link")}</label>+ <TextInput+ type="text"+ placeholder="https://example.com/rss"+ className="bg-base-200 mt-2"+ value={form.url}+ onChange={(e) => setForm({ ...form, url: e.target.value })}/></div><div className="flex justify-end items-center mt-5">diff --git a/components/SettingsSidebar.tsx b/components/SettingsSidebar.tsxindex 5707f798..d4eb6fad 100644--- a/components/SettingsSidebar.tsx+++ b/components/SettingsSidebar.tsx@@ -98,7 +98,7 @@ export default function SettingsSidebar({ className }: { className?: string }) {: "hover:bg-neutral/20"} duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}>- <i className="bi-credit-card text-primary text-xl"></i>+ <i className="bi-credit-card text-primary text-2xl"></i><p className="truncate w-full pr-7">{t("billing")}</p></div></Link>@@ -117,7 +117,7 @@ export default function SettingsSidebar({ className }: { className?: string }) {<divclassName={`hover:bg-neutral/20 duration-100 py-2 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}>- <i className="bi-question-circle text-primary text-xl"></i>+ <i className="bi-question-circle text-primary text-2xl"></i><p className="truncate w-full pr-7">{t("help")}</p></div></Link>@@ -125,7 +125,7 @@ export default function SettingsSidebar({ className }: { className?: string }) {<divclassName={`hover:bg-neutral/20 duration-100 py-2 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}>- <i className="bi-github text-primary text-xl"></i>+ <i className="bi-github text-primary text-2xl"></i><p className="truncate w-full pr-7">{t("github")}</p></div></Link>@@ -133,7 +133,7 @@ export default function SettingsSidebar({ className }: { className?: string }) {<divclassName={`hover:bg-neutral/20 duration-100 py-2 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}>- <i className="bi-twitter-x text-primary text-xl"></i>+ <i className="bi-twitter-x text-primary text-2xl"></i><p className="truncate w-full pr-7">{t("twitter")}</p></div></Link>@@ -141,7 +141,7 @@ export default function SettingsSidebar({ className }: { className?: string }) {<divclassName={`hover:bg-neutral/20 duration-100 py-2 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}>- <i className="bi-mastodon text-primary text-xl"></i>+ <i className="bi-mastodon text-primary text-2xl"></i><p className="truncate w-full pr-7">{t("mastodon")}</p></div></Link>diff --git a/hooks/store/rss.tsx b/hooks/store/rss.tsxindex 8ac15153..c420c1ce 100644--- a/hooks/store/rss.tsx+++ b/hooks/store/rss.tsx@@ -43,10 +43,7 @@ const useAddRssSubscription = () => {return data.response;},onSuccess: (data) => {- queryClient.setQueryData(- ["rss-subscriptions"],- (oldData: RssSubscription[]) => [...oldData, data]- );+ queryClient.invalidateQueries({ queryKey: ["rss-subscriptions"] });},});};@@ -63,15 +60,8 @@ const useDeleteRssSubscription = () => {const data = await response.json();if (!response.ok) throw new Error(data.response);},- onSuccess: (_, rssSubscriptionId) => {- queryClient.setQueryData(- ["rss-subscriptions"],- (oldData: RssSubscription[]) => {- return oldData.filter(- (rssSubscription) => rssSubscription.id !== rssSubscriptionId- );- }- );+ onSuccess: () => {+ queryClient.invalidateQueries({ queryKey: ["rss-subscriptions"] });},});};diff --git a/lib/api/controllers/links/postLink.ts b/lib/api/controllers/links/postLink.tsindex 830ac324..3159ca64 100644--- a/lib/api/controllers/links/postLink.ts+++ b/lib/api/controllers/links/postLink.ts@@ -2,7 +2,6 @@ import { prisma } from "@/lib/api/db";import fetchTitleAndHeaders from "@/lib/shared/fetchTitleAndHeaders";import createFolder from "@/lib/api/storage/createFolder";import setCollection from "../../setCollection";-import {PostLinkSchema,PostLinkSchemaType,diff --git a/lib/api/controllers/migration/exportData.ts b/lib/api/controllers/migration/exportData.tsindex 917406c3..9229003e 100644--- a/lib/api/controllers/migration/exportData.ts+++ b/lib/api/controllers/migration/exportData.ts@@ -6,6 +6,7 @@ export default async function exportData(userId: number) {include: {collections: {include: {+ rssSubscriptions: true,links: {include: {tags: true,diff --git a/lib/shared/schemaValidation.ts b/lib/shared/schemaValidation.tsindex 7cc94853..f655ff8c 100644--- a/lib/shared/schemaValidation.ts+++ b/lib/shared/schemaValidation.ts@@ -211,8 +211,8 @@ export const UpdateTagSchema = z.object({export type UpdateTagSchemaType = z.infer<typeof UpdateTagSchema>;export const PostRssSubscriptionSchema = z.object({- name: z.string(),- url: z.string().url(),+ name: z.string().max(50),+ url: z.string().url().max(2048),collectionId: z.number().optional(),- collectionName: z.string().optional(),+ collectionName: z.string().max(50).optional(),});diff --git a/pages/api/v1/user/rss/index.ts b/pages/api/v1/user/rss/index.tsindex 05a676f9..fadd99ca 100644--- a/pages/api/v1/user/rss/index.ts+++ b/pages/api/v1/user/rss/index.ts@@ -1,9 +1,7 @@import { prisma } from "@/lib/api/db";-import getPermission from "@/lib/api/getPermission";import setCollection from "@/lib/api/setCollection";import verifyUser from "@/lib/api/verifyUser";import { PostRssSubscriptionSchema } from "@/lib/shared/schemaValidation";-import { UsersAndCollections } from "@prisma/client";import { NextApiRequest, NextApiResponse } from "next";export default async function handler(@@ -38,6 +36,21 @@ export default async function handler(});}+ const rssSubscriptionCount = await prisma.rssSubscription.count({+ where: {+ ownerId: user.id,+ },+ });++ const RSS_SUBSCRIPTION_LIMIT_PER_USER =+ Number(process.env.RSS_SUBSCRIPTION_LIMIT_PER_USER) || 20;++ if (rssSubscriptionCount >= 10) {+ return res.status(403).json({+ response: `You have reached the limit of ${RSS_SUBSCRIPTION_LIMIT_PER_USER} RSS subscriptions.`,+ });+ }+const { name, url, collectionId, collectionName } = dataValidation.data;const linkCollection = await setCollection({diff --git a/pages/settings/rss-subscriptions.tsx b/pages/settings/rss-subscriptions.tsxindex ad382a0b..34b1940f 100644--- a/pages/settings/rss-subscriptions.tsx+++ b/pages/settings/rss-subscriptions.tsx@@ -30,7 +30,11 @@ export default function RssSubscriptions() {<div className="divider my-3"></div><div className="flex flex-col gap-3">- <p>{t("rss_subscriptions_desc")}</p>+ <p>+ {t("rss_subscriptions_desc", {+ number: process.env.NEXT_PUBLIC_RSS_POLLING_INTERVAL_MINUTES || 60,+ })}+ </p><buttonclassName={`btn ml-auto btn-accent dark:border-violet-400 text-white tracking-wider w-fit flex items-center gap-2`}@@ -55,14 +59,7 @@ export default function RssSubscriptions() {<tr key={i}><td>{rssSubscription.name}</td><td>{rssSubscription.url}</td>- <td>- <Link- className="hover:underline"- href={`/collections/${rssSubscription.collectionId}`}- >- {rssSubscription.collection.name}- </Link>- </td>+ <td>{rssSubscription.collection.name}</td><td><buttonclassName="btn btn-sm btn-ghost btn-square hover:bg-red-500"diff --git a/public/locales/en/common.json b/public/locales/en/common.jsonindex d1038f21..118aa7fb 100644--- a/public/locales/en/common.json+++ b/public/locales/en/common.json@@ -431,7 +431,7 @@"people_recommendation": "Recommendation (Friend, Family, etc.)","open_all_links": "Open all Links","rss_subscriptions": "RSS Subscriptions",- "rss_subscriptions_desc": "RSS Subscriptions are a way to keep up with your favorite websites and blogs. Linkwarden will automatically fetch the latest articles from the feeds you provide.",+ "rss_subscriptions_desc": "RSS Subscriptions are a way to keep up with your favorite websites and blogs. Linkwarden will automatically fetch the latest articles every {{number}} minutes from the feeds you provide.","rss_deletion_confirmation": "Are you sure you want to delete this RSS Subscription?","new_rss_subscription": "New RSS Subscription","rss_subscription_deleted": "RSS Subscription deleted!",diff --git a/scripts/worker.ts b/scripts/worker.tsindex 121ad48c..d0535aa1 100644--- a/scripts/worker.ts+++ b/scripts/worker.ts@@ -3,6 +3,7 @@ import { Collection, Link, User } from "@prisma/client";import { prisma } from "../lib/api/db";import archiveHandler from "../lib/api/archiveHandler";import Parser from "rss-parser";+import { hasPassedLimit } from "../lib/api/verifyCapacity";const args = process.argv.slice(2).join(" ");@@ -158,6 +159,19 @@ async function fetchAndProcessRSS() {return itemPubDate && itemPubDate > rssSubscription.lastBuildDate!; // We know lastBuildDate is not null here});+ 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;+ }+newItems.forEach(async (item) => {await prisma.link.create({data: {@@ -198,13 +212,12 @@ function delay(sec: number) {return new Promise((resolve) => setTimeout(resolve, sec * 1000));}-const POLLING_INTERVAL_MINUTES =- Number(process.env.RSS_POLLING_INTERVAL_MINUTES) || 60; // Default to one hour if not set-const pollingIntervalInSeconds = POLLING_INTERVAL_MINUTES * 60;+const pollingIntervalInSeconds =+ (Number(process.env.NEXT_PUBLIC_RSS_POLLING_INTERVAL_MINUTES) || 60) * 60; // Default to one hour if not setasync function startRSSPolling() {+ console.log("\x1b[34m%s\x1b[0m", "Starting RSS polling...");while (true) {- console.log("\x1b[34m%s\x1b[0m", "Starting RSS polling...");await fetchAndProcessRSS();await delay(pollingIntervalInSeconds);}@@ -214,8 +227,8 @@ const archiveIntervalInSeconds =Number(process.env.ARCHIVE_SCRIPT_INTERVAL) || 10;async function startArchiveProcessing() {+ console.log("\x1b[34m%s\x1b[0m", "Starting link preservation...");while (true) {- console.log("\x1b[34m%s\x1b[0m", "Starting archive processing...");await processBatch();await delay(archiveIntervalInSeconds);}