fix: validate thread share link cid

Ensure thread share links throw when cid is missing and require a cid in caller props so we never build /thread/undefined URLs.
This commit is contained in:
plebeius
2025-12-08 23:44:38 +01:00
parent c7d53bd9b5
commit 23f245145c
3 changed files with 24 additions and 6 deletions
@@ -15,7 +15,11 @@ import useHide from '../../../hooks/use-hide';
import _ from 'lodash';
import { PostMenuProps } from '../../../lib/utils/post-menu-props';
const CopyLinkButton = ({ cid, subplebbitAddress, linkType, onClose }: { cid?: string; subplebbitAddress: string; linkType: ShareLinkType; onClose: () => void }) => {
type CopyLinkButtonProps =
| { cid: string; subplebbitAddress: string; linkType: 'thread'; onClose: () => void }
| { subplebbitAddress: string; linkType: Exclude<ShareLinkType, 'thread'>; onClose: () => void; cid?: undefined };
const CopyLinkButton = ({ cid, subplebbitAddress, linkType, onClose }: CopyLinkButtonProps) => {
const { t } = useTranslation();
const defaultSubplebbits = useDefaultSubplebbits();
const boardIdentifier = getBoardPath(subplebbitAddress, defaultSubplebbits);
@@ -23,7 +23,11 @@ type HideButtonProps = {
onClose?: () => void;
};
const CopyLinkButton = ({ cid, subplebbitAddress, linkType, onClose }: { cid?: string; subplebbitAddress: string; linkType: ShareLinkType; onClose: () => void }) => {
type CopyLinkButtonProps =
| { cid: string; subplebbitAddress: string; linkType: 'thread'; onClose: () => void }
| { subplebbitAddress: string; linkType: Exclude<ShareLinkType, 'thread'>; onClose: () => void; cid?: undefined };
const CopyLinkButton = ({ cid, subplebbitAddress, linkType, onClose }: CopyLinkButtonProps) => {
const { t } = useTranslation();
const defaultSubplebbits = useDefaultSubplebbits();
const boardIdentifier = getBoardPath(subplebbitAddress, defaultSubplebbits);