DataFront/server/api/tools/qqazk/details.ts

49 lines
982 B
TypeScript

import {readFile, readFileSync} from "fs";
interface Word{
bsm:string
hz:string
pyJs:string[]
id:number
}
interface Ret{
data:Word
message:string
haveMess:boolean
}
let words:Word[] = []
const loadWords = ()=>{
const wordRaw = readFileSync('./word.json','utf-8')
words = JSON.parse(wordRaw)
for (let i = 0; i< words.length ; i++){
words[i].id =i;
}
}
export default defineEventHandler((event):Ret=>{
if (words.length===0){
loadWords()
}
const query = getQuery(event)
if (query.id=="错误"){
return {
data:words[0],
message:"参数错误",
haveMess:true
}
}
// @ts-ignore
if (query.id>=words.length){
return {
data:words[0],
message:"参数越界",
haveMess:true
}
}
return {
// @ts-ignore
data:words[query.id],
message:"",
haveMess:false
}
})