# -*- coding: utf-8 -*-

from fastapi import FastAPI, Form, HTTPException, Request,status,APIRouter,Query,Path
from fastapi.responses import FileResponse,PlainTextResponse
from tools.loglog import logger
from tools.audio import GetAudio
from core.respone_format import *
import traceback

from make_docx_demo.main_word_applet import start_make_word as s2

router = APIRouter()

"""
@router.post("/make_word")
def make_word(json_data:dict,request:Request,
            document_format:int=Query(1,description="1:docx;2.pdf"),
            scanpage_format:int=Query(1,description="1:老版筛查表;2.新版筛查表;3.老版+新版筛查表")):
    real_ip = request.headers.get("X-Real-IP")
    logger.info(f"收到生成word请求:客户ip:{real_ip},查询参数:document_format {document_format},scanpage_format {scanpage_format},参数:{json_data}")

   
    headers = {"Content-Type": "application/octet-stream"}
    if path := start_make_word(json_data, document_format, scanpage_format):
        return FileResponse(path=path,headers=headers, media_type='application/octet-stream')
    else:
        return PlainTextResponse(status_code=500,content="服务器内部错误")
"""



@router.post("/make_word/vocabulary_assault")
def make_word(json_data:dict,request:Request,
            document_format:int=Query(1,description="1:docx;2.pdf"),
            scanpage_format:int=Query(1,description="1:老版筛查表;2.新版筛查表;3.老版+新版筛查表")):

   
    headers = {"Content-Type": "application/octet-stream"}
    if path := s2(json_data, document_format, scanpage_format):
        return FileResponse(path=path,headers=headers, media_type='application/octet-stream')
    else:
        return PlainTextResponse(status_code=500,content="服务器内部错误")