⚡️⚡️⚡️ 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
remove whitelist and isPrivate due to low demand and high overhead
daniel31x13686e3b44e159
diff --git a/apps/web/lib/api/controllers/migration/exportData.ts b/apps/web/lib/api/controllers/migration/exportData.tsindex be0ca7b3..5df93c43 100644--- a/apps/web/lib/api/controllers/migration/exportData.ts+++ b/apps/web/lib/api/controllers/migration/exportData.ts@@ -23,7 +23,6 @@ export default async function exportData(userId: number) {},},pinnedLinks: true,- whitelistedUsers: true,},});diff --git a/apps/web/lib/api/controllers/public/users/getPublicUser.ts b/apps/web/lib/api/controllers/public/users/getPublicUser.tsindex adbfb5c7..8c140735 100644--- a/apps/web/lib/api/controllers/public/users/getPublicUser.ts+++ b/apps/web/lib/api/controllers/public/users/getPublicUser.ts@@ -2,8 +2,7 @@ import { prisma } from "@linkwarden/prisma";export default async function getPublicUser(targetId: number | string,- isId: boolean,- requestingId?: number+ isId: boolean) {const user = await prisma.user.findFirst({where: isId@@ -20,59 +19,9 @@ export default async function getPublicUser(},],},- include: {- whitelistedUsers: {- select: {- username: true,- },- },- },- });-- if (!user || !user.id)- return { response: "User not found or profile is private.", status: 404 };-- const whitelistedUsernames = user.whitelistedUsers?.map(- (usernames) => usernames.username- );-- const isInAPublicCollection = await prisma.collection.findFirst({- where: {- OR: [- { ownerId: user.id },- {- members: {- some: {- userId: user.id,- },- },- },- ],- isPublic: true,- },});- if (user?.isPrivate && !isInAPublicCollection) {- if (requestingId) {- const requestingUser = await prisma.user.findUnique({- where: { id: requestingId },- });-- if (- requestingUser?.id !== requestingId &&- (!requestingUser?.username ||- !whitelistedUsernames.includes(- requestingUser.username?.toLowerCase()- ))- ) {- return {- response: "User not found or profile is private.",- status: 404,- };- }- } else- return { response: "User not found or profile is private.", status: 404 };- }+ if (!user || !user.id) return { response: "User not found.", status: 404 };const { password, ...lessSensitiveInfo } = user;diff --git a/apps/web/lib/api/controllers/users/userId/getUserById.ts b/apps/web/lib/api/controllers/users/userId/getUserById.tsindex 1ca6ec96..6d4cb45e 100644--- a/apps/web/lib/api/controllers/users/userId/getUserById.ts+++ b/apps/web/lib/api/controllers/users/userId/getUserById.ts@@ -14,7 +14,6 @@ type GetUserByIdResponse = Omit<User, "password"> &};};} & {- whitelistedUsers: string[];dashboardSections: DashboardSection[];};@@ -24,11 +23,6 @@ export default async function getUserById(userId: number) {id: userId,},include: {- whitelistedUsers: {- select: {- username: true,- },- },subscriptions: true,parentSubscription: {include: {@@ -39,19 +33,13 @@ export default async function getUserById(userId: number) {},});- if (!user)- return { response: "User not found or profile is private.", status: 404 };-- const whitelistedUsernames = user.whitelistedUsers?.map(- (usernames) => usernames.username- );+ if (!user) return { response: "User not found.", status: 404 };const { password, subscriptions, parentSubscription, ...lessSensitiveInfo } =user;const data: GetUserByIdResponse = {...lessSensitiveInfo,- whitelistedUsers: whitelistedUsernames,subscription: {active: subscriptions?.active ?? false,quantity: subscriptions?.quantity ?? 0,diff --git a/apps/web/lib/api/controllers/users/userId/updateUserById.ts b/apps/web/lib/api/controllers/users/userId/updateUserById.tsindex 9896eb7b..abc82ea1 100644--- a/apps/web/lib/api/controllers/users/userId/updateUserById.ts+++ b/apps/web/lib/api/controllers/users/userId/updateUserById.ts@@ -189,7 +189,6 @@ export default async function updateUserById(data: {name: data.name,username: data.username,- isPrivate: data.isPrivate,image:data.image && data.image.startsWith("http")? data.image@@ -218,7 +217,6 @@ export default async function updateUserById(: undefined,},include: {- whitelistedUsers: true,subscriptions: true,dashboardSections: true,parentSubscription: {@@ -230,7 +228,6 @@ export default async function updateUserById(});const {- whitelistedUsers,password,subscriptions,dashboardSections,@@ -238,48 +235,8 @@ export default async function updateUserById(...userInfo} = updatedUser;- // If user.whitelistedUsers is not provided, we will assume the whitelistedUsers should be removed- const newWhitelistedUsernames: string[] = data.whitelistedUsers || [];-- // Get the current whitelisted usernames- const currentWhitelistedUsernames: string[] = whitelistedUsers.map(- (data) => data.username- );-- // Find the usernames to be deleted (present in current but not in new)- const usernamesToDelete: string[] = currentWhitelistedUsernames.filter(- (username) => !newWhitelistedUsernames.includes(username)- );-- // Find the usernames to be created (present in new but not in current)- const usernamesToCreate: string[] = newWhitelistedUsernames.filter(- (username) =>- !currentWhitelistedUsernames.includes(username) && username.trim() !== ""- );-- // Delete whitelistedUsers that are not present in the new list- await prisma.whitelistedUser.deleteMany({- where: {- userId: userId,- username: {- in: usernamesToDelete,- },- },- });-- // Create new whitelistedUsers that are not in the current list, no create many ;(- for (const username of usernamesToCreate) {- await prisma.whitelistedUser.create({- data: {- username,- userId: userId,- },- });- }-const response = {...userInfo,- whitelistedUsers: newWhitelistedUsernames,image: userInfo.image ? `${userInfo.image}?${Date.now()}` : "",subscription: {active: subscriptions?.active,diff --git a/apps/web/lib/api/controllers/users/userId/updateUserPreference.ts b/apps/web/lib/api/controllers/users/userId/updateUserPreference.tsindex 97a3454c..1ade267d 100644--- a/apps/web/lib/api/controllers/users/userId/updateUserPreference.ts+++ b/apps/web/lib/api/controllers/users/userId/updateUserPreference.ts@@ -33,7 +33,6 @@ export default async function updateUserPreference(readableLineWidth: data.readableLineWidth,},include: {- whitelistedUsers: true,subscriptions: true,dashboardSections: true,parentSubscription: {@@ -44,19 +43,13 @@ export default async function updateUserPreference(},});- if (!updatedUser)- return { response: "User not found or profile is private.", status: 404 };-- const whitelistedUsernames = updatedUser.whitelistedUsers?.map(- (usernames) => usernames.username- );+ if (!updatedUser) return { response: "User not found.", status: 404 };const { password, subscriptions, parentSubscription, ...lessSensitiveInfo } =updatedUser;const response = {...lessSensitiveInfo,- whitelistedUsers: whitelistedUsernames,subscription: {active: subscriptions?.active,quantity: subscriptions?.quantity,diff --git a/apps/web/lib/api/paymentCheckout.ts b/apps/web/lib/api/paymentCheckout.tsindex 643f8506..9cf0a2db 100644--- a/apps/web/lib/api/paymentCheckout.ts+++ b/apps/web/lib/api/paymentCheckout.ts@@ -21,7 +21,7 @@ export default async function paymentCheckout(email: string, priceId: string) {});if (!user) {- return { response: "User not found", status: 404 };+ return { response: "User not found.", status: 404 };}const trialEndTime =diff --git a/apps/web/lib/api/stripe/handleSubscription.ts b/apps/web/lib/api/stripe/handleSubscription.tsindex c62dc08f..4e6f1f10 100644--- a/apps/web/lib/api/stripe/handleSubscription.ts+++ b/apps/web/lib/api/stripe/handleSubscription.ts@@ -60,9 +60,9 @@ export default async function handleSubscription({if (!user) {if (action === "customer.subscription.deleted") {- return "User not found or deleted";+ return "User not found or deleted.";} else {- throw new Error("User not found");+ throw new Error("User not found.");}}diff --git a/apps/web/pages/api/v1/avatar/[id].ts b/apps/web/pages/api/v1/avatar/[id].tsindex 47b255b7..4cdb6358 100644--- a/apps/web/pages/api/v1/avatar/[id].ts+++ b/apps/web/pages/api/v1/avatar/[id].ts@@ -20,9 +20,6 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {where: {id: queryId,},- include: {- whitelistedUsers: true,- },});if (!targetUser) {@@ -32,62 +29,6 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {.send("File inaccessible.");}- const isInAPublicCollection = await prisma.collection.findFirst({- where: {- ["OR"]: [- { ownerId: targetUser.id },- {- members: {- some: {- userId: targetUser.id,- },- },- },- ],- isPublic: true,- },- });-- if (targetUser?.isPrivate && !isInAPublicCollection) {- if (!userId) {- return res- .setHeader("Content-Type", "text/plain")- .status(400)- .send("File inaccessible.");- }-- const user = await prisma.user.findUnique({- where: {- id: userId,- },- include: {- subscriptions: true,- },- });-- const whitelistedUsernames = targetUser?.whitelistedUsers.map(- (whitelistedUsername) => whitelistedUsername.username- );-- if (!user?.username) {- return res- .setHeader("Content-Type", "text/plain")- .status(400)- .send("File inaccessible.");- }-- if (- user.username &&- !whitelistedUsernames?.includes(user.username) &&- targetUser.id !== user.id- ) {- return res- .setHeader("Content-Type", "text/plain")- .status(400)- .send("File inaccessible.");- }- }-const { file, contentType, status } = await readFile(`uploads/avatar/${queryId}.jpg`);diff --git a/apps/web/pages/api/v1/public/users/[id].ts b/apps/web/pages/api/v1/public/users/[id].tsindex f34671da..95fd8745 100644--- a/apps/web/pages/api/v1/public/users/[id].ts+++ b/apps/web/pages/api/v1/public/users/[id].ts@@ -1,18 +1,14 @@import type { NextApiRequest, NextApiResponse } from "next";import getPublicUser from "@/lib/api/controllers/public/users/getPublicUser";-import verifyToken from "@/lib/api/verifyToken";export default async function users(req: NextApiRequest, res: NextApiResponse) {- const token = await verifyToken({ req });- const requestingId = typeof token === "string" ? undefined : token?.id;-const lookupId = req.query.id as string;// Check if "lookupId" is the user "id" or their "username"const isId = lookupId.split("").every((e) => Number.isInteger(parseInt(e)));if (req.method === "GET") {- const users = await getPublicUser(lookupId, isId, requestingId);+ const users = await getPublicUser(lookupId, isId);return res.status(users.status).json({ response: users.response });}}diff --git a/apps/web/pages/settings/account.tsx b/apps/web/pages/settings/account.tsxindex 4add33f1..3ff2ba1c 100644--- a/apps/web/pages/settings/account.tsx+++ b/apps/web/pages/settings/account.tsx@@ -45,10 +45,8 @@ const Page: NextPageWithLayout = () => {emailVerified: null,password: undefined,image: "",- isPrivate: false,// @ts-ignorecreatedAt: null,- whitelistedUsers: [],} as unknown as AccountSettings));@@ -56,16 +54,12 @@ const Page: NextPageWithLayout = () => {const { t } = useTranslation();- const [whitelistedUsersTextbox, setWhiteListedUsersTextbox] = useState("");-useEffect(() => {if (!account?.id) return;setUser({...account,- whitelistedUsers: account?.whitelistedUsers || [],});- setWhiteListedUsersTextbox(account?.whitelistedUsers?.join(", ") || "");}, [account]);const handleImageUpload = async (e: ChangeEvent<HTMLInputElement>) => {@@ -118,7 +112,6 @@ const Page: NextPageWithLayout = () => {locale: user.locale,image: user.image,isPrivate: user.isPrivate,- whitelistedUsers: stringToArray(whitelistedUsersTextbox),password: password ? password : undefined,},{@@ -160,29 +153,14 @@ const Page: NextPageWithLayout = () => {const hasAccountChanges = useMemo(() => {if (!account?.id) return false;- const currentWhitelist = normalizeUserList(- stringToArray(whitelistedUsersTextbox)- );- const originalWhitelist = normalizeUserList(- account?.whitelistedUsers || []- );-- const whitelistChanged =- currentWhitelist.length !== originalWhitelist.length ||- currentWhitelist.some(- (value, index) => value !== originalWhitelist[index]- );-return ((user.name || "") !== (account.name || "") ||(user.username || "") !== (account.username || "") ||(user.email || "") !== (account.email || "") ||(user.locale || "") !== (account.locale || "") ||- (user.image || "") !== (account.image || "") ||- Boolean(user.isPrivate) !== Boolean(account.isPrivate) ||- whitelistChanged+ (user.image || "") !== (account.image || ""));- }, [account, user, whitelistedUsersTextbox]);+ }, [account, user]);return (<>@@ -305,38 +283,6 @@ const Page: NextPageWithLayout = () => {</div></div>- <div className="sm:-mt-3">- <Checkbox- label={t("make_profile_private")}- state={user.isPrivate}- onClick={() => setUser({ ...user, isPrivate: !user.isPrivate })}- />-- <p className="text-neutral text-sm">{t("profile_privacy_info")}</p>-- {user.isPrivate && (- <div className="pl-5">- <p className="mt-2">{t("whitelisted_users")}</p>- <p className="text-neutral text-sm mb-3">- {t("whitelisted_users_info")}- </p>- <textarea- className="w-full max-w-screen-sm resize-none border rounded-md duration-100 bg-base-200 p-2 outline-none border-neutral-content focus:border-primary"- placeholder={t("whitelisted_users_placeholder")}- value={whitelistedUsersTextbox}- onChange={(e) => {- const value = e.target.value;- setWhiteListedUsersTextbox(value);- setUser((prev: AccountSettings) => ({- ...prev,- whitelistedUsers: stringToArray(value),- }));- }}- />- </div>- )}- </div>-<Buttonvariant="accent"onClick={() => {@@ -347,7 +293,7 @@ const Page: NextPageWithLayout = () => {}}}disabled={submitLoader || !hasAccountChanges}- className="mt-2 w-full sm:w-fit"+ className="w-full sm:w-fit">{t("save_changes")}</Button>diff --git a/apps/web/pages/settings/password.tsx b/apps/web/pages/settings/password.tsxindex cae67c11..03a66b13 100644--- a/apps/web/pages/settings/password.tsx+++ b/apps/web/pages/settings/password.tsx@@ -35,7 +35,6 @@ const Page: NextPageWithLayout = () => {id: account.id,username: account.username,email: account.email,- whitelistedUsers: account.whitelistedUsers || [],newPassword,oldPassword,},diff --git a/apps/web/pages/settings/preference.tsx b/apps/web/pages/settings/preference.tsxindex 7d961d12..d41376ef 100644--- a/apps/web/pages/settings/preference.tsx+++ b/apps/web/pages/settings/preference.tsx@@ -120,7 +120,6 @@ const Page: NextPageWithLayout = () => {id: account?.id,username: account?.username,email: account?.email,- whitelistedUsers: account?.whitelistedUsers || [],});const hasAiChanges =diff --git a/packages/lib/schemaValidation.ts b/packages/lib/schemaValidation.tsindex 901d32d8..b3be06b0 100644--- a/packages/lib/schemaValidation.ts+++ b/packages/lib/schemaValidation.ts@@ -90,7 +90,6 @@ export const UpdateUserSchema = () => {preventDuplicateLinks: z.boolean().optional(),collectionOrder: z.array(z.number()).optional(),linksRouteTo: z.enum(LinksRouteTo).optional(),- whitelistedUsers: z.array(z.string().max(50)).optional(),referredBy: z.string().max(100).nullish(),});};diff --git a/packages/router/user.tsx b/packages/router/user.tsxindex ae68da61..e54be22a 100644--- a/packages/router/user.tsx+++ b/packages/router/user.tsx@@ -49,7 +49,6 @@ const useUser = (auth?: MobileAuth) => {};};} & {- whitelistedUsers: string[];dashboardSections: DashboardSection[];};@@ -70,7 +69,6 @@ const useUser = (auth?: MobileAuth) => {};};} & {- whitelistedUsers: string[];dashboardSections: DashboardSection[];},});@@ -132,8 +130,6 @@ const useUpdateUserPreference = () => {email: string | null | undefined;};};- } & {- whitelistedUsers: string[];};},onSuccess: (data) => {diff --git a/packages/types/global.ts b/packages/types/global.tsindex 260fc79c..8e25cf35 100644--- a/packages/types/global.ts+++ b/packages/types/global.ts@@ -52,7 +52,6 @@ export interface TagIncludingLinkCount extends Tag {export interface AccountSettings extends User {newPassword?: string;oldPassword?: string;- whitelistedUsers: string[];subscription?: {active?: boolean;};