2024-03-20 00:37:31 +00:00
|
|
|
import getSSRApolloClient from '@/api/ssrApollo'
|
|
|
|
import { ITEM_OTS } from '@/fragments/items'
|
2023-01-22 20:17:50 +00:00
|
|
|
import stringifyCanon from 'canonical-json'
|
|
|
|
|
|
|
|
export default async function handler (req, res) {
|
2023-07-29 19:38:20 +00:00
|
|
|
const client = await getSSRApolloClient({ req, res })
|
2023-01-22 20:17:50 +00:00
|
|
|
const { data } = await client.query({
|
|
|
|
query: ITEM_OTS,
|
|
|
|
variables: { id: req.query.id }
|
|
|
|
})
|
|
|
|
|
|
|
|
if (!data?.item) {
|
|
|
|
res.status(404).end()
|
|
|
|
}
|
|
|
|
|
|
|
|
const { item } = data
|
|
|
|
const itemString = stringifyCanon({ parentHash: item.parentOtsHash, title: item.title, text: item.text, url: item.url })
|
|
|
|
|
|
|
|
res.setHeader('Content-Type', 'application/json')
|
|
|
|
res.setHeader('Content-Disposition', `attachment; filename="sn-item-${req.query.id}.json"`)
|
|
|
|
res.write(itemString)
|
|
|
|
res.status(200).end()
|
|
|
|
}
|