From ece12e29af8470bb08a2c237ff4e832f6e715f3c Mon Sep 17 00:00:00 2001 From: CEbbinghaus Date: Sat, 4 Nov 2023 21:06:14 +1100 Subject: [PATCH] feat: expanded plugin unzipping --- backend/src/browser.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/backend/src/browser.py b/backend/src/browser.py index da8569bee..c9b2711bb 100644 --- a/backend/src/browser.py +++ b/backend/src/browser.py @@ -9,7 +9,7 @@ from hashlib import sha256 from io import BytesIO from logging import getLogger -from os import R_OK, W_OK, path, listdir, access, mkdir +from os import R_OK, W_OK, path, listdir, access, mkdir, path from shutil import rmtree from time import time from zipfile import ZipFile @@ -57,7 +57,15 @@ def _unzip_to_plugin_dir(self, zip: BytesIO, name: str, hash: str): if hash and (zip_hash != hash): return False zip_file = ZipFile(zip) - zip_file.extractall(self.plugin_path) + + files = zip_file.namelist() + if "plugin.json" in files: + zip_file.extractall(path.join(self.plugin_path, name)) + if name in files: + zip_file.extractall(self.plugin_path) + if name + ".zip" in files: + return self._unzip_to_plugin_dir(BytesIO(zip_file.read(name + ".zip")), name, hash) + plugin_folder = self.find_plugin_folder(name) assert plugin_folder is not None plugin_dir = path.join(self.plugin_path, plugin_folder)