Esempio n. 1
0
def find_file_by_id(file_id):
    sql = "select id,file_name,file_size,key_words,creator,created_at,file_path,file_doc,permission,download_count " \
          "from `files` where id=%d" % file_id
    global cursor
    cursor.execute(sql)
    values = cursor.fetchall()
    for file_id, file_name, file_size, key_words, creator, created_at, file_path, file_doc, permission, download_count in values:
        f = FileInfo()
        f.file_id = file_id
        f.file_name = file_name
        f.file_size = file_size
        f.key_words = key_words
        f.creator = creator
        f.created_at = created_at
        f.file_path = file_path
        f.file_doc = file_doc
        f.permission = int(permission)
        f.download_count = download_count
        return f
Esempio n. 2
0
def insert_new_file(file_io, user_name, file_permission):
    if not allowed_file(file_io.filename):
        return None
    sec_file_name = file_io.filename
    save_path = os.path.join(UPLOAD_FOLDER, sec_file_name)
    file_io.save(save_path)

    file_info = FileInfo()
    file_info.file_name = sec_file_name
    file_info.file_doc = sec_file_name.rsplit('.', 1)[1]
    file_info.creator = user_name
    file_info.download_count = 0
    file_info.permission = file_permission
    file_info.file_path = save_path
    file_info.file_size = os.path.getsize(save_path)
    file_info.created_at = time.time() * 1000
    file_info.key_words = search_service.cal_keys_from_file(file_info)

    db_helper.insert_file_info(file_info)
    return file_info
Esempio n. 3
0
def query_all_files():
    sql = "select id,file_name,file_size,key_words,creator,created_at,file_path,file_doc,permission,download_count " \
          "from `files`"
    global cursor
    cursor.execute(sql)
    values = cursor.fetchall()
    result = []
    for file_id, file_name, file_size, key_words, creator, created_at, file_path, file_doc, permission, download_count in values:
        f = FileInfo()
        f.file_id = file_id
        f.file_name = file_name
        f.file_size = file_size
        f.key_words = key_words
        f.creator = creator
        f.created_at = created_at
        f.file_path = file_path
        f.file_doc = file_doc
        f.permission = int(permission)
        f.download_count = download_count
        result.append(f)
    return result