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:
@@ -20,11 +20,21 @@ export const isValidURL = (url: string) => {
|
||||
export type ShareLinkType = 'thread' | 'description' | 'rules';
|
||||
|
||||
// Copies a share link to clipboard for a board, thread, description, or rules page
|
||||
export const copyShareLinkToClipboard = async (boardIdentifier: string, linkType: ShareLinkType, cid?: string) => {
|
||||
const suffix = linkType === 'thread' ? `/thread/${cid}` : `/${linkType}`;
|
||||
const shareLink = `https://5chan.app/${boardIdentifier}${suffix}`;
|
||||
export function copyShareLinkToClipboard(boardIdentifier: string, linkType: 'thread', cid: string): Promise<void>;
|
||||
export function copyShareLinkToClipboard(boardIdentifier: string, linkType: Exclude<ShareLinkType, 'thread'>, cid?: undefined): Promise<void>;
|
||||
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);
|
||||
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'];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user