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

49 lines
982 B
TypeScript
Raw Normal View History

2023-08-30 07:46:11 +00:00
import {readFile, readFileSync} from "fs";
2023-08-27 16:30:58 +00:00
interface Word{
bsm:string
hz:string
pyJs:string[]
id:number
}
interface Ret{
data:Word
message:string
haveMess:boolean
}
2023-08-30 07:46:11 +00:00
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;
}
}
2023-08-27 16:30:58 +00:00
export default defineEventHandler((event):Ret=>{
2023-08-30 07:46:11 +00:00
if (words.length===0){
loadWords()
}
2023-08-27 16:30:58 +00:00
const query = getQuery(event)
if (query.id=="错误"){
return {
data:words[0],
message:"参数错误",
haveMess:true
}
}
2023-08-30 07:46:11 +00:00
// @ts-ignore
2023-08-27 16:30:58 +00:00
if (query.id>=words.length){
return {
data:words[0],
message:"参数越界",
haveMess:true
}
}
2023-08-30 07:46:11 +00:00
2023-08-27 16:30:58 +00:00
return {
2023-08-30 07:46:11 +00:00
// @ts-ignore
2023-08-27 16:30:58 +00:00
data:words[query.id],
message:"",
haveMess:false
}
})