Skip to content

Commit

Permalink
fix qi_niu related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ojhdt committed Jan 20, 2023
1 parent c020309 commit 1514483
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 20 deletions.
2 changes: 0 additions & 2 deletions efb_parabox_master/fcm_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#
Expand Down
10 changes: 5 additions & 5 deletions efb_parabox_master/master_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,23 @@ 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
m.mime = "image/jpeg"
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
m.mime = "audio/mpeg"
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
Expand All @@ -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
Expand All @@ -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
Expand Down
11 changes: 7 additions & 4 deletions efb_parabox_master/qiniu_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import TYPE_CHECKING

import requests
from qiniu import Auth, put_file, etag, BucketManager, put_data
import qiniu.config

Expand Down Expand Up @@ -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'],
}
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion efb_parabox_master/tencent_cos_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 0 additions & 2 deletions efb_parabox_master/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions efb_parabox_master/xmpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
#
Expand Down
4 changes: 0 additions & 4 deletions efb_parabox_master/xmpp_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
# password = "a8a46616c6b56db6d4169e617e74ab5824497a5b"
# asyncio.set_event_loop(asyncio.new_event_loop())
#
# self.xmpp = GCM(user, password, self.logger)
Expand Down

0 comments on commit 1514483

Please sign in to comment.