2024-03-20 00:37:31 +00:00
|
|
|
import Layout from '@/components/layout'
|
|
|
|
import { ITEM_OTS } from '@/fragments/items'
|
|
|
|
import { getGetServerSideProps } from '@/api/ssrApollo'
|
2023-01-22 20:17:50 +00:00
|
|
|
import stringifyCanon from 'canonical-json'
|
2023-07-24 18:35:05 +00:00
|
|
|
import Button from 'react-bootstrap/Button'
|
2023-07-23 15:08:43 +00:00
|
|
|
import { useQuery } from '@apollo/client'
|
|
|
|
import { useRouter } from 'next/router'
|
2024-03-20 00:37:31 +00:00
|
|
|
import PageLoading from '@/components/page-loading'
|
2023-01-22 20:17:50 +00:00
|
|
|
|
2023-08-28 17:52:15 +00:00
|
|
|
export const getServerSideProps = getGetServerSideProps({
|
|
|
|
query: ITEM_OTS,
|
|
|
|
notFound: data => !data.item || !data.item.otsHash
|
|
|
|
})
|
2023-01-22 20:17:50 +00:00
|
|
|
|
2023-07-23 15:08:43 +00:00
|
|
|
export default function OtsItem ({ ssrData }) {
|
|
|
|
const router = useRouter()
|
|
|
|
const { data } = useQuery(ITEM_OTS, { variables: { id: router.query.id } })
|
|
|
|
if (!data && !ssrData) return <PageLoading />
|
|
|
|
|
|
|
|
const { item } = data || ssrData
|
|
|
|
|
2023-01-22 20:17:50 +00:00
|
|
|
return (
|
2023-07-23 15:08:43 +00:00
|
|
|
<Layout seo={false}>
|
2023-01-22 20:17:50 +00:00
|
|
|
<Ots item={item} />
|
|
|
|
</Layout>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function Ots ({ item }) {
|
|
|
|
const itemString = stringifyCanon({ parentHash: item.parentOtsHash, title: item.title, text: item.text, url: item.url })
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className='form-label'>sha256 hash</div>
|
|
|
|
{item.otsHash}
|
|
|
|
<div className='form-label mt-2'>preimage</div>
|
|
|
|
{item.deletedAt
|
|
|
|
? <div>item was deleted by author - original preimage is lost</div>
|
|
|
|
: (
|
|
|
|
<pre
|
|
|
|
className='mb-2 p-2 rounded'
|
2023-08-05 00:21:51 +00:00
|
|
|
style={{ whiteSpace: 'pre-wrap', wordWrap: 'break-word', border: '1px solid var(--theme-borderColor)', color: 'var(--bs-body-color)' }}
|
2023-01-22 20:17:50 +00:00
|
|
|
>{itemString}
|
|
|
|
</pre>)}
|
|
|
|
<Button href={`/api/ots/preimage/${item.id}`} className='mt-1' variant='grey-medium'>download preimage</Button>
|
|
|
|
<div className='form-label mt-2'>merkle proof</div>
|
|
|
|
<Button href={`/api/ots/proof/${item.id}`} className='mt-1' variant='grey-medium'>download ots file</Button>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|