@@ -2,14 +2,24 @@ import datetime
|
||||
import uuid
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI, Depends, UploadFile, Form, File, HTTPException, BackgroundTasks
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import HTMLResponse, FileResponse
|
||||
from starlette.staticfiles import StaticFiles
|
||||
|
||||
from sqlalchemy import select, update, func
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
import os
|
||||
try:
|
||||
import chardet
|
||||
from fastapi import FastAPI, Depends, UploadFile, Form, File, HTTPException, BackgroundTasks
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import HTMLResponse, FileResponse
|
||||
from starlette.staticfiles import StaticFiles
|
||||
from sqlalchemy import select, update, func
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
except ImportError:
|
||||
os.system("pip install -r requirements.txt")
|
||||
import chardet
|
||||
from fastapi import FastAPI, Depends, UploadFile, Form, File, HTTPException, BackgroundTasks
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import HTMLResponse, FileResponse
|
||||
from starlette.staticfiles import StaticFiles
|
||||
from sqlalchemy import select, update, func
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
|
||||
import settings
|
||||
from utils import delete_expire_files, storage, get_code, error_ip_limit, upload_ip_limit
|
||||
|
||||
+2
-1
@@ -4,4 +4,5 @@ SQLAlchemy==1.4.44
|
||||
python-multipart==0.0.5
|
||||
uvicorn==0.15.0
|
||||
greenlet==2.0.1
|
||||
starlette~=0.22.0
|
||||
starlette~=0.22.0
|
||||
chardet == 5.1.0
|
||||
+14
-1
@@ -1,7 +1,20 @@
|
||||
from starlette.config import Config
|
||||
|
||||
from utf8togbk import convert_encoding
|
||||
import os
|
||||
import shutil
|
||||
# 配置文件.env
|
||||
# 请将.env移动至data目录,方便docker部署
|
||||
|
||||
# 判断根目录下是否存在.env文件
|
||||
if os.path.exists('.env'):
|
||||
# 将文件复制到data目录
|
||||
shutil.copy('.env', 'data/.env')
|
||||
# 获取data目录下的.env文件编码,如果为utf-8编码,就转换为gbk编码
|
||||
convert_encoding('./data/.env')
|
||||
elif os.path.exists('data/.env'):
|
||||
# 获取data目录下的.env文件编码,如果为utf-8编码,就转换为gbk编码
|
||||
convert_encoding('./data/.env')
|
||||
|
||||
config = Config("data/.env")
|
||||
# 是否开启DEBUG模式
|
||||
DEBUG = config('DEBUG', cast=bool, default=False)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import chardet
|
||||
|
||||
|
||||
# 将UTF-8编码的文件转换为GBK编码
|
||||
def utf8togbk(file):
|
||||
with open(file, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
with open(file, 'w', encoding='gbk') as f:
|
||||
f.writelines(lines)
|
||||
|
||||
|
||||
# 获取文件编码
|
||||
def get_encoding(file):
|
||||
with open(file, 'rb') as f:
|
||||
return chardet.detect(f.read())['encoding']
|
||||
|
||||
|
||||
# 获取文件编码,如果为utf-8编码,就转换为gbk编码
|
||||
def convert_encoding(file):
|
||||
if get_encoding(file) == 'utf-8':
|
||||
utf8togbk(file)
|
||||
Reference in New Issue
Block a user