From 8dd759d78c0fd8f7fde37af61fafb77a2fe5f6d9 Mon Sep 17 00:00:00 2001 From: Kata Date: Thu, 21 Mar 2019 07:57:56 -0500 Subject: [PATCH] improve social modes for discordbot crawler. --- api/auth.js | 6 ++++++ ui/pages/_internal/_discordbot/_auth.js | 6 ++++++ ui/pages/_internal/_discordbot/_magic.js | 6 ++++++ ui/pages/_internal/_server.js | 27 +++++++++++++++++++----- ui/pages/auth/login.js | 4 ++++ 5 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 ui/pages/_internal/_discordbot/_auth.js create mode 100644 ui/pages/_internal/_discordbot/_magic.js diff --git a/api/auth.js b/api/auth.js index 5a7b91f..8f28cad 100644 --- a/api/auth.js +++ b/api/auth.js @@ -146,8 +146,14 @@ export default (R: Router, $: AppContext) => { }) R.get('/magic/:challenge', async (ctx: Context) => { + if (ctx.request.headers['user-agent'].includes('Discordbot')) { + return $.ui.render(ctx.req, ctx.res, '/_internal/_discordbot/_magic', {}) + } + const { challenge } = ((ctx.params: any): { challenge: string }) const chall = await $.auth.fetchDMChallenge({ magic: challenge }) + // log.notice('magic user agent', { ua: ctx.request.headers['User-Agent'] }) + if (chall == null) { log.warn('bad magic', challenge) return ctx.redirect('/auth/expired') diff --git a/ui/pages/_internal/_discordbot/_auth.js b/ui/pages/_internal/_discordbot/_auth.js new file mode 100644 index 0000000..c28e708 --- /dev/null +++ b/ui/pages/_internal/_discordbot/_auth.js @@ -0,0 +1,6 @@ +import * as React from 'react' +import SocialCards from '../../../components/social-cards' + +export default () => <> + + diff --git a/ui/pages/_internal/_discordbot/_magic.js b/ui/pages/_internal/_discordbot/_magic.js new file mode 100644 index 0000000..406bfdf --- /dev/null +++ b/ui/pages/_internal/_discordbot/_magic.js @@ -0,0 +1,6 @@ +import * as React from 'react' +import SocialCards from '../../../components/social-cards' + +export default () => <> + + diff --git a/ui/pages/_internal/_server.js b/ui/pages/_internal/_server.js index b372321..fcd68a0 100644 --- a/ui/pages/_internal/_server.js +++ b/ui/pages/_internal/_server.js @@ -12,7 +12,8 @@ import Role from '../../components/role' type ServerPageProps = PageProps & { currentServer: ServerState, - view: ViewState + view: ViewState, + isDiscordBot: boolean } const mapStateToProps = (state, { router: { query: { id } } }) => { @@ -33,13 +34,20 @@ const Hider = styled.div` class Server extends React.Component { static async getInitialProps (ctx: *, rpc: *, router: *) { + const isDiscordBot = ctx.req.headers['user-agent'].includes('Discordbot') if (ctx.user == null) { - redirect(ctx, `/auth/login?r=${router.asPath}`) + if (!isDiscordBot) { + redirect(ctx, `/auth/login?r=${router.asPath}`) + } } ctx.robots = 'NOINDEX, NOFOLLOW' await ctx.store.dispatch(fetchServerIfNeed(router.query.id, rpc)) - await ctx.store.dispatch(renderRoles(router.query.id)) + + if (!isDiscordBot) { + await ctx.store.dispatch(renderRoles(router.query.id)) + } + return { isDiscordBot } } async componentDidMount () { @@ -58,19 +66,28 @@ class Server extends React.Component { } } + renderSocial () { + const { currentServer } = this.props + return + } + render () { - const { currentServer, view } = this.props + const { isDiscordBot, currentServer, view } = this.props // console.log({ currentServer }) if (currentServer == null) { return null } + if (isDiscordBot) { + return this.renderSocial() + } + return (
{currentServer.server.name} - Roleypoly - + { this.renderSocial() } hello {currentServer.gm.nickname} on {currentServer.server.name} ({ view.dirty ? 'dirty' : 'clean' }) { !view.invalidated && view.categories.map(c => diff --git a/ui/pages/auth/login.js b/ui/pages/auth/login.js index c1248d1..e21eefc 100644 --- a/ui/pages/auth/login.js +++ b/ui/pages/auth/login.js @@ -129,6 +129,10 @@ export default class AuthLogin extends React.Component