update:encoding convert
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
||||
import datetime
|
||||
from sqlalchemy import Boolean, Column, Integer, String, DateTime, JSON
|
||||
from sqlalchemy import Boolean, Column, Integer, String, DateTime, JSON, Text
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||
@@ -35,7 +35,7 @@ class Codes(Base):
|
||||
name = Column(String(500))
|
||||
size = Column(Integer)
|
||||
type = Column(String(20))
|
||||
text = Column(String(500))
|
||||
text = Column(Text)
|
||||
used = Column(Boolean, default=False)
|
||||
count = Column(Integer, default=-1)
|
||||
use_time = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
# 获取文件编码
|
||||
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编码
|
||||
def other2utf8(file, encoding):
|
||||
with open(file, 'r', encoding=encoding) as f:
|
||||
lines = f.readlines()
|
||||
with open(file, 'w', encoding='utf-8') as f:
|
||||
f.writelines(lines)
|
||||
|
||||
|
||||
# 获取文件编码,如果为utf-8编码,就转换为gbk编码
|
||||
def convert_encoding(file):
|
||||
if get_encoding(file) == 'utf-8':
|
||||
utf8togbk(file)
|
||||
encoding = get_encoding(file)
|
||||
if encoding != 'utf-8':
|
||||
other2utf8(file, encoding)
|
||||
@@ -212,7 +212,7 @@ async def share(background_tasks: BackgroundTasks, text: str = Form(default=None
|
||||
await s.commit()
|
||||
upload_ip_limit.add_ip(ip)
|
||||
return {
|
||||
'detail': '分享成功,请点击取件码按钮查看上传列表',
|
||||
'detail': '分享成功,请点击我的文件按钮查看上传列表',
|
||||
'data': {'code': code, 'key': key, 'name': name}
|
||||
}
|
||||
|
||||
@@ -220,4 +220,4 @@ async def share(background_tasks: BackgroundTasks, text: str = Form(default=None
|
||||
if __name__ == '__main__':
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run('main:app', host='0.0.0.0', port=settings.PORT, reload=settings.DEBUG)
|
||||
uvicorn.run('main:app', host=':', port=settings.PORT, reload=settings.DEBUG)
|
||||
|
||||
+4
-6
@@ -1,19 +1,17 @@
|
||||
from starlette.config import Config
|
||||
from utf8togbk import convert_encoding
|
||||
import os
|
||||
import shutil
|
||||
import encoding_convert
|
||||
|
||||
# 配置文件.env
|
||||
# 请将.env移动至data目录,方便docker部署
|
||||
|
||||
# 判断根目录下是否存在.env文件
|
||||
if os.path.exists('.env'):
|
||||
# 将文件复制到data目录
|
||||
shutil.copy('.env', 'data/.env')
|
||||
if os.path.exists('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')
|
||||
encoding_convert.convert_encoding('./data/.env')
|
||||
|
||||
config = Config("data/.env")
|
||||
# 是否开启DEBUG模式
|
||||
|
||||
+1
-61
@@ -73,58 +73,7 @@
|
||||
</el-pagination>
|
||||
</el-col>
|
||||
<el-col v-if="activeIndex === '3'">
|
||||
<el-form ref="form" style="width: 50%;margin:2rem auto" :model="config" label-width="200px">
|
||||
<!--? <el-form-item label="错误限制">-->
|
||||
<!--? <div>-->
|
||||
<!--? 间隔:-->
|
||||
<!--? <el-input-number v-model="config.error_count" :min="1"></el-input-number>-->
|
||||
<!--? 分钟-->
|
||||
<!--? </div>-->
|
||||
<!--? <div>-->
|
||||
<!--? 数量:-->
|
||||
<!--? <el-input-number v-model="config.error_minute" :min="1"></el-input-number>-->
|
||||
<!--? 个-->
|
||||
<!--? </div>-->
|
||||
<!--? </el-form-item>-->
|
||||
<!--? <el-form-item label="上传限制">-->
|
||||
<!--? <div>-->
|
||||
<!--? 开启上传:-->
|
||||
<!--? <el-switch-->
|
||||
<!--? v-model="config.enable_upload"-->
|
||||
<!--? active-color="#13ce66"-->
|
||||
<!--? inactive-color="#ff4949">-->
|
||||
<!--? </el-switch>-->
|
||||
<!--? </div>-->
|
||||
<!--? <div>-->
|
||||
<!--? 间隔:-->
|
||||
<!--? <el-input-number v-model="config.upload_minute" :min="1"></el-input-number>-->
|
||||
<!--? 分钟-->
|
||||
<!--? </div>-->
|
||||
<!--? <div>-->
|
||||
<!--? 数量:-->
|
||||
<!--? <el-input-number v-model="config.upload_count" :min="1"></el-input-number>-->
|
||||
<!--? 个-->
|
||||
<!--? </div>-->
|
||||
<!--? <div>-->
|
||||
<!--? 最长:-->
|
||||
<!--? <el-input-number v-model="config.max_days" :min="1"></el-input-number>-->
|
||||
<!--? 天-->
|
||||
<!--? </div>-->
|
||||
<!--? <div>-->
|
||||
<!--? 大小:-->
|
||||
<!--? <el-input-number v-model="config.file_size_limit" :min="1"></el-input-number>-->
|
||||
<!--? MB-->
|
||||
<!--? </div>-->
|
||||
<!--? </el-form-item>-->
|
||||
<!--? <el-form-item label="删除间隔">-->
|
||||
<!--? 时长:-->
|
||||
<!--? <el-input-number v-model="config.delete_expire_files_interval"></el-input-number>-->
|
||||
<!--? 分钟-->
|
||||
<!--? </el-form-item>-->
|
||||
<!--? <el-form-item label="管理员密码">-->
|
||||
<!--? <el-input v-model="config.admin_password" type="password"></el-input>-->
|
||||
<!--? </el-form-item>-->
|
||||
<el-form-item v-for="(banner,index) in config.banners" :label="'Banner'+ (index+1)">
|
||||
<el-form ref="form" style="width: 50%;margin:2rem auto" :model="config" label-width="200px"><el-form-item v-for="(banner,index) in config.banners" :label="'Banner'+ (index+1)">
|
||||
<div style="width: 50%;display: inline-block">
|
||||
<el-input v-model="banner.text" placeholder="文本"></el-input>
|
||||
<el-input v-model="banner.url" placeholder="跳转链接"></el-input>
|
||||
@@ -162,15 +111,6 @@
|
||||
pwd: '',
|
||||
activeIndex: '2',
|
||||
config: {
|
||||
// enable_upload: true,
|
||||
// max_days: 7,
|
||||
// error_count: 3,
|
||||
// error_minute: 10,
|
||||
// upload_count: 10,
|
||||
// upload_minute: 10,
|
||||
// delete_expire_files_interval: 10,
|
||||
// admin_password: 'admin',
|
||||
// file_size_limit: 10,
|
||||
banners: []
|
||||
},
|
||||
files: [],
|
||||
|
||||
@@ -11,11 +11,7 @@
|
||||
<meta name="description" content="{{description}}"/>
|
||||
<meta name="keywords" content="{{keywords}}"/>
|
||||
<meta name="generator" content="FileCodeBox"/>
|
||||
<meta name="template" content="Lan-V1.5.8"/>
|
||||
<meta name="description" content="{{description}}"/>
|
||||
<meta name="keywords" content="{{keywords}}"/>
|
||||
<meta name="generator" content="FileCodeBox"/>
|
||||
<meta name="template" content="Lan-V1.5.8"/>
|
||||
<meta name="template" content="Lan-V1.5.9.1"/>
|
||||
<style>
|
||||
body {
|
||||
background: #f5f5f5;
|
||||
|
||||
Reference in New Issue
Block a user