mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
refactor(routing): namespace board mod queue under board mod routes
Updated the canonical board mod queue URL to /:boardIdentifier/mod/queue and made legacy /:boardIdentifier/modqueue paths resolve to not found. Tightened route helpers so board-scoped mod URLs no longer fall through as generic board pages.
This commit is contained in:
+38
-6
@@ -12,7 +12,18 @@ import useIsMobile from './hooks/use-is-mobile';
|
||||
import useTheme from './hooks/use-theme';
|
||||
import { useDirectories } from './hooks/use-directories';
|
||||
import { useResolvedSubplebbitAddress } from './hooks/use-resolved-subplebbit-address';
|
||||
import { getBoardPath, getSubplebbitAddress, isDirectoryBoard, isPostRoute, isPendingPostRoute, isModQueueRoute } from './lib/utils/route-utils';
|
||||
import {
|
||||
getBoardPath,
|
||||
getSubplebbitAddress,
|
||||
isBoardModRoute,
|
||||
isDirectoryBoard,
|
||||
isLegacyBoardModQueueRoute,
|
||||
isPostRoute,
|
||||
isPendingPostRoute,
|
||||
isModQueueRoute,
|
||||
isValidBoardModRoute,
|
||||
isValidModRoute,
|
||||
} from './lib/utils/route-utils';
|
||||
import styles from './app.module.css';
|
||||
import { DesktopBoardButtons, MobileBoardButtons } from './components/board-buttons';
|
||||
import Board from './views/board';
|
||||
@@ -90,6 +101,20 @@ const BoardLayout = () => {
|
||||
return <Navigate to='/not-found' replace />;
|
||||
}
|
||||
|
||||
// Invalid /mod/ paths (e.g. /mod/modqueue, /mod/asdoijasd) -> not-found
|
||||
if (location.pathname.startsWith('/mod/') && !isValidModRoute(location.pathname)) {
|
||||
return <Navigate to='/not-found' replace />;
|
||||
}
|
||||
|
||||
if (isLegacyBoardModQueueRoute(location.pathname)) {
|
||||
return <Navigate to='/not-found' replace />;
|
||||
}
|
||||
|
||||
// Invalid board-scoped mod paths (e.g. /biz/mod, /biz/mod/asdoijasd) -> not-found
|
||||
if (isBoardModRoute(location.pathname) && !isValidBoardModRoute(location.pathname)) {
|
||||
return <Navigate to='/not-found' replace />;
|
||||
}
|
||||
|
||||
// Normalize address URLs to directory codes: /anime-and-manga.eth/thread/xxx -> /a/thread/xxx
|
||||
if (boardIdentifier && !isDirectoryBoard(boardIdentifier, directories)) {
|
||||
const canonicalBoardIdentifier = getBoardPath(boardIdentifier, directories);
|
||||
@@ -287,10 +312,12 @@ const App = () => {
|
||||
<Route path='/mod/catalog' element={catalogFeedElement} />
|
||||
<Route path='/mod/catalog/settings' element={catalogFeedElement} />
|
||||
|
||||
<Route path='/mod/modqueue' element={<ModQueueRoute />} />
|
||||
<Route path='/mod/modqueue/settings' element={<ModQueueRoute />} />
|
||||
<Route path='/mod/queue' element={<ModQueueRoute />} />
|
||||
<Route path='/mod/queue/settings' element={<ModQueueRoute />} />
|
||||
|
||||
{/* Invalid subpaths: old time-filter URLs (e.g. /all/24h) -> not-found */}
|
||||
{/* Invalid subpaths: old URLs and unknown paths -> not-found */}
|
||||
<Route path='/mod/modqueue' element={<Navigate to='/not-found' replace />} />
|
||||
<Route path='/mod/modqueue/settings' element={<Navigate to='/not-found' replace />} />
|
||||
<Route path='/all/*' element={<Navigate to='/not-found' replace />} />
|
||||
<Route path='/subs/*' element={<Navigate to='/not-found' replace />} />
|
||||
<Route path='/mod/*' element={<Navigate to='/not-found' replace />} />
|
||||
@@ -302,8 +329,13 @@ const App = () => {
|
||||
<Route path='/:boardIdentifier/catalog' element={catalogFeedElement} />
|
||||
<Route path='/:boardIdentifier/catalog/settings' element={catalogFeedElement} />
|
||||
|
||||
<Route path='/:boardIdentifier/modqueue' element={<ModQueueRoute />} />
|
||||
<Route path='/:boardIdentifier/modqueue/settings' element={<ModQueueRoute />} />
|
||||
<Route path='/:boardIdentifier/mod/queue' element={<ModQueueRoute />} />
|
||||
<Route path='/:boardIdentifier/mod/queue/settings' element={<ModQueueRoute />} />
|
||||
|
||||
<Route path='/:boardIdentifier/modqueue' element={<Navigate to='/not-found' replace />} />
|
||||
<Route path='/:boardIdentifier/modqueue/settings' element={<Navigate to='/not-found' replace />} />
|
||||
<Route path='/:boardIdentifier/mod' element={<Navigate to='/not-found' replace />} />
|
||||
<Route path='/:boardIdentifier/mod/*' element={<Navigate to='/not-found' replace />} />
|
||||
|
||||
<Route path='/:boardIdentifier/thread/:commentCid' element={<Post />} />
|
||||
<Route path='/:boardIdentifier/thread/:commentCid/settings' element={<Post />} />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { isFeedRoute, normalizeMultiboardFeedPath } from '../route-utils';
|
||||
import { isBoardModRoute, isFeedRoute, isLegacyBoardModQueueRoute, isModQueueRoute, isValidBoardModRoute, normalizeMultiboardFeedPath } from '../route-utils';
|
||||
|
||||
describe('normalizeMultiboardFeedPath', () => {
|
||||
it('normalizes /all/3 -> /all', () => {
|
||||
@@ -41,4 +41,41 @@ describe('isFeedRoute', () => {
|
||||
expect(isFeedRoute('/subs/catalog/1w')).toBe(false);
|
||||
expect(isFeedRoute('/all/1w/3')).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false for board-scoped mod namespace paths', () => {
|
||||
expect(isFeedRoute('/biz/mod')).toBe(false);
|
||||
expect(isFeedRoute('/biz/mod/queue')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('board mod routes', () => {
|
||||
it('recognizes canonical mod queue routes', () => {
|
||||
expect(isModQueueRoute('/mod/queue')).toBe(true);
|
||||
expect(isModQueueRoute('/biz/mod/queue')).toBe(true);
|
||||
expect(isModQueueRoute('/biz/mod/queue/settings')).toBe(true);
|
||||
});
|
||||
|
||||
it('does not recognize legacy board modqueue routes', () => {
|
||||
expect(isModQueueRoute('/biz/modqueue')).toBe(false);
|
||||
});
|
||||
|
||||
it('recognizes legacy board modqueue routes for rejection', () => {
|
||||
expect(isLegacyBoardModQueueRoute('/biz/modqueue')).toBe(true);
|
||||
expect(isLegacyBoardModQueueRoute('/biz/modqueue/settings')).toBe(true);
|
||||
expect(isLegacyBoardModQueueRoute('/biz/mod/queue')).toBe(false);
|
||||
});
|
||||
|
||||
it('recognizes board mod namespace paths', () => {
|
||||
expect(isBoardModRoute('/biz/mod')).toBe(true);
|
||||
expect(isBoardModRoute('/biz/mod/queue')).toBe(true);
|
||||
expect(isBoardModRoute('/mod/queue')).toBe(false);
|
||||
});
|
||||
|
||||
it('validates allowed board mod routes', () => {
|
||||
expect(isValidBoardModRoute('/biz/mod/queue')).toBe(true);
|
||||
expect(isValidBoardModRoute('/biz/mod/queue/settings')).toBe(true);
|
||||
expect(isValidBoardModRoute('/biz/mod')).toBe(false);
|
||||
expect(isValidBoardModRoute('/biz/mod/log')).toBe(false);
|
||||
expect(isValidBoardModRoute('/biz/modqueue')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -120,7 +120,7 @@ export const isFeedRoute = (pathname: string): boolean => {
|
||||
|
||||
if (normalizedPath.includes('/thread/')) return false;
|
||||
if (normalizedPath.startsWith('/pending/')) return false;
|
||||
if (normalizedPath.includes('/modqueue')) return false;
|
||||
if (isBoardModRoute(normalizedPath) || isModQueueRoute(normalizedPath)) return false;
|
||||
|
||||
const pathWithoutSettings = normalizedPath.replace(/\/settings$/, '');
|
||||
const segments = pathWithoutSettings.split('/').filter(Boolean);
|
||||
@@ -147,9 +147,38 @@ export const isPendingPostRoute = (pathname: string): boolean => {
|
||||
return normalizedPath.startsWith('/pending/');
|
||||
};
|
||||
|
||||
export const isBoardModRoute = (pathname: string): boolean => {
|
||||
const normalizedPath = pathname.replace(/\/$/, '');
|
||||
return /^\/[^/]+\/mod(?:\/.*)?$/.test(normalizedPath);
|
||||
};
|
||||
|
||||
export const isLegacyBoardModQueueRoute = (pathname: string): boolean => {
|
||||
const normalizedPath = pathname.replace(/\/$/, '');
|
||||
return /^\/[^/]+\/modqueue(?:\/settings)?$/.test(normalizedPath);
|
||||
};
|
||||
|
||||
export const isModQueueRoute = (pathname: string): boolean => {
|
||||
const normalizedPath = pathname.replace(/\/settings$/, '');
|
||||
return normalizedPath.includes('/modqueue');
|
||||
const normalizedPath = pathname.replace(/\/settings$/, '').replace(/\/$/, '');
|
||||
return normalizedPath === '/mod/queue' || /^\/[^/]+\/mod\/queue$/.test(normalizedPath);
|
||||
};
|
||||
|
||||
const VALID_MOD_PATHS = ['/mod', '/mod/settings', '/mod/catalog', '/mod/catalog/settings', '/mod/queue', '/mod/queue/settings'];
|
||||
const VALID_BOARD_MOD_SUBPATHS = ['queue', 'queue/settings'];
|
||||
|
||||
export const isValidModRoute = (pathname: string): boolean => {
|
||||
const normalized = pathname.replace(/\/$/, '');
|
||||
return VALID_MOD_PATHS.includes(normalized);
|
||||
};
|
||||
|
||||
export const isValidBoardModRoute = (pathname: string): boolean => {
|
||||
const normalizedPath = pathname.replace(/\/$/, '');
|
||||
const match = normalizedPath.match(/^\/[^/]+\/mod(?:\/(.*))?$/);
|
||||
if (!match) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const subpath = match[1] ?? '';
|
||||
return VALID_BOARD_MOD_SUBPATHS.includes(subpath);
|
||||
};
|
||||
|
||||
/** Page numbers 1–10 for board feed pagination */
|
||||
@@ -228,7 +257,7 @@ export const getFeedCacheKey = (pathname: string): string | null => {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (normalizedPath.includes('/modqueue')) {
|
||||
if (isBoardModRoute(normalizedPath) || isModQueueRoute(normalizedPath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -82,10 +82,11 @@ export const is5chanLink = (url: string): boolean => {
|
||||
// - /{boardIdentifier} (directory code or address)
|
||||
// - /{boardIdentifier}/thread/{commentCid}
|
||||
// - /{boardIdentifier}/catalog
|
||||
// - /{boardIdentifier}/mod/queue
|
||||
// - /all, /subs, /mod, /pending/{index}
|
||||
return (
|
||||
/^\/p\/[^/]+(\/c\/[^/]+)?$/.test(routePath) ||
|
||||
/^\/[^/]+(\/thread\/[^/]+|\/catalog)?$/.test(routePath) ||
|
||||
/^\/[^/]+(\/thread\/[^/]+|\/catalog|\/mod\/queue)?$/.test(routePath) ||
|
||||
/^\/(all|subscriptions|mod)(\/catalog|\/thread\/[^/]+)?(\/[^/]+)?$/.test(routePath) ||
|
||||
/^\/pending\/[^/]+$/.test(routePath)
|
||||
);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { isBoardModRoute, isModQueueRoute } from './route-utils';
|
||||
|
||||
export type ParamsType = {
|
||||
accountCommentIndex?: string;
|
||||
boardIdentifier?: string;
|
||||
@@ -17,6 +19,7 @@ export const isBoardView = (pathname: string, params: ParamsType): boolean => {
|
||||
pathname.startsWith('/all') ||
|
||||
pathname.startsWith('/subs') ||
|
||||
pathname.startsWith('/mod') ||
|
||||
isBoardModRoute(pathname) ||
|
||||
pathname.startsWith('/pending') ||
|
||||
pathname === '/' ||
|
||||
pathname.startsWith('/faq') ||
|
||||
@@ -53,7 +56,7 @@ export const isModView = (pathname: string): boolean => {
|
||||
};
|
||||
|
||||
export const isModQueueView = (pathname: string): boolean => {
|
||||
return pathname.includes('/modqueue');
|
||||
return isModQueueRoute(pathname);
|
||||
};
|
||||
|
||||
export const isPendingPostView = (pathname: string, params: ParamsType): boolean => {
|
||||
|
||||
@@ -269,7 +269,7 @@ const ModQueueRow = memo(({ comment, isOdd = false, showBoard = false, boardPath
|
||||
const threadTargetCid = threadCid || cid;
|
||||
const postUrl = boardPath && threadTargetCid ? `/${boardPath}/thread/${threadTargetCid}` : undefined;
|
||||
|
||||
const modQueueUrl = boardPath ? `/${boardPath}/modqueue` : undefined;
|
||||
const modQueueUrl = boardPath ? `/${boardPath}/mod/queue` : undefined;
|
||||
|
||||
return (
|
||||
<div className={`${styles.row} ${isOdd ? styles.rowOdd : ''}`}>
|
||||
@@ -370,7 +370,7 @@ const ModQueueCard = memo(({ comment, showBoard = false, boardPath }: ModQueueCa
|
||||
const threadTargetCid = threadCid || cid;
|
||||
const postUrl = boardPath && threadTargetCid ? `/${boardPath}/thread/${threadTargetCid}` : undefined;
|
||||
|
||||
const modQueueUrl = boardPath ? `/${boardPath}/modqueue` : undefined;
|
||||
const modQueueUrl = boardPath ? `/${boardPath}/mod/queue` : undefined;
|
||||
|
||||
return (
|
||||
<div className={styles.mobileCard}>
|
||||
@@ -651,7 +651,7 @@ const ModQueueButtonContent = ({ feed, alertThresholdSeconds, boardIdentifier, i
|
||||
}, [statusMap]);
|
||||
|
||||
const totalCount = normalCount + urgentCount;
|
||||
const to = boardIdentifier ? `/${boardIdentifier}/modqueue` : '/mod/modqueue';
|
||||
const to = boardIdentifier ? `/${boardIdentifier}/mod/queue` : '/mod/queue';
|
||||
|
||||
const buttonContent = (
|
||||
<button className='button'>
|
||||
|
||||
Reference in New Issue
Block a user