mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(directories): support multisub public keys
This commit is contained in:
@@ -23,7 +23,12 @@ import {
|
||||
|
||||
const communities = [
|
||||
{ address: 'business.eth', title: '/biz/ - Business & Finance' },
|
||||
{ address: 'music-posting.bso', title: '/mu/ - Music' },
|
||||
{
|
||||
address: 'music-posting.bso',
|
||||
name: 'music-posting.bso',
|
||||
publicKey: '12D3KooWQdQ6TkVA1Xe9zzaFP6vXBgsLeMAewpLpLwbsAYKivnQy',
|
||||
title: '/mu/ - Music',
|
||||
},
|
||||
{ address: 'random.eth', directoryCode: 'b', title: 'Random' },
|
||||
];
|
||||
|
||||
@@ -36,6 +41,7 @@ describe('directory mapping helpers', () => {
|
||||
it('maps addresses to canonical board paths and back', () => {
|
||||
expect(getBoardPath('business.eth', communities)).toBe('biz');
|
||||
expect(getBoardPath('music-posting.eth', communities)).toBe('mu');
|
||||
expect(getBoardPath('12D3KooWQdQ6TkVA1Xe9zzaFP6vXBgsLeMAewpLpLwbsAYKivnQy', communities)).toBe('mu');
|
||||
expect(getBoardPath('unknown.example', communities)).toBe('unknown.example');
|
||||
|
||||
expect(getSubplebbitAddress('biz', communities)).toBe('business.eth');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ChallengeVerification } from '@bitsocialnet/bitsocial-react-hooks';
|
||||
import directoriesData from '../../data/5chan-directories.json';
|
||||
import { getFallbackDirectoriesData } from '../../hooks/use-directories';
|
||||
import { getBoardPath } from './route-utils';
|
||||
|
||||
const resolveBoardIdentifier = (communityAddress: unknown): string => {
|
||||
@@ -7,7 +7,7 @@ const resolveBoardIdentifier = (communityAddress: unknown): string => {
|
||||
return 'unknown board';
|
||||
}
|
||||
|
||||
const boardPath = getBoardPath(communityAddress, directoriesData.communities);
|
||||
const boardPath = getBoardPath(communityAddress, getFallbackDirectoriesData().communities);
|
||||
return boardPath === communityAddress ? communityAddress : `/${boardPath}/`;
|
||||
};
|
||||
|
||||
|
||||
@@ -18,6 +18,10 @@ let cachedAddressToDirectoryMap: Map<string, string> | null = null;
|
||||
|
||||
const getDirectoryCode = (community: DirectoryCommunity): string | null => community.directoryCode ?? extractDirectoryFromTitle(community.title ?? '');
|
||||
|
||||
const getCommunityLookupAddresses = (community: DirectoryCommunity): string[] => [
|
||||
...new Set([community.address, community.name, community.publicKey].filter((value): value is string => typeof value === 'string' && value.length > 0)),
|
||||
];
|
||||
|
||||
/**
|
||||
* Create a map from directory codes to community addresses
|
||||
* Uses caching to avoid recreating the map when communities array hasn't changed
|
||||
@@ -58,7 +62,9 @@ const getAddressToDirectoryMap = (communities: DirectoryCommunity[]): Map<string
|
||||
if (!community.address) continue;
|
||||
const directory = getDirectoryCode(community);
|
||||
if (directory) {
|
||||
map.set(community.address, directory);
|
||||
for (const address of getCommunityLookupAddresses(community)) {
|
||||
map.set(address, directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user