mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-04-25 12:19:10 +00:00
improve social modes for discordbot crawler.
This commit is contained in:
parent
cd70c58cc9
commit
8dd759d78c
5 changed files with 44 additions and 5 deletions
|
@ -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')
|
||||
|
|
6
ui/pages/_internal/_discordbot/_auth.js
Normal file
6
ui/pages/_internal/_discordbot/_auth.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
import * as React from 'react'
|
||||
import SocialCards from '../../../components/social-cards'
|
||||
|
||||
export default () => <>
|
||||
<SocialCards title='Sign in on Roleypoly' />
|
||||
</>
|
6
ui/pages/_internal/_discordbot/_magic.js
Normal file
6
ui/pages/_internal/_discordbot/_magic.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
import * as React from 'react'
|
||||
import SocialCards from '../../../components/social-cards'
|
||||
|
||||
export default () => <>
|
||||
<SocialCards title='Sign in on Roleypoly' description="Click this link to log in. It's magic!" />
|
||||
</>
|
|
@ -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<ServerPageProps> {
|
||||
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<ServerPageProps> {
|
|||
}
|
||||
}
|
||||
|
||||
renderSocial () {
|
||||
const { currentServer } = this.props
|
||||
return <SocialCards title={`${currentServer.server.name} on Roleypoly`} description='Manage your roles here.' />
|
||||
}
|
||||
|
||||
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 (
|
||||
<div>
|
||||
<Head>
|
||||
<title key='title'>{currentServer.server.name} - Roleypoly</title>
|
||||
</Head>
|
||||
<SocialCards title={`${currentServer.server.name} on Roleypoly`} />
|
||||
{ this.renderSocial() }
|
||||
hello <span style={{ color: currentServer.gm.color }}>{currentServer.gm.nickname}</span> on {currentServer.server.name} ({ view.dirty ? 'dirty' : 'clean' })
|
||||
<Hider visible={true || currentServer.id !== null}>
|
||||
{ !view.invalidated && view.categories.map(c => <Category key={c.id}>
|
||||
|
|
|
@ -129,6 +129,10 @@ export default class AuthLogin extends React.Component<AuthLoginProps, AuthLogin
|
|||
redirect(ctx, r || '/')
|
||||
}
|
||||
|
||||
if (ctx.req.headers['user-agent'].contains('Discordbot')) {
|
||||
redirect(ctx, '/_internal/_discordbot/_login')
|
||||
}
|
||||
|
||||
ctx.robots = 'NOINDEX, NOFOLLOW'
|
||||
|
||||
if (r != null) {
|
||||
|
|
Loading…
Add table
Reference in a new issue