api2.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:codex-backend 作者: codexgigassys 项目源码 文件源码
def get_file():
    tmp_folder = "/tmp/mass_download"
    subprocess.call(["mkdir", "-p", tmp_folder])
    file_hash = clean_hash(request.query.file_hash)
    key = ''
    if len(file_hash) == 40:
        key = 'sha1'
    else:
        response.status = 400
        return jsonize({'message': 'Invalid hash format (use sha1)'})

    pc = PackageController()
    res = pc.searchFile(file_hash)

    if res is None:
        response.status = 404
        return jsonize({'message': 'File not found in the database'})
    if res == 1:
        response.status = 400
        return jsonize({'message': 'File not available for downloading'})
    res = pc.getFile(file_hash)
    zip_name = os.path.join(tmp_folder, str(file_hash) + '.zip')
    file_name = os.path.join(tmp_folder, str(file_hash) + '.codex')
    fd = open(file_name, "wb")
    fd.write(res)
    fd.close()
    subprocess.call(["zip", "-ju", "-P", "codex", zip_name, file_name])
    return static_file(str(file_hash) + ".zip", root=tmp_folder, download=True)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号