mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
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:
@@ -15,7 +15,11 @@ import useHide from '../../../hooks/use-hide';
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { PostMenuProps } from '../../../lib/utils/post-menu-props';
|
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 { t } = useTranslation();
|
||||||
const defaultSubplebbits = useDefaultSubplebbits();
|
const defaultSubplebbits = useDefaultSubplebbits();
|
||||||
const boardIdentifier = getBoardPath(subplebbitAddress, defaultSubplebbits);
|
const boardIdentifier = getBoardPath(subplebbitAddress, defaultSubplebbits);
|
||||||
|
|||||||
@@ -23,7 +23,11 @@ type HideButtonProps = {
|
|||||||
onClose?: () => void;
|
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 { t } = useTranslation();
|
||||||
const defaultSubplebbits = useDefaultSubplebbits();
|
const defaultSubplebbits = useDefaultSubplebbits();
|
||||||
const boardIdentifier = getBoardPath(subplebbitAddress, defaultSubplebbits);
|
const boardIdentifier = getBoardPath(subplebbitAddress, defaultSubplebbits);
|
||||||
|
|||||||
@@ -20,11 +20,21 @@ export const isValidURL = (url: string) => {
|
|||||||
export type ShareLinkType = 'thread' | 'description' | 'rules';
|
export type ShareLinkType = 'thread' | 'description' | 'rules';
|
||||||
|
|
||||||
// Copies a share link to clipboard for a board, thread, description, or rules page
|
// Copies a share link to clipboard for a board, thread, description, or rules page
|
||||||
export const copyShareLinkToClipboard = async (boardIdentifier: string, linkType: ShareLinkType, cid?: string) => {
|
export function copyShareLinkToClipboard(boardIdentifier: string, linkType: 'thread', cid: string): Promise<void>;
|
||||||
const suffix = linkType === 'thread' ? `/thread/${cid}` : `/${linkType}`;
|
export function copyShareLinkToClipboard(boardIdentifier: string, linkType: Exclude<ShareLinkType, 'thread'>, cid?: undefined): Promise<void>;
|
||||||
const shareLink = `https://5chan.app/${boardIdentifier}${suffix}`;
|
export async function copyShareLinkToClipboard(boardIdentifier: string, linkType: ShareLinkType, cid?: string): Promise<void> {
|
||||||
|
if (linkType === 'thread') {
|
||||||
|
if (!cid) {
|
||||||
|
throw new Error('copyShareLinkToClipboard: thread links require a cid');
|
||||||
|
}
|
||||||
|
const shareLink = `https://5chan.app/${boardIdentifier}/thread/${cid}`;
|
||||||
await copyToClipboard(shareLink);
|
await copyToClipboard(shareLink);
|
||||||
};
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const shareLink = `https://5chan.app/${boardIdentifier}/${linkType}`;
|
||||||
|
await copyToClipboard(shareLink);
|
||||||
|
}
|
||||||
|
|
||||||
const CHAN_5_HOSTNAMES = ['pleb.bz', '5chan.app', '5chan.eth.limo', '5chan.eth.link', '5chan.eth.sucks', '5chan.netlify.app'];
|
const CHAN_5_HOSTNAMES = ['pleb.bz', '5chan.app', '5chan.eth.limo', '5chan.eth.link', '5chan.eth.sucks', '5chan.netlify.app'];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user