def upload_package(storage_elem, version: str = None, apk_type: APKType = APKType.rgc, apk_arch: APKArch = APKArch.noarch) -> NoReturn: data = get_rgc_bytes() if version is None: PackageImporter(apk_type, apk_arch, storage_elem, data, mimetype) else: storage_elem.save_file(apk_type, apk_arch, version, mimetype, data)
def post(self, apk_type: APK_Type, apk_arch: APK_Arch): is_upload: bool = False apk: io.BytesIO = None filename: str = None if 'multipart/form-data' in self.api_req.content_type: filename = self.api_req.data['data'].get('filename', None) try: apk = io.BytesIO(self.api_req.data['files'].get('file').read()) except AttributeError: return ('No file present', 406) is_upload = True if self.api_req.content_type == 'application/octet-stream': filename = self.api_req.headers.get('filename', None) apk = io.BytesIO(self.api_req.data) is_upload = True if is_upload: if filename is None: return ('filename must be specified', 406) elems: MAD_APKS = get_apk_status(self.storage_obj) try: elems[apk_type][apk_arch] except KeyError: return ('Non-supported Type / Architecture', 406) filename_split = filename.rsplit('.', 1) if filename_split[1] in ['zip', 'apks']: mimetype = 'application/zip' elif filename_split[1] == 'apk': mimetype = 'application/vnd.android.package-archive' else: return ('Unsupported extension', 406) try: PackageImporter(apk_type, apk_arch, self.storage_obj, apk, mimetype) if 'multipart/form-data' in self.api_req.content_type: return flask.redirect(None, code=201) return (None, 201) except (BadZipFile, LargeZipFile) as err: return (str(err), 406) except WizardError as err: self._logger.warning(str(err)) return (str(err), 406) except Exception: self._logger.opt( exception=True).critical("An unhanded exception occurred!") return (None, 500) else: try: call = self.api_req.data['call'] wizard = APKWizard(self.dbc, self.storage_obj) if call == 'import': thread_args = (apk_type, apk_arch) t = Thread(target=wizard.apk_download, args=thread_args) t.start() return (None, 204) elif call == 'search': wizard.apk_search(apk_type, apk_arch) return (None, 204) elif call == 'search_download': try: wizard.apk_all_actions() return (None, 204) except TypeError: return (None, 404) else: return (call, 501) except KeyError: import traceback traceback.print_exc() return (call, 501) return (None, 500)