update:encoding convert
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
import datetime
|
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.declarative import declarative_base
|
||||||
from sqlalchemy.ext.asyncio import create_async_engine
|
from sqlalchemy.ext.asyncio import create_async_engine
|
||||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||||
@@ -35,7 +35,7 @@ class Codes(Base):
|
|||||||
name = Column(String(500))
|
name = Column(String(500))
|
||||||
size = Column(Integer)
|
size = Column(Integer)
|
||||||
type = Column(String(20))
|
type = Column(String(20))
|
||||||
text = Column(String(500))
|
text = Column(Text)
|
||||||
used = Column(Boolean, default=False)
|
used = Column(Boolean, default=False)
|
||||||
count = Column(Integer, default=-1)
|
count = Column(Integer, default=-1)
|
||||||
use_time = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
|
use_time = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now)
|
||||||
|
|||||||
@@ -1,21 +1,22 @@
|
|||||||
|
# 获取文件编码
|
||||||
import chardet
|
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):
|
def get_encoding(file):
|
||||||
with open(file, 'rb') as f:
|
with open(file, 'rb') as f:
|
||||||
return chardet.detect(f.read())['encoding']
|
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编码
|
# 获取文件编码,如果为utf-8编码,就转换为gbk编码
|
||||||
def convert_encoding(file):
|
def convert_encoding(file):
|
||||||
if get_encoding(file) == 'utf-8':
|
encoding = get_encoding(file)
|
||||||
utf8togbk(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()
|
await s.commit()
|
||||||
upload_ip_limit.add_ip(ip)
|
upload_ip_limit.add_ip(ip)
|
||||||
return {
|
return {
|
||||||
'detail': '分享成功,请点击取件码按钮查看上传列表',
|
'detail': '分享成功,请点击我的文件按钮查看上传列表',
|
||||||
'data': {'code': code, 'key': key, 'name': name}
|
'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__':
|
if __name__ == '__main__':
|
||||||
import uvicorn
|
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 starlette.config import Config
|
||||||
from utf8togbk import convert_encoding
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import encoding_convert
|
||||||
|
|
||||||
# 配置文件.env
|
# 配置文件.env
|
||||||
# 请将.env移动至data目录,方便docker部署
|
# 请将.env移动至data目录,方便docker部署
|
||||||
|
|
||||||
# 判断根目录下是否存在.env文件
|
# 判断根目录下是否存在.env文件
|
||||||
if os.path.exists('.env'):
|
if os.path.exists('.env'):
|
||||||
# 将文件复制到data目录
|
# 将文件复制到data目录
|
||||||
shutil.copy('.env', 'data/.env')
|
shutil.copy('.env', 'data/.env')
|
||||||
|
if os.path.exists('data/.env'):
|
||||||
# 获取data目录下的.env文件编码,如果为utf-8编码,就转换为gbk编码
|
# 获取data目录下的.env文件编码,如果为utf-8编码,就转换为gbk编码
|
||||||
convert_encoding('./data/.env')
|
encoding_convert.convert_encoding('./data/.env')
|
||||||
elif os.path.exists('data/.env'):
|
|
||||||
# 获取data目录下的.env文件编码,如果为utf-8编码,就转换为gbk编码
|
|
||||||
convert_encoding('./data/.env')
|
|
||||||
|
|
||||||
config = Config("data/.env")
|
config = Config("data/.env")
|
||||||
# 是否开启DEBUG模式
|
# 是否开启DEBUG模式
|
||||||
|
|||||||
+1
-61
@@ -73,58 +73,7 @@
|
|||||||
</el-pagination>
|
</el-pagination>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col v-if="activeIndex === '3'">
|
<el-col v-if="activeIndex === '3'">
|
||||||
<el-form ref="form" style="width: 50%;margin:2rem auto" :model="config" label-width="200px">
|
<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)">
|
||||||
<!--? <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)">
|
|
||||||
<div style="width: 50%;display: inline-block">
|
<div style="width: 50%;display: inline-block">
|
||||||
<el-input v-model="banner.text" placeholder="文本"></el-input>
|
<el-input v-model="banner.text" placeholder="文本"></el-input>
|
||||||
<el-input v-model="banner.url" placeholder="跳转链接"></el-input>
|
<el-input v-model="banner.url" placeholder="跳转链接"></el-input>
|
||||||
@@ -162,15 +111,6 @@
|
|||||||
pwd: '',
|
pwd: '',
|
||||||
activeIndex: '2',
|
activeIndex: '2',
|
||||||
config: {
|
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: []
|
banners: []
|
||||||
},
|
},
|
||||||
files: [],
|
files: [],
|
||||||
|
|||||||
@@ -11,11 +11,7 @@
|
|||||||
<meta name="description" content="{{description}}"/>
|
<meta name="description" content="{{description}}"/>
|
||||||
<meta name="keywords" content="{{keywords}}"/>
|
<meta name="keywords" content="{{keywords}}"/>
|
||||||
<meta name="generator" content="FileCodeBox"/>
|
<meta name="generator" content="FileCodeBox"/>
|
||||||
<meta name="template" content="Lan-V1.5.8"/>
|
<meta name="template" content="Lan-V1.5.9.1"/>
|
||||||
<meta name="description" content="{{description}}"/>
|
|
||||||
<meta name="keywords" content="{{keywords}}"/>
|
|
||||||
<meta name="generator" content="FileCodeBox"/>
|
|
||||||
<meta name="template" content="Lan-V1.5.8"/>
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
background: #f5f5f5;
|
background: #f5f5f5;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import random
|
import random
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
import chardet
|
||||||
from sqlalchemy import or_, select, delete
|
from sqlalchemy import or_, select, delete
|
||||||
from sqlalchemy.ext.asyncio.session import AsyncSession
|
from sqlalchemy.ext.asyncio.session import AsyncSession
|
||||||
import settings
|
import settings
|
||||||
|
|||||||
Reference in New Issue
Block a user