|
|
@ -2,41 +2,35 @@ import React from 'react'
|
|
|
|
import Router from 'next/router'
|
|
|
|
import Router from 'next/router'
|
|
|
|
|
|
|
|
|
|
|
|
import EmbedPage from './index'
|
|
|
|
import EmbedPage from './index'
|
|
|
|
import ApiContext from '../../components/ApiContext'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import api from '../../lib/api'
|
|
|
|
import api from '../../lib/api'
|
|
|
|
|
|
|
|
|
|
|
|
class EmbedIdPage extends React.PureComponent {
|
|
|
|
export async function getServerSideProps({ req, res, query }) {
|
|
|
|
static contextType = ApiContext
|
|
|
|
const path = query.id
|
|
|
|
static async getInitialProps({ req, res, query }) {
|
|
|
|
const parameter = path.length >= 19 && path.indexOf('.') < 0 ? path : null
|
|
|
|
const path = query.id
|
|
|
|
|
|
|
|
const parameter = path.length >= 19 && path.indexOf('.') < 0 ? path : null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let snippet
|
|
|
|
let snippet
|
|
|
|
if (parameter) {
|
|
|
|
if (parameter) {
|
|
|
|
const host = req ? req.headers.host : undefined
|
|
|
|
const host = req ? req.headers.host : undefined
|
|
|
|
snippet = await api.snippet.get(parameter, { host })
|
|
|
|
snippet = await api.snippet.get(parameter, { host })
|
|
|
|
if (snippet /* && snippet.gist_id */) {
|
|
|
|
if (snippet /* && snippet.gist_id */) {
|
|
|
|
return { snippet }
|
|
|
|
return { props: { snippet } }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 404 Not found
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
|
|
|
res.writeHead(302, {
|
|
|
|
|
|
|
|
Location: '/embed',
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
res.end()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Router.push('/embed')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {}
|
|
|
|
// 404 Not found
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
|
|
|
res.writeHead(302, {
|
|
|
|
|
|
|
|
Location: '/embed',
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
res.end()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Router.push('/embed')
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return { props: {} }
|
|
|
|
return <EmbedPage {...this.props} />
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default EmbedIdPage
|
|
|
|
export default React.memo(function EmbedIdPage(props) {
|
|
|
|
|
|
|
|
return <EmbedPage {...props} />
|
|
|
|
|
|
|
|
})
|
|
|
|