From 15144833f8ccb291461f9a3afa87a3b90a65fcd7 Mon Sep 17 00:00:00 2001 From: ojhdt Date: Sat, 21 Jan 2023 00:26:53 +0800 Subject: [PATCH] fix qi_niu related issues --- efb_parabox_master/fcm_util.py | 2 -- efb_parabox_master/master_message.py | 10 +++++----- efb_parabox_master/qiniu_util.py | 11 +++++++---- efb_parabox_master/tencent_cos_util.py | 2 +- efb_parabox_master/wizard.py | 2 -- efb_parabox_master/xmpp.py | 2 -- efb_parabox_master/xmpp_backup.py | 4 ---- 7 files changed, 13 insertions(+), 20 deletions(-) diff --git a/efb_parabox_master/fcm_util.py b/efb_parabox_master/fcm_util.py index 5807e44..8b41ca6 100644 --- a/efb_parabox_master/fcm_util.py +++ b/efb_parabox_master/fcm_util.py @@ -13,11 +13,9 @@ # self.config = channel.config # self.logger = channel.logger # self.fcm_token = self.config.get('fcm_token') -# self.authorization_file_path = self.config.get('authorization_file_path') # self.app = None # # def init(self): -# path = efb_utils.get_data_path(self.channel.channel_id) / self.authorization_file_path # cred = credentials.Certificate(path) # self.app = firebase_admin.initialize_app(credential=cred) # diff --git a/efb_parabox_master/master_message.py b/efb_parabox_master/master_message.py index fe3aa9c..249ae10 100644 --- a/efb_parabox_master/master_message.py +++ b/efb_parabox_master/master_message.py @@ -179,7 +179,7 @@ def process_parabox_server_message(self, param): elif mtype == 1: file_name = content['file_name'] f = tempfile.NamedTemporaryFile(suffix=".jpg") - f.write(self.download_file(content['cloud_type'], content['cloud_id']).read()) + f.write(self.download_file(content['cloud_type'], content['cloud_id'])) f.seek(0) m.file = f m.filename = file_name @@ -187,7 +187,7 @@ def process_parabox_server_message(self, param): elif mtype == 2: file_name = content['file_name'] f = tempfile.NamedTemporaryFile(suffix=".mp3") - f.write(self.download_file(content['cloud_type'], content['cloud_id']).read()) + f.write(self.download_file(content['cloud_type'], content['cloud_id'])) f.seek(0) m.file = f m.filename = file_name @@ -195,7 +195,7 @@ def process_parabox_server_message(self, param): elif mtype == 3: file_name = content['file_name'] f = tempfile.NamedTemporaryFile(suffix=".mpeg") - f.write(self.download_file(content['cloud_type'], content['cloud_id']).read()) + f.write(self.download_file(content['cloud_type'], content['cloud_id'])) f.seek(0) m.file = f m.filename = file_name @@ -204,7 +204,7 @@ def process_parabox_server_message(self, param): file_name = content['file_name'] f = tempfile.NamedTemporaryFile() f.name = file_name - f.write(self.download_file(content['cloud_type'], content['cloud_id']).read()) + f.write(self.download_file(content['cloud_type'], content['cloud_id'])) f.seek(0) m.file = f m.filename = file_name @@ -213,7 +213,7 @@ def process_parabox_server_message(self, param): elif mtype == 5: file_name = content['fileName'] f = tempfile.NamedTemporaryFile(suffix=".gif") - f.write(self.download_file(content['cloud_type'], content['cloud_id']).read()) + f.write(self.download_file(content['cloud_type'], content['cloud_id'])) f.seek(0) m.file = f m.filename = file_name diff --git a/efb_parabox_master/qiniu_util.py b/efb_parabox_master/qiniu_util.py index e599102..873c931 100644 --- a/efb_parabox_master/qiniu_util.py +++ b/efb_parabox_master/qiniu_util.py @@ -1,4 +1,6 @@ from typing import TYPE_CHECKING + +import requests from qiniu import Auth, put_file, etag, BucketManager, put_data import qiniu.config @@ -31,7 +33,7 @@ def upload_file(self, file, filename): ret, info = put_file(token, key, file.name) if ret['key'] is not None: return { - 'url': self.domain + ret['key'], + 'url': 'http://%s/%s' % (self.domain, ret['key']), 'cloud_type': 3, 'cloud_id': ret['key'], } @@ -42,9 +44,10 @@ def download_file(self, key): self.init() q = Auth(self.access_key, self.secret_key) - bucket = BucketManager(q) - ret, info = bucket.fetch(self.domain + key, self.bucket, key) - return ret['data'] + base_url = 'http://%s/%s' % (self.domain, key) + private_url = q.private_download_url(base_url, expires=3600) + r = requests.get(private_url) + return r.content def upload_bytes(self, file_bytes, filename): self.init() diff --git a/efb_parabox_master/tencent_cos_util.py b/efb_parabox_master/tencent_cos_util.py index dbdd5df..1d342df 100644 --- a/efb_parabox_master/tencent_cos_util.py +++ b/efb_parabox_master/tencent_cos_util.py @@ -81,4 +81,4 @@ def download_file(self, key): Bucket=self.bucket, Key=key, ) - return download_response['Body'] + return download_response['Body'].get_raw_stream().read() diff --git a/efb_parabox_master/wizard.py b/efb_parabox_master/wizard.py index 460421d..a082af1 100644 --- a/efb_parabox_master/wizard.py +++ b/efb_parabox_master/wizard.py @@ -123,8 +123,6 @@ def save(self): "# domain: your_custom_domain\n" "#\n" ) - f.write("\n") - self.yaml.dump({"authorization_file_path": 'service-account.json'}, f) with self.config_path.open() as f: self.data = self.yaml.load(f) self.building_default = False diff --git a/efb_parabox_master/xmpp.py b/efb_parabox_master/xmpp.py index 3973201..1900854 100644 --- a/efb_parabox_master/xmpp.py +++ b/efb_parabox_master/xmpp.py @@ -31,8 +31,6 @@ # self.channel = channel # self.config = channel.config # self.logger = channel.logger -# self.authorization_file_path = self.config.get('authorization_file_path') -# path = efb_utils.get_data_path(self.channel.channel_id) / self.authorization_file_path # cred = credentials.Certificate(path) # cred.get_access_token() # diff --git a/efb_parabox_master/xmpp_backup.py b/efb_parabox_master/xmpp_backup.py index 933655b..02e6b95 100644 --- a/efb_parabox_master/xmpp_backup.py +++ b/efb_parabox_master/xmpp_backup.py @@ -25,11 +25,7 @@ # self.channel = channel # self.config = channel.config # self.logger = channel.logger -# self.authorization_file_path = self.config.get('authorization_file_path') -# path = efb_utils.get_data_path(self.channel.channel_id) / self.authorization_file_path # cred = credentials.Certificate(path) -# user = "292416108654@fcm.googleapis.com" -# password = "a8a46616c6b56db6d4169e617e74ab5824497a5b" # asyncio.set_event_loop(asyncio.new_event_loop()) # # self.xmpp = GCM(user, password, self.logger)