Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
package = await PackageParse.parse(file_path)
if not package:
os.remove(file_path)
raise BadRequest('the file is not support')
app_query = session.query(AppModel).filter_by(package_name=package.package_name, type=package.app_type)
if app_query.count(): # 已存在
exists = True
app = app_query.one()
else: # 不存在
exists = False
# 生成短链
while 1:
short_chain = random(8)
if not session.query(AppModel).filter_by(short_chain_uri_=short_chain).count():
break
app_uuid = uuid('+_{}-{}_+'.format(package.app_type, package.package_name), 16)
icon_name = '{}.{}'.format(app_uuid, package.icon_path[package.icon_path.rfind('.') + 1:])
app = AppModel(type=package.app_type, short_chain_uri_=short_chain, detail='', name=package.app_name,
package_name=package.package_name, icon_='{}/{}'.format(Config.icon_dir, icon_name),
icon_uri_='{}/{}'.format(Config.static_icon, icon_name))
session.add(app)
session.commit()
app.version_code = package.version_code
app.version_name = package.version_name
# 保存图标
await package.save_icon(app.icon_)
def generate_pairing_code():
shortuuid.set_alphabet("0123456789ABCDEF")
return shortuuid.random(length=6)