import type {NextApiRequest,NextApiResponse} from 'next'; import {serveApiDocumentation} from '@/lib/api-documentation'; import {sameOrigin,apiError} from '@/lib/api'; import {archiveInput,postIdentifier,setPostArchived} from '@/lib/post-archive'; export default async function handler(req:NextApiRequest,res:NextApiResponse){ if(serveApiDocumentation(req,res,'/api/posts/{id}/archive'))return; res.setHeader('Cache-Control','no-store');if(req.method!=='POST'){res.setHeader('Allow','POST');return res.status(405).end()} try{sameOrigin(req);const post=await setPostArchived(postIdentifier.parse(req.query.id),archiveInput.parse(req.body).archived);return post?res.json({post}):res.status(404).json({error:'笔记不存在'})}catch(error){return apiError(res,error)} } export const config={api:{bodyParser:{sizeLimit:'1kb'}}};