-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
leezhua17
committed
Apr 9, 2023
1 parent
96ac996
commit 89712d6
Showing
7 changed files
with
73 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
import subprocess | ||
|
||
import config | ||
|
||
|
||
def mobi_to_epub(mobi_file_path): | ||
""" | ||
将mobi格式电子书转换为epub格式 | ||
:param mobi_file_path: mobi文件的路径 | ||
:return: epub文件的路径 | ||
""" | ||
# 获取mobi文件名和目录 | ||
mobi_file_name = os.path.basename(mobi_file_path) | ||
# 生成epub文件路径 | ||
epub_file_name = os.path.splitext(mobi_file_name)[0] + '.epub' | ||
epub_file_path = os.path.join(config.DOWNLOAD_DIR, epub_file_name) | ||
|
||
# 调用calibre进行转换 | ||
command = f"ebook-convert {mobi_file_path} {epub_file_path}" | ||
try: | ||
status = subprocess.check_call(command, shell=True, stdout=subprocess.PIPE) | ||
if status == 0: | ||
return config.DOWNLOAD_URL + epub_file_name | ||
return "error" | ||
except subprocess.CalledProcessError as e: | ||
print(f"Conversion failed with return code {e.returncode}.") | ||
return False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,31 @@ | ||
import logging | ||
from flask import request | ||
from flask_jwt_extended import get_jwt_identity, jwt_required | ||
from book import app, jwt, Userlog, db | ||
from book.utils.ApiResponse import APIResponse | ||
|
||
|
||
@app.route("/user/send/ebook", methods=["POST"]) | ||
@jwt_required() | ||
def dl_ebook(): | ||
try: | ||
data = request.get_json() | ||
book_name = data.get('book_name') | ||
ipfs_cid = data.get('ipfs_cid') | ||
if not all(x in data for x in ['book_name', 'ipfs_cid']): | ||
return APIResponse.internal_server_error(msg="参数错误!") | ||
user = get_jwt_identity() | ||
if user.wx_openid is None: | ||
return APIResponse.bad_request(msg="请先关注公众号,发送注册邮箱进行绑定") | ||
|
||
filesize = data.get('filesize', 0) | ||
user_log = Userlog(wx_openid=user.wx_openid, book_name=book_name, receive_email=user.kindle_email, | ||
user_id=user.id, operation_type='download', | ||
status=0, ipfs_cid=ipfs_cid, filesize=filesize) | ||
db.session.add(user_log) | ||
db.session.commit() | ||
return APIResponse.success(msg="发送成功,邮箱接收!") | ||
|
||
except Exception as e: | ||
logging.error(e) | ||
return APIResponse.bad_request(msg="发送失败") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters