main.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. import xml.etree.ElementTree as ET
  2. from typing import Union
  3. from fastapi import FastAPI
  4. import os
  5. import uuid
  6. import re
  7. import zipfile
  8. import json
  9. from fastapi.middleware.cors import CORSMiddleware
  10. from fastapi.middleware.gzip import GZipMiddleware
  11. import base64
  12. from pydantic import BaseModel
  13. from subdir import service
  14. from subdir import db
  15. from subdir import util
  16. import xml.dom.minidom as MD
  17. import numpy as np
  18. from fastapi.staticfiles import StaticFiles
  19. from pymongo import AsyncMongoClient
  20. client = AsyncMongoClient()
  21. from fastapi.responses import FileResponse
  22. from fastapi import WebSocket, WebSocketDisconnect
  23. from fastapi import UploadFile
  24. class ConnectionManager:
  25. """Class defining socket events"""
  26. def __init__(self):
  27. """init method, keeping track of connections"""
  28. self.active_connections = []
  29. async def connect(self, websocket: WebSocket):
  30. """connect event"""
  31. await websocket.accept()
  32. self.active_connections.append(websocket)
  33. async def send_personal_message(self, message: str, websocket: WebSocket):
  34. """Direct Message"""
  35. await websocket.send_text(message)
  36. def disconnect(self, websocket: WebSocket):
  37. """disconnect event"""
  38. self.active_connections.remove(websocket)
  39. app = FastAPI()
  40. origins = [
  41. "http://localhost.tiangolo.com",
  42. "https://localhost.tiangolo.com",
  43. "http://localhost",
  44. "http://localhost:9002",
  45. "http://127.0.0.1:9002",
  46. ]
  47. app.add_middleware(
  48. CORSMiddleware,
  49. allow_origins=["*"],
  50. allow_credentials=True,
  51. allow_methods=["*"],
  52. allow_headers=["*"],
  53. )
  54. app.add_middleware(GZipMiddleware, minimum_size=1000, compresslevel=5)
  55. app.mount("/static", StaticFiles(directory="front/dist"), name="static")
  56. manager = ConnectionManager()
  57. for root, dirs, files in os.walk("./data", topdown=False):
  58. for name in files:
  59. print(os.path.join(root, name))
  60. file_data = os.path.join(root, name)
  61. def getDetail(root):
  62. print(root.tag)
  63. print(root.text)
  64. print(root.attrib)
  65. result = []
  66. result.append(["名称", "金额", "暂估价", "安全文明施工费", "规费"])
  67. for child in root:
  68. print(child.tag)
  69. print(child.attrib)
  70. if child.tag == "TouBiaoXx":
  71. result.append([child.attrib["Zbr"], child.attrib["Tbzj"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  72. if child.tag == "Dxgcxx":
  73. Dxgcbh = child.attrib["Dxgcbh"]
  74. Dxgcmc = child.attrib["Dxgcmc"]
  75. result.append([child.attrib["Dxgcmc"], child.attrib["Je"], child.attrib["Zgj"], child.attrib["Aqwmf"], child.attrib["Gf"]])
  76. return result
  77. def getOutline(root):
  78. print(root.tag)
  79. print(root.text)
  80. print(root.attrib)
  81. result = []
  82. for child in root:
  83. print(child.tag)
  84. print(child.attrib)
  85. if child.tag == "TouBiaoXx":
  86. result.append({"id" : "TouBiaoXx", "label" : "投标信息" })
  87. if child.tag == "Dxgcxx":
  88. Dxgcbh = child.attrib["Dxgcbh"]
  89. Dxgcmc = child.attrib["Dxgcmc"]
  90. result2 = []
  91. for child1 in child:
  92. #print("level2===================================")
  93. #print(child1.tag)
  94. #print(child1.attrib)
  95. Dwgcbh = child1.attrib["Dwgcbh"]
  96. Dwgcmc = child1.attrib["Dwgcmc"]
  97. Zylb = child1.attrib["Zylb"]
  98. result2.append({"id" : Dwgcbh,"Zylb":Zylb, "label": Dwgcmc, "children" : service.getDwgc(root, Dwgcbh, Zylb)})
  99. result.append({"id" : Dxgcbh, "label" : Dxgcmc, "children" : result2})
  100. return result
  101. class Info(BaseModel):
  102. name: str
  103. class DingeshuRequest(BaseModel):
  104. value: int
  105. class DingeXilieRequest(BaseModel):
  106. value: int
  107. id: str
  108. class SingleDingeXilieRequest(BaseModel):
  109. zhuanye: int
  110. debh: str
  111. class InfoWithID(BaseModel):
  112. name: str
  113. id: str
  114. class Tiaojia(BaseModel):
  115. biao_id: str
  116. bh: str
  117. bm: str
  118. mingcheng: str
  119. danwei: str
  120. jiage: str
  121. glf: str
  122. lr: str
  123. bz: int
  124. class SearchDe(BaseModel):
  125. zhuanye: str
  126. text: str
  127. class UpdateZjcs(BaseModel):
  128. biao_id: str
  129. bh: str
  130. mc: str
  131. fl: str
  132. @app.post("/outline")
  133. async def read_root(info: Info):
  134. for root, dirs, files in os.walk("./data", topdown=False):
  135. for name in files:
  136. if name == info.name:
  137. print(os.path.join(root, name))
  138. file_data = os.path.join(root, name)
  139. tree = ET.parse(file_data)
  140. root = tree.getroot()
  141. return getOutline(root)
  142. @app.post("/outline2")
  143. async def read_root2(info: Info):
  144. return await db.getOutline(client, info.name)
  145. @app.post("/detail")
  146. async def read_detail(info: Info):
  147. for root, dirs, files in os.walk("./data", topdown=False):
  148. for name in files:
  149. if name == info.name:
  150. print(os.path.join(root, name))
  151. file_data = os.path.join(root, name)
  152. tree = ET.parse(file_data)
  153. root = tree.getroot()
  154. return getDetail(root)
  155. @app.post("/detail2")
  156. async def read_detail2(info: Info):
  157. return await db.getDetail(client, info.name)
  158. @app.post("/baojiahuizong/")
  159. async def read_bjhz(info: InfoWithID):
  160. for root, dirs, files in os.walk("./data", topdown=False):
  161. for name in files:
  162. if name == info.name:
  163. print(os.path.join(root, name))
  164. file_data = os.path.join(root, name)
  165. tree = ET.parse(file_data)
  166. root = tree.getroot()
  167. return service.getBjhz(root, info.id)
  168. @app.post("/baojiahuizong2/")
  169. async def read_bjhz2(info: InfoWithID):
  170. raw = await db.getBjhz(client, info.name, info.id)
  171. raw2 = []
  172. for entry in raw:
  173. if "__children" in entry:
  174. entry["_children"] = entry["__children"]
  175. for grandchild in entry["_children"]:
  176. if "__children" in grandchild:
  177. grandchild['_children'] = grandchild['__children']
  178. del grandchild['__children']
  179. del entry["__children"]
  180. raw2.append(entry)
  181. return raw2
  182. @app.post("/guifeishuijin/")
  183. async def read_gfsj(info: InfoWithID):
  184. for root, dirs, files in os.walk("./data", topdown=False):
  185. for name in files:
  186. if name == info.name:
  187. print(os.path.join(root, name))
  188. file_data = os.path.join(root, name)
  189. tree = ET.parse(file_data)
  190. root = tree.getroot()
  191. return service.getGfsj(root, info.id)
  192. @app.post("/guifeishuijin2/")
  193. async def read_gfsj2(info: InfoWithID):
  194. raw = await db.getGfsj(client, info.name, info.id)
  195. raw2 = []
  196. for entry in raw:
  197. if "__children" in entry:
  198. entry["_children"] = entry["__children"]
  199. del entry["__children"]
  200. raw2.append(entry)
  201. return raw2
  202. @app.post("/qitaxiangmu/")
  203. async def read_qtxm(info: InfoWithID):
  204. for root, dirs, files in os.walk("./data", topdown=False):
  205. for name in files:
  206. if name == info.name:
  207. print(os.path.join(root, name))
  208. file_data = os.path.join(root, name)
  209. tree = ET.parse(file_data)
  210. root = tree.getroot()
  211. return service.getQtxm(root, info.id)
  212. @app.post("/qitaxiangmu2/")
  213. async def read_qtxm2(info: InfoWithID):
  214. raw = await db.getQtxm(client, info.name, info.id)
  215. raw2 = []
  216. for entry in raw:
  217. if "__children" in entry:
  218. entry["_children"] = entry["__children"]
  219. del entry["__children"]
  220. raw2.append(entry)
  221. return raw2
  222. @app.post("/zygczgj/")
  223. async def zygczgj(info: InfoWithID):
  224. return await db.getZygczgj(client, info.name, info.id)
  225. @app.post("/zanliejine/")
  226. async def read_zlje(info: InfoWithID):
  227. for root, dirs, files in os.walk("./data", topdown=False):
  228. for name in files:
  229. if name == info.name:
  230. print(os.path.join(root, name))
  231. file_data = os.path.join(root, name)
  232. tree = ET.parse(file_data)
  233. root = tree.getroot()
  234. return service.getZlje(root, info.id)
  235. @app.post("/zanliejine2/")
  236. async def read_zlje2(info: InfoWithID):
  237. return await db.getZlje(client, info.name, info.id)
  238. @app.post("/jirigong/")
  239. async def read_jrg(info: InfoWithID):
  240. for root, dirs, files in os.walk("./data", topdown=False):
  241. for name in files:
  242. if name == info.name:
  243. print(os.path.join(root, name))
  244. file_data = os.path.join(root, name)
  245. tree = ET.parse(file_data)
  246. root = tree.getroot()
  247. return service.getJrg(root, info.id)
  248. @app.post("/jirigong2/")
  249. async def read_jrg2(info: InfoWithID):
  250. return await db.getJrg(client, info.name, info.id)
  251. @app.post("/zongchengbaofuwufei/")
  252. async def read_zcbfwf(info: InfoWithID):
  253. for root, dirs, files in os.walk("./data", topdown=False):
  254. for name in files:
  255. if name == info.name:
  256. print(os.path.join(root, name))
  257. file_data = os.path.join(root, name)
  258. tree = ET.parse(file_data)
  259. root = tree.getroot()
  260. return service.getZcbfwf(root, info.id)
  261. @app.post("/zongchengbaofuwufei2/")
  262. async def read_zcbfwf2(info: InfoWithID):
  263. return await db.getZcbfwf(client, info.name, info.id)
  264. @app.post("/fabaorengongyingcailiao/")
  265. async def read_fbrgycl(info: InfoWithID):
  266. for root, dirs, files in os.walk("./data", topdown=False):
  267. for name in files:
  268. if name == info.name:
  269. print(os.path.join(root, name))
  270. file_data = os.path.join(root, name)
  271. tree = ET.parse(file_data)
  272. root = tree.getroot()
  273. return service.getFbrgycl(root, info.id)
  274. @app.post("/fabaorengongyingcailiao2/")
  275. async def read_fbrgycl2(info: InfoWithID):
  276. return await db.getFbrgycl(client, info.name, info.id)
  277. @app.post("/rencaijihuizong/")
  278. async def read_rcjhz(info: InfoWithID):
  279. for root, dirs, files in os.walk("./data", topdown=False):
  280. for name in files:
  281. if name == info.name:
  282. print(os.path.join(root, name))
  283. file_data = os.path.join(root, name)
  284. tree = ET.parse(file_data)
  285. root = tree.getroot()
  286. return service.getRcjhz(root, info.id)
  287. @app.post("/rencaijihuizong2/")
  288. async def read_rcjhz2(info: InfoWithID):
  289. return await db.getRcjhz(client, info.name, info.id)
  290. @app.post("/qingdanxiangmu/")
  291. async def read_qdxm(info: InfoWithID):
  292. for root, dirs, files in os.walk("./data", topdown=False):
  293. for name in files:
  294. if name == info.name:
  295. print(os.path.join(root, name))
  296. file_data = os.path.join(root, name)
  297. tree = ET.parse(file_data)
  298. root = tree.getroot()
  299. return service.getQdxm(root, info.id)
  300. #return []
  301. @app.post("/qingdanxiangmu2/")
  302. async def read_qdxm2(info: InfoWithID):
  303. return await db.getQdxm(client, info.name, info.id)
  304. class Item(BaseModel):
  305. bh: str
  306. bt: str
  307. name: str
  308. class Rcj(BaseModel):
  309. bh: str
  310. bt: str
  311. bm: str
  312. name: str
  313. class Dercj(BaseModel):
  314. bh: str
  315. bt: str
  316. qdbm: str
  317. debm: str
  318. name: str
  319. class Zjcs(BaseModel):
  320. bh: str
  321. name: str
  322. @app.post("/qingdanmingxi/")
  323. async def read_qdmx(item : Item):
  324. return await db.getQdmx(client, item.name, item.bh, item.bt)
  325. @app.post("/qingdanrcj/")
  326. async def read_rcj(item : Rcj):
  327. if item.bt == "Djcs":
  328. return await db.getDjcsQingdanrcj(client, item.name, item.bh, item.bt, item.bm)
  329. return await db.getQingdanrcj(client, item.name, item.bh, item.bt, item.bm)
  330. @app.post("/qingdantuijian/")
  331. async def read_tuijian(item : Rcj):
  332. return service.getQingdanTuijian(item.bh, item.bt, item.bm)
  333. @app.post("/dingercj/")
  334. async def read_dercj(item : Dercj):
  335. if item.bt == "Djcs":
  336. return await db.getDjcsDingercj(client, item.name, item.bh, item.bt, item.qdbm, item.debm)
  337. return await db.getDingercj(client, item.name, item.bh, item.bt, item.qdbm, item.debm)
  338. @app.post("/zjcs/")
  339. async def read_zjcs(item : Zjcs):
  340. raw = await db.getZjcs(client, item.name, item.bh)
  341. raw2 = []
  342. for entry in raw:
  343. if "__children" in entry:
  344. entry["_children"] = entry["__children"]
  345. del entry["__children"]
  346. raw2.append(entry)
  347. return raw2
  348. @app.post("/djcs/")
  349. async def read_djcs(item : Zjcs):
  350. raw = await db.getDjcs(client, item.name, item.bh)
  351. raw2 = []
  352. for entry in raw:
  353. if "__children" in entry:
  354. entry["_children"] = entry["__children"]
  355. del entry["__children"]
  356. raw2.append(entry)
  357. return raw2
  358. @app.post("/files/")
  359. async def read_files():
  360. result = []
  361. for root, dirs, files in os.walk("./data", topdown=False):
  362. for name in files:
  363. print(os.path.join(root, name))
  364. result.append([name, "", ""])
  365. return result
  366. @app.post("/files2/")
  367. async def read_files2():
  368. result = await db.list_files(client)
  369. return result
  370. @app.post("/deleteFile/")
  371. async def delete(r: Info):
  372. result = await db.delete_files(client, r.name)
  373. return result
  374. @app.post("/des/")
  375. async def read_des(r: DingeshuRequest):
  376. result = service.getDes(r.value)
  377. #print(result)
  378. return result
  379. @app.post("/pbs/")
  380. async def read_pbs(r: DingeshuRequest):
  381. result = service.getPbs(r.value)
  382. #print(result)
  383. result.insert(0, {"id": "0", "label": "全部"})
  384. return result
  385. @app.post("/pbxl/")
  386. async def read_pbxl(r: Info):
  387. result = service.getPbxl(r.name)
  388. #print(result)
  389. return result
  390. @app.post("/cankao/")
  391. async def cankao():
  392. result = service.getCankao()
  393. #print(result)
  394. return result
  395. @app.post("/qufei/")
  396. async def read_qufei(r: Info):
  397. return await db.getQufei(client, r.name)
  398. @app.post("/dexilie/")
  399. async def read_dexilie(r: DingeXilieRequest):
  400. result = service.getDeXilie(r.value, r.id)
  401. #print(result)
  402. return result
  403. @app.post("/singledexilie/")
  404. async def read_singledexilie(r: SingleDingeXilieRequest):
  405. if r.debh.startswith("D") :
  406. return json.dumps({
  407. "reverse": "None",
  408. "rgde": None,
  409. "jxde": None,
  410. "clde": None,
  411. "actual_zhuanye": r.zhuanye,
  412. "bz_selected": {"BZBH": {}},
  413. "bz_selected2": {"BZBH": {}}
  414. }, ensure_ascii=False)
  415. result1, result2, rgde, jxde, clde, bz_selected, bz_selected2, actual_zhuanye= service.getSingleDeXilie(r.zhuanye, r.debh)
  416. print("get result ***************************************")
  417. if result1:
  418. result3 = json.loads(result1)
  419. else:
  420. result3 = {}
  421. result3["reverse"] = str(result2)
  422. result3["rgde"] = rgde
  423. result3["jxde"] = jxde
  424. result3["clde"] = clde
  425. result3["actual_zhuanye"] = actual_zhuanye
  426. if bz_selected != None:
  427. result3["bz_selected"] = json.loads(bz_selected)
  428. else:
  429. result3["bz_selected"] = {"BZBH": {}}
  430. if bz_selected2 != None:
  431. result3["bz_selected2"] = json.loads(bz_selected2)
  432. else:
  433. result3["bz_selected2"] = {"BZBH": {}}
  434. if "[" in r.debh:
  435. position3 = r.debh.find("*")
  436. coef = 1
  437. if position3 == -1:
  438. pass
  439. else:
  440. coef = r.debh[1 + position3:]
  441. print(coef)
  442. tail = 0
  443. for i in range(0, len(coef) + 1):
  444. if i == len(coef):
  445. tail = i
  446. break
  447. if coef[i] > '9' or coef[i] < '0':
  448. tail = i
  449. break
  450. if tail == 0:
  451. print("1113111")
  452. result3["reverse"] = 'None'
  453. return json.dumps(result3, ensure_ascii=False)
  454. coef = int(coef[0:tail])
  455. position1 = r.debh.find("[")
  456. position2 = r.debh.find("]")
  457. if position2 == -1:
  458. print("1121111")
  459. result3["reverse"] = 'None'
  460. return json.dumps(result3, ensure_ascii=False)
  461. if r.debh[position1-1] == "+":
  462. pass
  463. elif r.debh[position1-1] == "-":
  464. coef = -coef
  465. else:
  466. print("111111")
  467. result3["reverse"] = 'None'
  468. return json.dumps(result3, ensure_ascii=False)
  469. debh = r.debh[position1+1: position2]
  470. if result3['GLDE']: ##csv文件里的字段,表示这个定额有没有配套的增减定额
  471. hit = False
  472. for key, value in result3['GLDE'].items():
  473. if value == debh:
  474. hit = True
  475. if not hit:
  476. result3["reverse"] = 'None'
  477. return json.dumps(result3, ensure_ascii=False)
  478. else:
  479. result3["reverse"] = 'None'
  480. return json.dumps(result3, ensure_ascii=False)
  481. result1_, result2_, rgde_, jxde_, clde_, bz_selected_, bz_selected2_, actual_zhuanye_ = service.getSingleDeXilie(r.zhuanye, debh)
  482. if result1_:
  483. util.mergerg(rgde, rgde_, coef)
  484. util.mergejx(jxde, jxde_, coef)
  485. util.mergecl(clde, clde_, coef)
  486. result3["rgde"] = rgde
  487. result3["jxde"] = jxde
  488. result3["clde"] = clde
  489. item_ = None
  490. for item in result3['DW'].keys():
  491. item_ = item
  492. result3['DEBH'] = {item_: util.cleanBM(r.debh)}
  493. else:
  494. result3["reverse"] = 'None'
  495. return json.dumps(result3, ensure_ascii=False)
  496. @app.post("/save/")
  497. async def save(r: Info):
  498. data = json.loads(r.name)
  499. print(data)
  500. return await db.save(client, data)
  501. @app.post("/savedjcs/")
  502. async def savedjcs(r: Info):
  503. data = json.loads(r.name)
  504. print(data)
  505. return await db.savedjcs(client, data)
  506. @app.post("/applyFL/")
  507. async def applyFL(r: InfoWithID):
  508. data = json.loads(r.name)
  509. print(data)
  510. return await db.applyFL(client, r.id, data)
  511. @app.post("/tiaojia/")
  512. async def tiaojia(r: Tiaojia):
  513. ##return []
  514. glf = r.glf
  515. lr = r.lr
  516. if r.glf == '':
  517. glf = '0'
  518. if r.lr == "":
  519. lr = '0'
  520. return await db.tiaojia(client, r.biao_id, r.bh, r.bm, r.mingcheng, r.danwei, r.jiage, glf, lr, r.bz)
  521. @app.post("/searchde/")
  522. async def searchde(r: SearchDe):
  523. ##return []
  524. return await db.searchde(client, r.zhuanye, r.text)
  525. @app.post("/updatezjcs/")
  526. async def updatezjcs(r: UpdateZjcs):
  527. ##return []
  528. return await db.updatezjcs(client, r.biao_id, r.bh, r.mc, r.fl)
  529. @app.post("/upload/")
  530. async def upload(file: UploadFile):
  531. if file.filename.endswith('13jz') or file.filename.endswith("13jt"):
  532. content = await file.read()
  533. string = content.decode('utf-8')
  534. await resolve(string)
  535. return [file.filename]
  536. elif file.filename.endswith("jszf"):
  537. content = await file.read()
  538. string = content.decode('utf-8')
  539. root = ET.fromstring(string)
  540. for child in root:
  541. print(child)
  542. if child.tag == "ZBFileContent":
  543. base64_bytes = child.text.encode("ascii")
  544. sample_string_bytes = base64.b64decode(base64_bytes)
  545. tmp = str(uuid.uuid4())
  546. os.mkdir(os.path.join("tmp", tmp))
  547. with open(tmp, "wb") as file_:
  548. file_.write(sample_string_bytes)
  549. with zipfile.ZipFile(tmp, 'r') as zip_ref:
  550. zip_ref.extractall(os.path.join("tmp", tmp))
  551. dir_list = os.listdir(os.path.join("tmp", tmp))
  552. print(dir_list)
  553. for entry in dir_list:
  554. if entry.endswith("13jz"):
  555. with open(os.path.join("tmp", tmp, entry), 'r') as f:
  556. await resolve(f.read())
  557. return [file.filename]
  558. else:
  559. return [file.filename]
  560. @app.get("/download/{item_id}")
  561. async def download_file(item_id):
  562. file_path = "export/contacts.xml.b"
  563. # Create the root element
  564. root = ET.Element("JingJiBiao")
  565. # Create a sub-element
  566. ##TouBiaoXx = ET.SubElement(root, "TouBiaoXx")
  567. await db.build(client, root, item_id)
  568. # Create the tree and write to a file
  569. tree = ET.ElementTree(root)
  570. tree.write("export/contacts.xml", encoding="utf-8")
  571. dom = MD.parse("export/contacts.xml")
  572. with open("export/contacts.xml.b", 'w') as f:
  573. f.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n")
  574. content = (dom.toprettyxml(indent=" "))
  575. content_ = content.split("\n")
  576. f.write("\n".join(content_[1:]))
  577. return FileResponse(file_path, media_type='application/octet-stream', filename="contacts.xml")
  578. async def resolve(data):
  579. await db.resolve(data, client)##manager.send_personal_message(f"You wrote: {data}", websocket)
  580. @app.websocket("/ws")
  581. async def websocket_endpoint(websocket: WebSocket):
  582. await manager.connect(websocket)
  583. try:
  584. while True:
  585. data = await websocket.receive_text()
  586. await resolve(websocket, data)
  587. ##await manager.broadcast(f"Client #{client_id} says: {data}")
  588. except WebSocketDisconnect:
  589. manager.disconnect(websocket)
  590. ##await manager.broadcast(f"Client left the chat")