Merge branch 'dev' of https://github.com/linkwarden/linkwarden into feat/single-file
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import { CollectionIncludingMembersAndLinkCount, Member } from "@/types/global";
|
||||
import getPublicUserData from "./getPublicUserData";
|
||||
import { toast } from "react-hot-toast";
|
||||
import { TFunction } from "i18next";
|
||||
|
||||
const addMemberToCollection = async (
|
||||
ownerUsername: string,
|
||||
memberUsername: string,
|
||||
collection: CollectionIncludingMembersAndLinkCount,
|
||||
setMember: (newMember: Member) => null | undefined
|
||||
setMember: (newMember: Member) => null | undefined,
|
||||
t: TFunction<"translation", undefined>
|
||||
) => {
|
||||
const checkIfMemberAlreadyExists = collection.members.find((e) => {
|
||||
const username = (e.user.username || "").toLowerCase();
|
||||
@@ -39,9 +41,9 @@ const addMemberToCollection = async (
|
||||
},
|
||||
});
|
||||
}
|
||||
} else if (checkIfMemberAlreadyExists) toast.error("User already exists.");
|
||||
} else if (checkIfMemberAlreadyExists) toast.error(t("user_already_member"));
|
||||
else if (memberUsername.trim().toLowerCase() === ownerUsername.toLowerCase())
|
||||
toast.error("You are already the collection owner.");
|
||||
toast.error(t("you_are_already_collection_owner"));
|
||||
};
|
||||
|
||||
export default addMemberToCollection;
|
||||
|
||||
@@ -7,8 +7,8 @@ import { LinksRouteTo } from "@prisma/client";
|
||||
import {
|
||||
pdfAvailable,
|
||||
readabilityAvailable,
|
||||
singlefileAvailable,
|
||||
screenshotAvailable,
|
||||
singlefileAvailable,
|
||||
} from "../shared/getArchiveValidity";
|
||||
|
||||
export const generateLinkHref = (
|
||||
@@ -17,28 +17,33 @@ export const generateLinkHref = (
|
||||
): string => {
|
||||
// Return the links href based on the account's preference
|
||||
// If the user's preference is not available, return the original link
|
||||
switch (account.linksRouteTo) {
|
||||
case LinksRouteTo.ORIGINAL:
|
||||
return link.url || "";
|
||||
case LinksRouteTo.PDF:
|
||||
if (!pdfAvailable(link)) return link.url || "";
|
||||
if (account.linksRouteTo === LinksRouteTo.ORIGINAL && link.type === "url") {
|
||||
return link.url || "";
|
||||
} else if (account.linksRouteTo === LinksRouteTo.PDF || link.type === "pdf") {
|
||||
if (!pdfAvailable(link)) return link.url || "";
|
||||
|
||||
return `/preserved/${link?.id}?format=${ArchivedFormat.pdf}`;
|
||||
case LinksRouteTo.READABLE:
|
||||
if (!readabilityAvailable(link)) return link.url || "";
|
||||
return `/preserved/${link?.id}?format=${ArchivedFormat.pdf}`;
|
||||
} else if (
|
||||
account.linksRouteTo === LinksRouteTo.READABLE &&
|
||||
link.type === "url"
|
||||
) {
|
||||
if (!readabilityAvailable(link)) return link.url || "";
|
||||
|
||||
return `/preserved/${link?.id}?format=${ArchivedFormat.readability}`;
|
||||
case LinksRouteTo.SINGLEFILE:
|
||||
if (!singlefileAvailable(link)) return link.url || "";
|
||||
return `/preserved/${link?.id}?format=${ArchivedFormat.readability}`;
|
||||
} else if (
|
||||
account.linksRouteTo === LinksRouteTo.SCREENSHOT ||
|
||||
link.type === "image"
|
||||
) {
|
||||
if (!screenshotAvailable(link)) return link.url || "";
|
||||
|
||||
return `/preserved/${link?.id}?format=${ArchivedFormat.singlefile}`;
|
||||
case LinksRouteTo.SCREENSHOT:
|
||||
if (!screenshotAvailable(link)) return link.url || "";
|
||||
return `/preserved/${link?.id}?format=${
|
||||
link?.image?.endsWith("png") ? ArchivedFormat.png : ArchivedFormat.jpeg
|
||||
}`;
|
||||
} else if (account.linksRouteTo === LinksRouteTo.SINGLEFILE) {
|
||||
if (!singlefileAvailable(link)) return link.url || "";
|
||||
|
||||
return `/preserved/${link?.id}?format=${
|
||||
link?.image?.endsWith("png") ? ArchivedFormat.png : ArchivedFormat.jpeg
|
||||
}`;
|
||||
default:
|
||||
return link.url || "";
|
||||
return `/preserved/${link?.id}?format=${ArchivedFormat.singlefile}`;
|
||||
} else {
|
||||
return link.url || "";
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { GetServerSideProps } from "next";
|
||||
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
|
||||
import { i18n } from "next-i18next.config";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import { prisma } from "../api/db";
|
||||
|
||||
const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const acceptLanguageHeader = ctx.req.headers["accept-language"];
|
||||
const availableLanguages = i18n.locales;
|
||||
|
||||
const token = await getToken({ req: ctx.req });
|
||||
|
||||
if (token) {
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: token.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (user) {
|
||||
return {
|
||||
props: {
|
||||
...(await serverSideTranslations(user.locale ?? "en", ["common"])),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const acceptedLanguages = acceptLanguageHeader
|
||||
?.split(",")
|
||||
.map((lang) => lang.split(";")[0]);
|
||||
|
||||
let bestMatch = acceptedLanguages?.find((lang) =>
|
||||
availableLanguages.includes(lang)
|
||||
);
|
||||
|
||||
if (!bestMatch) {
|
||||
acceptedLanguages?.some((acceptedLang) => {
|
||||
const partialMatch = availableLanguages.find((lang) =>
|
||||
lang.startsWith(acceptedLang)
|
||||
);
|
||||
if (partialMatch) {
|
||||
bestMatch = partialMatch;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
...(await serverSideTranslations(bestMatch ?? "en", ["common"])),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default getServerSideProps;
|
||||
@@ -18,3 +18,7 @@ export function dropdownTriggerer(e: any) {
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
import clsx, { ClassValue } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
export const cn = (...classes: ClassValue[]) => twMerge(clsx(...classes));
|
||||
|
||||
Reference in New Issue
Block a user