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:
plebeius
2026-03-07 16:02:19 +08:00
parent 4eed34e4a7
commit 95088300bd
6 changed files with 118 additions and 16 deletions
+38 -6
View File
@@ -12,7 +12,18 @@ import useIsMobile from './hooks/use-is-mobile';
import useTheme from './hooks/use-theme'; import useTheme from './hooks/use-theme';
import { useDirectories } from './hooks/use-directories'; import { useDirectories } from './hooks/use-directories';
import { useResolvedSubplebbitAddress } from './hooks/use-resolved-subplebbit-address'; 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 styles from './app.module.css';
import { DesktopBoardButtons, MobileBoardButtons } from './components/board-buttons'; import { DesktopBoardButtons, MobileBoardButtons } from './components/board-buttons';
import Board from './views/board'; import Board from './views/board';
@@ -90,6 +101,20 @@ const BoardLayout = () => {
return <Navigate to='/not-found' replace />; 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 // Normalize address URLs to directory codes: /anime-and-manga.eth/thread/xxx -> /a/thread/xxx
if (boardIdentifier && !isDirectoryBoard(boardIdentifier, directories)) { if (boardIdentifier && !isDirectoryBoard(boardIdentifier, directories)) {
const canonicalBoardIdentifier = getBoardPath(boardIdentifier, directories); const canonicalBoardIdentifier = getBoardPath(boardIdentifier, directories);
@@ -287,10 +312,12 @@ const App = () => {
<Route path='/mod/catalog' element={catalogFeedElement} /> <Route path='/mod/catalog' element={catalogFeedElement} />
<Route path='/mod/catalog/settings' element={catalogFeedElement} /> <Route path='/mod/catalog/settings' element={catalogFeedElement} />
<Route path='/mod/modqueue' element={<ModQueueRoute />} /> <Route path='/mod/queue' element={<ModQueueRoute />} />
<Route path='/mod/modqueue/settings' 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='/all/*' element={<Navigate to='/not-found' replace />} />
<Route path='/subs/*' element={<Navigate to='/not-found' replace />} /> <Route path='/subs/*' element={<Navigate to='/not-found' replace />} />
<Route path='/mod/*' 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' element={catalogFeedElement} />
<Route path='/:boardIdentifier/catalog/settings' element={catalogFeedElement} /> <Route path='/:boardIdentifier/catalog/settings' element={catalogFeedElement} />
<Route path='/:boardIdentifier/modqueue' element={<ModQueueRoute />} /> <Route path='/:boardIdentifier/mod/queue' element={<ModQueueRoute />} />
<Route path='/:boardIdentifier/modqueue/settings' 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' element={<Post />} />
<Route path='/:boardIdentifier/thread/:commentCid/settings' element={<Post />} /> <Route path='/:boardIdentifier/thread/:commentCid/settings' element={<Post />} />
+38 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'; import { describe, it, expect } from 'vitest';
import { isFeedRoute, normalizeMultiboardFeedPath } from '../route-utils'; import { isBoardModRoute, isFeedRoute, isLegacyBoardModQueueRoute, isModQueueRoute, isValidBoardModRoute, normalizeMultiboardFeedPath } from '../route-utils';
describe('normalizeMultiboardFeedPath', () => { describe('normalizeMultiboardFeedPath', () => {
it('normalizes /all/3 -> /all', () => { it('normalizes /all/3 -> /all', () => {
@@ -41,4 +41,41 @@ describe('isFeedRoute', () => {
expect(isFeedRoute('/subs/catalog/1w')).toBe(false); expect(isFeedRoute('/subs/catalog/1w')).toBe(false);
expect(isFeedRoute('/all/1w/3')).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);
});
}); });
+33 -4
View File
@@ -120,7 +120,7 @@ export const isFeedRoute = (pathname: string): boolean => {
if (normalizedPath.includes('/thread/')) return false; if (normalizedPath.includes('/thread/')) return false;
if (normalizedPath.startsWith('/pending/')) 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 pathWithoutSettings = normalizedPath.replace(/\/settings$/, '');
const segments = pathWithoutSettings.split('/').filter(Boolean); const segments = pathWithoutSettings.split('/').filter(Boolean);
@@ -147,9 +147,38 @@ export const isPendingPostRoute = (pathname: string): boolean => {
return normalizedPath.startsWith('/pending/'); 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 => { export const isModQueueRoute = (pathname: string): boolean => {
const normalizedPath = pathname.replace(/\/settings$/, ''); const normalizedPath = pathname.replace(/\/settings$/, '').replace(/\/$/, '');
return normalizedPath.includes('/modqueue'); 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 110 for board feed pagination */ /** Page numbers 110 for board feed pagination */
@@ -228,7 +257,7 @@ export const getFeedCacheKey = (pathname: string): string | null => {
return null; return null;
} }
if (normalizedPath.includes('/modqueue')) { if (isBoardModRoute(normalizedPath) || isModQueueRoute(normalizedPath)) {
return null; return null;
} }
+2 -1
View File
@@ -82,10 +82,11 @@ export const is5chanLink = (url: string): boolean => {
// - /{boardIdentifier} (directory code or address) // - /{boardIdentifier} (directory code or address)
// - /{boardIdentifier}/thread/{commentCid} // - /{boardIdentifier}/thread/{commentCid}
// - /{boardIdentifier}/catalog // - /{boardIdentifier}/catalog
// - /{boardIdentifier}/mod/queue
// - /all, /subs, /mod, /pending/{index} // - /all, /subs, /mod, /pending/{index}
return ( return (
/^\/p\/[^/]+(\/c\/[^/]+)?$/.test(routePath) || /^\/p\/[^/]+(\/c\/[^/]+)?$/.test(routePath) ||
/^\/[^/]+(\/thread\/[^/]+|\/catalog)?$/.test(routePath) || /^\/[^/]+(\/thread\/[^/]+|\/catalog|\/mod\/queue)?$/.test(routePath) ||
/^\/(all|subscriptions|mod)(\/catalog|\/thread\/[^/]+)?(\/[^/]+)?$/.test(routePath) || /^\/(all|subscriptions|mod)(\/catalog|\/thread\/[^/]+)?(\/[^/]+)?$/.test(routePath) ||
/^\/pending\/[^/]+$/.test(routePath) /^\/pending\/[^/]+$/.test(routePath)
); );
+4 -1
View File
@@ -1,3 +1,5 @@
import { isBoardModRoute, isModQueueRoute } from './route-utils';
export type ParamsType = { export type ParamsType = {
accountCommentIndex?: string; accountCommentIndex?: string;
boardIdentifier?: string; boardIdentifier?: string;
@@ -17,6 +19,7 @@ export const isBoardView = (pathname: string, params: ParamsType): boolean => {
pathname.startsWith('/all') || pathname.startsWith('/all') ||
pathname.startsWith('/subs') || pathname.startsWith('/subs') ||
pathname.startsWith('/mod') || pathname.startsWith('/mod') ||
isBoardModRoute(pathname) ||
pathname.startsWith('/pending') || pathname.startsWith('/pending') ||
pathname === '/' || pathname === '/' ||
pathname.startsWith('/faq') || pathname.startsWith('/faq') ||
@@ -53,7 +56,7 @@ export const isModView = (pathname: string): boolean => {
}; };
export const isModQueueView = (pathname: string): boolean => { export const isModQueueView = (pathname: string): boolean => {
return pathname.includes('/modqueue'); return isModQueueRoute(pathname);
}; };
export const isPendingPostView = (pathname: string, params: ParamsType): boolean => { export const isPendingPostView = (pathname: string, params: ParamsType): boolean => {
+3 -3
View File
@@ -269,7 +269,7 @@ const ModQueueRow = memo(({ comment, isOdd = false, showBoard = false, boardPath
const threadTargetCid = threadCid || cid; const threadTargetCid = threadCid || cid;
const postUrl = boardPath && threadTargetCid ? `/${boardPath}/thread/${threadTargetCid}` : undefined; const postUrl = boardPath && threadTargetCid ? `/${boardPath}/thread/${threadTargetCid}` : undefined;
const modQueueUrl = boardPath ? `/${boardPath}/modqueue` : undefined; const modQueueUrl = boardPath ? `/${boardPath}/mod/queue` : undefined;
return ( return (
<div className={`${styles.row} ${isOdd ? styles.rowOdd : ''}`}> <div className={`${styles.row} ${isOdd ? styles.rowOdd : ''}`}>
@@ -370,7 +370,7 @@ const ModQueueCard = memo(({ comment, showBoard = false, boardPath }: ModQueueCa
const threadTargetCid = threadCid || cid; const threadTargetCid = threadCid || cid;
const postUrl = boardPath && threadTargetCid ? `/${boardPath}/thread/${threadTargetCid}` : undefined; const postUrl = boardPath && threadTargetCid ? `/${boardPath}/thread/${threadTargetCid}` : undefined;
const modQueueUrl = boardPath ? `/${boardPath}/modqueue` : undefined; const modQueueUrl = boardPath ? `/${boardPath}/mod/queue` : undefined;
return ( return (
<div className={styles.mobileCard}> <div className={styles.mobileCard}>
@@ -651,7 +651,7 @@ const ModQueueButtonContent = ({ feed, alertThresholdSeconds, boardIdentifier, i
}, [statusMap]); }, [statusMap]);
const totalCount = normalCount + urgentCount; const totalCount = normalCount + urgentCount;
const to = boardIdentifier ? `/${boardIdentifier}/modqueue` : '/mod/modqueue'; const to = boardIdentifier ? `/${boardIdentifier}/mod/queue` : '/mod/queue';
const buttonContent = ( const buttonContent = (
<button className='button'> <button className='button'>