2023-08-30 07:46:11 +00:00
|
|
|
import {readFile, readFileSync} from "fs";
|
2023-08-27 10:15:04 +00:00
|
|
|
import path from "path";
|
|
|
|
interface Word{
|
|
|
|
bsm:string
|
|
|
|
hz:string
|
|
|
|
pyJs:string[]
|
2023-08-27 16:30:58 +00:00
|
|
|
id:number
|
2023-08-27 10:15:04 +00:00
|
|
|
}
|
|
|
|
interface Ret{
|
2023-08-27 16:30:58 +00:00
|
|
|
data:Word[]
|
2023-08-27 10:15:04 +00:00
|
|
|
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
|
|
|
}
|
2023-08-30 07:46:11 +00:00
|
|
|
}
|
|
|
|
|
2023-08-27 10:15:04 +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 retWords:Word[] = []
|
|
|
|
const query = getQuery(event)
|
2023-08-30 07:46:11 +00:00
|
|
|
// @ts-ignore
|
2023-08-27 16:30:58 +00:00
|
|
|
if (query.words=="错误"||query.method=="错误"||!(query.method=="bsmf"||query.method=="bsmc"||query.method=="hz")||query.words.length>20){
|
|
|
|
return {
|
|
|
|
data:[],
|
|
|
|
message:"参数错误",
|
|
|
|
haveMess:true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const word:string = query.words as unknown as string
|
|
|
|
if (word==""){
|
|
|
|
return {
|
|
|
|
data:words,
|
|
|
|
message:"",
|
|
|
|
haveMess:false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (query.method=="hz"){
|
|
|
|
for (let i =0;i<word.length;i++){
|
|
|
|
for (let j=0;j<words.length;j++){
|
|
|
|
if (words[j].hz.includes(word[i])){
|
|
|
|
let newWords:Word = words[j]
|
|
|
|
retWords.push(newWords)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else if (query.method=="bsmf"){
|
|
|
|
words.forEach((wf,index)=>{
|
|
|
|
if (wf.bsm.startsWith(word)) retWords.push(wf)
|
|
|
|
})
|
|
|
|
}else if(query.method=="bsmc"){
|
|
|
|
words.forEach((wf,index)=>{
|
|
|
|
if (wf.bsm.includes(word)) retWords.push(wf)
|
|
|
|
})
|
|
|
|
}
|
2023-08-27 10:15:04 +00:00
|
|
|
return {
|
2023-08-27 16:30:58 +00:00
|
|
|
data:retWords,
|
2023-08-27 10:15:04 +00:00
|
|
|
message:"",
|
|
|
|
haveMess:false
|
|
|
|
}
|
|
|
|
})
|