bug fixed
This commit is contained in:
@@ -18,7 +18,7 @@ import useModalStore from "@/store/modals";
|
|||||||
import { faCalendarDays } from "@fortawesome/free-regular-svg-icons";
|
import { faCalendarDays } from "@fortawesome/free-regular-svg-icons";
|
||||||
import usePermissions from "@/hooks/usePermissions";
|
import usePermissions from "@/hooks/usePermissions";
|
||||||
import { toast } from "react-hot-toast";
|
import { toast } from "react-hot-toast";
|
||||||
import isValidUrl from "@/lib/client/isValidUrl";
|
import isValidUrl from "@/lib/shared/isValidUrl";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import unescapeString from "@/lib/client/unescapeString";
|
import unescapeString from "@/lib/client/unescapeString";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
@@ -54,7 +54,7 @@ export default function LinkCard({ link, count, className }: Props) {
|
|||||||
let shortendURL;
|
let shortendURL;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
shortendURL = new URL(link.url).host.toLowerCase();
|
shortendURL = new URL(link.url || "").host.toLowerCase();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,8 @@ export default function LinkCard({ link, count, className }: Props) {
|
|||||||
setExpandDropdown(false);
|
setExpandDropdown(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const url = isValidUrl(link.url) ? new URL(link.url) : undefined;
|
const url =
|
||||||
|
isValidUrl(link.url || "") && link.url ? new URL(link.url) : undefined;
|
||||||
|
|
||||||
const formattedDate = new Date(link.createdAt as string).toLocaleString(
|
const formattedDate = new Date(link.createdAt as string).toLocaleString(
|
||||||
"en-US",
|
"en-US",
|
||||||
@@ -230,7 +231,7 @@ export default function LinkCard({ link, count, className }: Props) {
|
|||||||
) : undefined} */}
|
) : undefined} */}
|
||||||
|
|
||||||
<Link
|
<Link
|
||||||
href={link.url}
|
href={link.url || ""}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { faFolder, faLink } from "@fortawesome/free-solid-svg-icons";
|
|||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { faCalendarDays } from "@fortawesome/free-regular-svg-icons";
|
import { faCalendarDays } from "@fortawesome/free-regular-svg-icons";
|
||||||
import isValidUrl from "@/lib/client/isValidUrl";
|
import isValidUrl from "@/lib/shared/isValidUrl";
|
||||||
import A from "next/link";
|
import A from "next/link";
|
||||||
import unescapeString from "@/lib/client/unescapeString";
|
import unescapeString from "@/lib/client/unescapeString";
|
||||||
import { Link } from "@prisma/client";
|
import { Link } from "@prisma/client";
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ export default function AddOrEditLink({
|
|||||||
activeLink || {
|
activeLink || {
|
||||||
name: "",
|
name: "",
|
||||||
url: "",
|
url: "",
|
||||||
|
type: "",
|
||||||
description: "",
|
description: "",
|
||||||
tags: [],
|
tags: [],
|
||||||
screenshotPath: "",
|
screenshotPath: "",
|
||||||
@@ -139,10 +140,10 @@ export default function AddOrEditLink({
|
|||||||
{method === "UPDATE" ? (
|
{method === "UPDATE" ? (
|
||||||
<div
|
<div
|
||||||
className="text-gray-500 dark:text-gray-300 break-all w-full flex gap-2"
|
className="text-gray-500 dark:text-gray-300 break-all w-full flex gap-2"
|
||||||
title={link.url}
|
title={link.url || ""}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faLink} className="w-6 h-6" />
|
<FontAwesomeIcon icon={faLink} className="w-6 h-6" />
|
||||||
<Link href={link.url} target="_blank" className="w-full">
|
<Link href={link.url || ""} target="_blank" className="w-full">
|
||||||
{link.url}
|
{link.url}
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
@@ -153,7 +154,7 @@ export default function AddOrEditLink({
|
|||||||
<div className="sm:col-span-3 col-span-5">
|
<div className="sm:col-span-3 col-span-5">
|
||||||
<p className="text-black dark:text-white mb-2">Address (URL)</p>
|
<p className="text-black dark:text-white mb-2">Address (URL)</p>
|
||||||
<TextInput
|
<TextInput
|
||||||
value={link.url}
|
value={link.url || ""}
|
||||||
onChange={(e) => setLink({ ...link, url: e.target.value })}
|
onChange={(e) => setLink({ ...link, url: e.target.value })}
|
||||||
placeholder="e.g. http://example.com/"
|
placeholder="e.g. http://example.com/"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { faChevronRight } from "@fortawesome/free-solid-svg-icons";
|
|||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { Link as LinkType, Tag } from "@prisma/client";
|
import { Link as LinkType, Tag } from "@prisma/client";
|
||||||
import isValidUrl from "@/lib/client/isValidUrl";
|
import isValidUrl from "@/lib/shared/isValidUrl";
|
||||||
import unescapeString from "@/lib/client/unescapeString";
|
import unescapeString from "@/lib/client/unescapeString";
|
||||||
import { TagIncludingLinkCount } from "@/types/global";
|
import { TagIncludingLinkCount } from "@/types/global";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@@ -17,7 +17,7 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function LinkCard({ link, count }: Props) {
|
export default function LinkCard({ link, count }: Props) {
|
||||||
const url = isValidUrl(link.url) ? new URL(link.url) : undefined;
|
const url = link.url && isValidUrl(link.url) ? new URL(link.url) : undefined;
|
||||||
|
|
||||||
const formattedDate = new Date(
|
const formattedDate = new Date(
|
||||||
link.createdAt as unknown as string
|
link.createdAt as unknown as string
|
||||||
@@ -68,10 +68,10 @@ export default function LinkCard({ link, count }: Props) {
|
|||||||
<p>{formattedDate}</p>
|
<p>{formattedDate}</p>
|
||||||
<p>·</p>
|
<p>·</p>
|
||||||
<Link
|
<Link
|
||||||
href={url ? url.href : link.url}
|
href={url ? url.href : link.url || ""}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
className="hover:opacity-50 duration-100 truncate w-52 sm:w-fit"
|
className="hover:opacity-50 duration-100 truncate w-52 sm:w-fit"
|
||||||
title={url ? url.href : link.url}
|
title={url ? url.href : link.url || ""}
|
||||||
>
|
>
|
||||||
{url ? url.host : link.url}
|
{url ? url.host : link.url}
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
|||||||
import urlHandler from "@/lib/api/urlHandler";
|
import urlHandler from "@/lib/api/urlHandler";
|
||||||
import { prisma } from "@/lib/api/db";
|
import { prisma } from "@/lib/api/db";
|
||||||
import verifyUser from "@/lib/api/verifyUser";
|
import verifyUser from "@/lib/api/verifyUser";
|
||||||
|
import isValidUrl from "@/lib/shared/isValidUrl";
|
||||||
|
|
||||||
const RE_ARCHIVE_LIMIT = Number(process.env.RE_ARCHIVE_LIMIT) || 5;
|
const RE_ARCHIVE_LIMIT = Number(process.env.RE_ARCHIVE_LIMIT) || 5;
|
||||||
|
|
||||||
@@ -41,7 +42,13 @@ export default async function links(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
} minutes or create a new one.`,
|
} minutes or create a new one.`,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (link.url && isValidUrl(link.url)) {
|
||||||
urlHandler(link.id, link.url, user.id);
|
urlHandler(link.id, link.url, user.id);
|
||||||
|
return res.status(200).json({
|
||||||
|
response: "Link is not a webpage to be archived.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
response: "Link is being archived.",
|
response: "Link is being archived.",
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import Image from "next/image";
|
|||||||
import ColorThief, { RGBColor } from "colorthief";
|
import ColorThief, { RGBColor } from "colorthief";
|
||||||
import { useTheme } from "next-themes";
|
import { useTheme } from "next-themes";
|
||||||
import unescapeString from "@/lib/client/unescapeString";
|
import unescapeString from "@/lib/client/unescapeString";
|
||||||
import isValidUrl from "@/lib/client/isValidUrl";
|
import isValidUrl from "@/lib/shared/isValidUrl";
|
||||||
import DOMPurify from "dompurify";
|
import DOMPurify from "dompurify";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faBoxesStacked, faFolder } from "@fortawesome/free-solid-svg-icons";
|
import { faBoxesStacked, faFolder } from "@fortawesome/free-solid-svg-icons";
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import Image from "next/image";
|
|||||||
import ColorThief, { RGBColor } from "colorthief";
|
import ColorThief, { RGBColor } from "colorthief";
|
||||||
import { useTheme } from "next-themes";
|
import { useTheme } from "next-themes";
|
||||||
import unescapeString from "@/lib/client/unescapeString";
|
import unescapeString from "@/lib/client/unescapeString";
|
||||||
import isValidUrl from "@/lib/client/isValidUrl";
|
import isValidUrl from "@/lib/shared/isValidUrl";
|
||||||
import DOMPurify from "dompurify";
|
import DOMPurify from "dompurify";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faBoxesStacked, faFolder } from "@fortawesome/free-solid-svg-icons";
|
import { faBoxesStacked, faFolder } from "@fortawesome/free-solid-svg-icons";
|
||||||
|
|||||||
Reference in New Issue
Block a user