first commit
|
|
@ -0,0 +1,8 @@
|
||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# 基于编辑器的 HTTP 客户端请求
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<Languages>
|
||||||
|
<language minSize="70" name="Python" />
|
||||||
|
</Languages>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredPackages">
|
||||||
|
<value>
|
||||||
|
<list size="4">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="colorama" />
|
||||||
|
<item index="1" class="java.lang.String" itemvalue="DBUtils" />
|
||||||
|
<item index="2" class="java.lang.String" itemvalue="PyMySQL" />
|
||||||
|
<item index="3" class="java.lang.String" itemvalue="bcrypt" />
|
||||||
|
</list>
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredIdentifiers">
|
||||||
|
<list>
|
||||||
|
<option value="modules.command.*" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (fastApiTest)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/fastApiTest.iml" filepath="$PROJECT_DIR$/.idea/fastApiTest.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1704339319044" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2285" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M704 0H320a96 96 0 0 0-96 96v832a96 96 0 0 0 96 96h384a96 96 0 0 0 96-96V96a96 96 0 0 0-96-96z m32 928a32 32 0 0 1-32 32H320a32 32 0 0 1-32-32V96a32 32 0 0 1 32-32h384a32 32 0 0 1 32 32z m-224-128a64 64 0 1 0 64 64 64 64 0 0 0-64-64z m64-704h-128a32 32 0 0 0 0 64h128a32 32 0 0 0 0-64z" fill="#1B1B1B" p-id="2286"></path></svg>
|
||||||
|
After Width: | Height: | Size: 660 B |
|
|
@ -0,0 +1 @@
|
||||||
|
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1704352351942" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5421" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M512 283.456c-165.248 0-299.392 74.304-408.128 228.864 107.2 154.112 241.28 228.224 408.128 228.224 166.848 0 300.928-74.112 408.128-228.224C811.392 357.76 677.248 283.52 512 283.52zM512 832c-213.888 0-384.512-106.688-512-320 129.408-213.312 300.032-320 512-320 211.968 0 382.592 106.688 512 320-127.488 213.312-298.112 320-512 320z m0-137.152a182.848 182.848 0 1 0 0-365.696 182.848 182.848 0 0 0 0 365.696zM512 576a64 64 0 1 1 0-128 64 64 0 0 1 0 128z" fill="#262626" p-id="5422"></path></svg>
|
||||||
|
After Width: | Height: | Size: 828 B |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
|
@ -0,0 +1 @@
|
||||||
|
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1704351441252" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3422" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M746.666667 373.333333h-39.637334V294.101333A198.186667 198.186667 0 0 0 509.013333 96a198.186667 198.186667 0 0 0-198.101333 198.101333V373.333333h-39.68A79.445333 79.445333 0 0 0 192 452.565333v353.493334a79.445333 79.445333 0 0 0 79.232 79.274666H746.666667a79.445333 79.445333 0 0 0 79.274666-79.232v-353.536A79.445333 79.445333 0 0 0 746.666667 373.333333z m-197.802667 307.712a29.269333 29.269333 0 0 1-29.098667 29.525334 29.269333 29.269333 0 0 1-29.098666-29.525334v-118.186666c0-16.341333 13.013333-29.525333 29.098666-29.525334 7.978667 0 15.274667 3.328 20.522667 8.661334 5.290667 5.376 8.533333 12.757333 8.533333 20.906666v118.144zM386.133333 373.333333V294.101333a122.88 122.88 0 0 1 122.837334-122.837333 122.88 122.88 0 0 1 122.794666 122.794667V373.333333H386.133333z" fill="#000000" p-id="3423"></path></svg>
|
||||||
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
|
@ -0,0 +1 @@
|
||||||
|
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1704352142928" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4457" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M337.387283 341.82659c-17.757225 0-35.514451 11.83815-35.514451 29.595375s17.757225 29.595376 35.514451 29.595376 29.595376-11.83815 29.595376-29.595376c0-18.49711-11.83815-29.595376-29.595376-29.595375zM577.849711 513.479769c-11.83815 0-22.936416 12.578035-22.936416 23.6763 0 12.578035 11.83815 23.676301 22.936416 23.676301 17.757225 0 29.595376-11.83815 29.595376-23.676301s-11.83815-23.676301-29.595376-23.6763zM501.641618 401.017341c17.757225 0 29.595376-12.578035 29.595376-29.595376 0-17.757225-11.83815-29.595376-29.595376-29.595375s-35.514451 11.83815-35.51445 29.595375 17.757225 29.595376 35.51445 29.595376zM706.589595 513.479769c-11.83815 0-22.936416 12.578035-22.936416 23.6763 0 12.578035 11.83815 23.676301 22.936416 23.676301 17.757225 0 29.595376-11.83815 29.595376-23.676301s-11.83815-23.676301-29.595376-23.6763z" fill="#28C445" p-id="4458"></path><path d="M510.520231 2.959538C228.624277 2.959538 0 231.583815 0 513.479769s228.624277 510.520231 510.520231 510.520231 510.520231-228.624277 510.520231-510.520231-228.624277-510.520231-510.520231-510.520231zM413.595376 644.439306c-29.595376 0-53.271676-5.919075-81.387284-12.578034l-81.387283 41.433526 22.936416-71.768786c-58.450867-41.433526-93.965318-95.445087-93.965317-159.815029 0-113.202312 105.803468-201.988439 233.803468-201.98844 114.682081 0 216.046243 71.028902 236.023121 166.473989-7.398844-0.739884-14.797688-1.479769-22.196532-1.479769-110.982659 1.479769-198.289017 85.086705-198.289017 188.67052 0 17.017341 2.959538 33.294798 7.398844 49.572255-7.398844 0.739884-15.537572 1.479769-22.936416 1.479768z m346.265896 82.867052l17.757225 59.190752-63.630058-35.514451c-22.936416 5.919075-46.612717 11.83815-70.289017 11.83815-111.722543 0-199.768786-76.947977-199.768786-172.393063-0.739884-94.705202 87.306358-171.653179 198.289017-171.65318 105.803468 0 199.028902 77.687861 199.028902 172.393064 0 53.271676-34.774566 100.624277-81.387283 136.138728z" fill="#28C445" p-id="4459"></path></svg>
|
||||||
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 398 KiB |
|
After Width: | Height: | Size: 719 KiB |
|
After Width: | Height: | Size: 538 KiB |
|
|
@ -0,0 +1,94 @@
|
||||||
|
from fastapi import FastAPI, HTTPException, Request
|
||||||
|
from fastapi.responses import FileResponse
|
||||||
|
import base64
|
||||||
|
import os
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
async def root():
|
||||||
|
return {"message": "Hello World"}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/hello/{name}")
|
||||||
|
async def say_hello(name: str):
|
||||||
|
return {"message": f"Hello {name}"}
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/user/login")
|
||||||
|
async def login(request: Request):
|
||||||
|
print(request)
|
||||||
|
data = await request.json()
|
||||||
|
username = data.get("username")
|
||||||
|
password = data.get("password")
|
||||||
|
print(f"username: {username},password: {password}")
|
||||||
|
# Replace with your actual validation logic
|
||||||
|
if username == "1" and password == "1":
|
||||||
|
data1 = None
|
||||||
|
return {"code": "0", "msg": "ok", "data": data1}
|
||||||
|
else:
|
||||||
|
data2 = None
|
||||||
|
return {"code": "-1", "msg": "账号或密码错误", "data": data2}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/get-menu")
|
||||||
|
async def get_menu():
|
||||||
|
pic_list = [
|
||||||
|
{id: 1, "menu_name": "政策查询", "url": "/pages/policy/policy", "path": "assets/images/icon/政策解读.png"},
|
||||||
|
{id: 2, "menu_name": "问答", "url": "/pages/qa/qa", "path": "assets/images/icon/问答.png"},
|
||||||
|
{id: 3, "menu_name": "信息管理", "url": "/pages/assist/assist", "path": "assets/images/icon/群众信息管理.png"},
|
||||||
|
{id: 4, "menu_name": "招聘", "url": "/pages/recruit/recruit", "path": "assets/images/icon/招聘.png"}
|
||||||
|
]
|
||||||
|
data = []
|
||||||
|
for item in pic_list:
|
||||||
|
with open(item['path'], "rb") as image_file:
|
||||||
|
encoded_string = base64.b64encode(image_file.read()).decode()
|
||||||
|
data.append({
|
||||||
|
"id": item[id],
|
||||||
|
"menu_name": item['menu_name'],
|
||||||
|
"url": item['url'],
|
||||||
|
"base64EncodedImage": encoded_string
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
"code": 0,
|
||||||
|
"msg": "ok",
|
||||||
|
"data": data
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/get-swiper-list")
|
||||||
|
async def get_swiper_list():
|
||||||
|
# 设置图片所在的目录
|
||||||
|
directory = "assets/images/pictures"
|
||||||
|
base_url = "http://127.0.0.1:8000/api/swiper-image/"
|
||||||
|
|
||||||
|
# 列出目录下所有文件
|
||||||
|
files = os.listdir(directory)
|
||||||
|
for i in files:
|
||||||
|
if i == '.DS_Store':
|
||||||
|
files.remove(i)
|
||||||
|
print(files)
|
||||||
|
# 生成包含完整路径的图片列表
|
||||||
|
swiper_list = [{"id": i + 1, "path": base_url + file} for i, file in enumerate(files)]
|
||||||
|
|
||||||
|
return {
|
||||||
|
"code": 0,
|
||||||
|
"msg": "ok",
|
||||||
|
"data": swiper_list
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/swiper-image/{image_id}.png")
|
||||||
|
async def get_swiper_image(image_id: str):
|
||||||
|
base_image_path = "assets/images/pictures"
|
||||||
|
# 构造图片文件的完整路径
|
||||||
|
image_path = f"{base_image_path}/{image_id}.png" # 假设图片格式为png,根据需要修改
|
||||||
|
print(image_path)
|
||||||
|
try:
|
||||||
|
# 返回图片文件的响应
|
||||||
|
return FileResponse(image_path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
# 如果文件没有找到,返回404错误
|
||||||
|
raise HTTPException(status_code=404, detail="Image not found")
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Test your FastAPI endpoints
|
||||||
|
|
||||||
|
GET http://127.0.0.1:8000/
|
||||||
|
Accept: application/json
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
GET http://127.0.0.1:8000/hello/User
|
||||||
|
Accept: application/json
|
||||||
|
|
||||||
|
###
|
||||||