feat: サンプルのルーティングを削除
This commit is contained in:
parent
7d30331cda
commit
b7e9682be6
@ -1,44 +0,0 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, File, Form, Request, UploadFile
|
||||
|
||||
from src.templates import templates
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get('/')
|
||||
def get_view(request: Request):
|
||||
return templates.TemplateResponse(
|
||||
'sample_send_file.html',
|
||||
{
|
||||
'request': request
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@router.post('/')
|
||||
# file.readがCoroutineが返ってくるため、必ずasync関数にする
|
||||
async def post_view(
|
||||
# formからファイルを受け取る。(formタグにenctype="multipart/form-data"を指定すること)
|
||||
file: Annotated[UploadFile, File()],
|
||||
message: str = Form()
|
||||
):
|
||||
# ファイルを読み込む(Coroutineが取れるため、必ずawaitする)
|
||||
file_bytes = await file.read()
|
||||
# 閉じとく
|
||||
await file.close()
|
||||
# 読み込んだファイルはbytesで返ってくるので、デコードする
|
||||
file_content = file_bytes.decode()
|
||||
print(file_content)
|
||||
try:
|
||||
return {
|
||||
# ファイル名
|
||||
"file_name": file.filename,
|
||||
# ファイルのバイト数
|
||||
"file_size": file.size,
|
||||
# Content-Type
|
||||
"file_content_type": file.content_type
|
||||
}
|
||||
except Exception:
|
||||
return {'code': 'fail'}
|
||||
@ -7,7 +7,6 @@ from starlette import status
|
||||
import src.static as static
|
||||
from src.controller import (bio, bio_download, healthcheck, login, logout,
|
||||
master_mainte, menu, root, ultmarc)
|
||||
from src.controller.sample_send_file import router as sample_router
|
||||
from src.core import tasks
|
||||
from src.error.exception_handler import http_exception_handler
|
||||
from src.error.exceptions import UnexpectedException
|
||||
@ -36,9 +35,6 @@ app.include_router(master_mainte.router, prefix='/masterMainte')
|
||||
# ヘルスチェック用のルーター
|
||||
app.include_router(healthcheck.router, prefix='/healthcheck')
|
||||
|
||||
# サンプル実装、ファイル送信ルーター
|
||||
app.include_router(sample_router, prefix='/sample')
|
||||
|
||||
# エラー発生時にログアウト画面に遷移させるハンドラー
|
||||
app.add_exception_handler(status.HTTP_401_UNAUTHORIZED, http_exception_handler)
|
||||
app.add_exception_handler(status.HTTP_403_FORBIDDEN, http_exception_handler)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user