Redirect NIP-19 IDs
This commit is contained in:
parent
00aa373997
commit
199f534892
3 changed files with 40 additions and 1 deletions
34
src/features/nostr/Bech32Redirect.tsx
Normal file
34
src/features/nostr/Bech32Redirect.tsx
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { nip19 } from 'nostr-tools';
|
||||
import React from 'react';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
|
||||
import MissingIndicator from 'soapbox/components/missing-indicator';
|
||||
|
||||
interface INIP19Redirect {
|
||||
params: {
|
||||
bech32: string;
|
||||
};
|
||||
}
|
||||
|
||||
const Bech32Redirect: React.FC<INIP19Redirect> = ({ params }) => {
|
||||
try {
|
||||
const result = nip19.decode(params.bech32);
|
||||
|
||||
switch (result.type) {
|
||||
case 'npub':
|
||||
case 'nprofile':
|
||||
return <Redirect to={`/@${params.bech32}`} />;
|
||||
case 'note':
|
||||
return <Redirect to={`/posts/${result.data}`} />;
|
||||
case 'nevent':
|
||||
return <Redirect to={`/posts/${result.data.id}`} />;
|
||||
default:
|
||||
return <MissingIndicator />;
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
return <MissingIndicator />;
|
||||
}
|
||||
};
|
||||
|
||||
export default Bech32Redirect;
|
|
@ -140,6 +140,7 @@ import {
|
|||
EditIdentity,
|
||||
Domains,
|
||||
NostrRelays,
|
||||
Bech32Redirect,
|
||||
} from './util/async-components';
|
||||
import GlobalHotkeys from './util/global-hotkeys';
|
||||
import { WrappedRoute } from './util/react-router-helpers';
|
||||
|
@ -284,6 +285,7 @@ const SwitchingColumnsArea: React.FC<ISwitchingColumnsArea> = ({ children }) =>
|
|||
{features.events && <WrappedRoute path='/@:username/events/:statusId' publicRoute exact page={EventPage} component={EventInformation} content={children} />}
|
||||
{features.events && <WrappedRoute path='/@:username/events/:statusId/discussion' publicRoute exact page={EventPage} component={EventDiscussion} content={children} />}
|
||||
<Redirect from='/@:username/:statusId' to='/@:username/posts/:statusId' />
|
||||
<WrappedRoute path='/posts/:statusId' publicRoute exact page={DefaultPage} component={Status} content={children} />
|
||||
|
||||
{features.groups && <WrappedRoute path='/groups' exact page={GroupsPage} component={Groups} content={children} />}
|
||||
{features.groupsDiscovery && <WrappedRoute path='/groups/discover' exact page={GroupsPage} component={GroupsDiscover} content={children} />}
|
||||
|
@ -361,6 +363,8 @@ const SwitchingColumnsArea: React.FC<ISwitchingColumnsArea> = ({ children }) =>
|
|||
<Redirect from='/auth/password/new' to='/reset-password' />
|
||||
<Redirect from='/auth/password/edit' to={`/edit-password${search}`} />
|
||||
|
||||
<WrappedRoute path='/:bech32([\x21-\x7E]{1,83}1[023456789acdefghjklmnpqrstuvwxyz]{6,})' publicRoute page={EmptyPage} component={Bech32Redirect} content={children} />
|
||||
|
||||
<WrappedRoute page={EmptyPage} component={GenericNotFound} content={children} />
|
||||
</Switch>
|
||||
);
|
||||
|
|
|
@ -170,4 +170,5 @@ export const SelectBookmarkFolderModal = lazy(() => import('soapbox/features/ui/
|
|||
export const EditIdentity = lazy(() => import('soapbox/features/edit-identity'));
|
||||
export const Domains = lazy(() => import('soapbox/features/admin/domains'));
|
||||
export const EditDomainModal = lazy(() => import('soapbox/features/ui/components/modals/edit-domain-modal'));
|
||||
export const NostrRelays = lazy(() => import('soapbox/features/nostr-relays'));
|
||||
export const NostrRelays = lazy(() => import('soapbox/features/nostr-relays'));
|
||||
export const Bech32Redirect = lazy(() => import('soapbox/features/nostr/Bech32Redirect'));
|
Loading…
Reference in a new issue