diff --git a/app_common/__manifest__.py b/app_common/__manifest__.py index 25f45f8e..f35c2aeb 100644 --- a/app_common/__manifest__.py +++ b/app_common/__manifest__.py @@ -39,7 +39,7 @@ { 'name': "odooAi Common Util and Tools,欧度智能基础核心优化", - 'version': '16.24.04.07', + 'version': '16.24.04.18', 'author': 'odooai.cn', 'category': 'Base', 'website': 'https://www.odooai.cn', diff --git a/app_common/models/base.py b/app_common/models/base.py index d8f545f1..312491d2 100644 --- a/app_common/models/base.py +++ b/app_common/models/base.py @@ -126,6 +126,9 @@ class Base(models.AbstractModel): 'datas': image, 'name': file_name, 'website_id': False, + 'res_model': self._name, + 'res_id': self.id, + 'public': True, }) attachment.generate_access_token() return attachment @@ -146,6 +149,9 @@ class Base(models.AbstractModel): 'datas': image, 'name': file_name, 'website_id': False, + 'res_model': self._name, + 'res_id': self.id, + 'public': True, }) attachment.generate_access_token() return attachment @@ -154,6 +160,29 @@ class Base(models.AbstractModel): return False else: return False + + @api.model + def _get_video_url2attachment(self, url): + if not self._app_check_sys_op(): + return False + video, file_name = get_video_url2attachment(url) + if video and file_name: + try: + attachment = self.env['ir.attachment'].create({ + 'datas': video, + 'name': file_name, + 'website_id': False, + 'res_model': self._name, + 'res_id': self.id, + 'public': True, + }) + attachment.generate_access_token() + return attachment + except Exception as e: + _logger.error('get_video_url2attachment error: %s' % str(e)) + return False + else: + return False def get_ua_type(self): return get_ua_type() @@ -199,6 +228,21 @@ def get_image_base642attachment(data): return jpeg_base64, file_name except Exception as e: return None, None + +def get_video_url2attachment(url): + if not url: + return None + try: + if url.startswith('//'): + url = 'https:%s' % url + response = requests.get(url, timeout=90) + video_content = response.content + except Exception as e: + return None, None + # return this video in base64 + base64_video = base64.b64encode(video_content) + file_name = url.split('/')[-1] + return base64_video, file_name def get_ua_type(): ua = request.httprequest.headers.get('User-Agent')