Example #1
0
def update_book(id_):
    book = Book.query.get(id_)
    if not book:
        raise ApiError('书本不存在')
    data = request.json
    book = book.update(data)
    book = book.to_dict()
    project_ids = data.get('project_ids', [])
    Project.generate_project(id_, project_ids)
    return api_success(book)
Example #2
0
def add_book():
    data = request.json
    data['file_type'] = os.path.splitext(data['file_path'])[1].strip('.')
    data['file_size'] = book_service.get_size(data['file_path'])
    if data['file_type'] == 'epub':
        file_path = current_app.config['APP_PATH'] + data['file_path']
        opf_path = book_service.generate_opf_from_epub(file_path,
                                                       data['file_path'])
        data['opf_path'] = os.path.join((data['file_path'] + "_files/"),
                                        opf_path)
    if not data.get('image') and data['file_type'] == 'epub':
        cover_path = book_service.cover_path_from_epub(data['file_path'])
        data['image'] = cover_path
    book = Book.create(data)
    project_ids = data.get('project_ids', [])
    res = book.to_dict()
    Project.generate_project(book.id, project_ids)
    return api_success(res)