mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-04-28 21:49: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) => {
|
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 { challenge } = ((ctx.params: any): { challenge: string })
|
||||||
const chall = await $.auth.fetchDMChallenge({ magic: challenge })
|
const chall = await $.auth.fetchDMChallenge({ magic: challenge })
|
||||||
|
// log.notice('magic user agent', { ua: ctx.request.headers['User-Agent'] })
|
||||||
|
|
||||||
if (chall == null) {
|
if (chall == null) {
|
||||||
log.warn('bad magic', challenge)
|
log.warn('bad magic', challenge)
|
||||||
return ctx.redirect('/auth/expired')
|
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 & {
|
type ServerPageProps = PageProps & {
|
||||||
currentServer: ServerState,
|
currentServer: ServerState,
|
||||||
view: ViewState
|
view: ViewState,
|
||||||
|
isDiscordBot: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state, { router: { query: { id } } }) => {
|
const mapStateToProps = (state, { router: { query: { id } } }) => {
|
||||||
|
@ -33,13 +34,20 @@ const Hider = styled.div`
|
||||||
|
|
||||||
class Server extends React.Component<ServerPageProps> {
|
class Server extends React.Component<ServerPageProps> {
|
||||||
static async getInitialProps (ctx: *, rpc: *, router: *) {
|
static async getInitialProps (ctx: *, rpc: *, router: *) {
|
||||||
|
const isDiscordBot = ctx.req.headers['user-agent'].includes('Discordbot')
|
||||||
if (ctx.user == null) {
|
if (ctx.user == null) {
|
||||||
redirect(ctx, `/auth/login?r=${router.asPath}`)
|
if (!isDiscordBot) {
|
||||||
|
redirect(ctx, `/auth/login?r=${router.asPath}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.robots = 'NOINDEX, NOFOLLOW'
|
ctx.robots = 'NOINDEX, NOFOLLOW'
|
||||||
await ctx.store.dispatch(fetchServerIfNeed(router.query.id, rpc))
|
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 () {
|
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 () {
|
render () {
|
||||||
const { currentServer, view } = this.props
|
const { isDiscordBot, currentServer, view } = this.props
|
||||||
// console.log({ currentServer })
|
// console.log({ currentServer })
|
||||||
if (currentServer == null) {
|
if (currentServer == null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isDiscordBot) {
|
||||||
|
return this.renderSocial()
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Head>
|
<Head>
|
||||||
<title key='title'>{currentServer.server.name} - Roleypoly</title>
|
<title key='title'>{currentServer.server.name} - Roleypoly</title>
|
||||||
</Head>
|
</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' })
|
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}>
|
<Hider visible={true || currentServer.id !== null}>
|
||||||
{ !view.invalidated && view.categories.map(c => <Category key={c.id}>
|
{ !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 || '/')
|
redirect(ctx, r || '/')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ctx.req.headers['user-agent'].contains('Discordbot')) {
|
||||||
|
redirect(ctx, '/_internal/_discordbot/_login')
|
||||||
|
}
|
||||||
|
|
||||||
ctx.robots = 'NOINDEX, NOFOLLOW'
|
ctx.robots = 'NOINDEX, NOFOLLOW'
|
||||||
|
|
||||||
if (r != null) {
|
if (r != null) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue