mirror of
https://github.com/bombsquad-community/plugin-manager.git
synced 2025-11-07 17:36:00 +00:00
[ci] auto-format
This commit is contained in:
parent
f421d4a5bd
commit
09319de3e3
1 changed files with 58 additions and 42 deletions
|
|
@ -8,6 +8,11 @@ by : Mr.Smoothy
|
|||
Thanks Dliwk for contributing MultiPartForm.class
|
||||
'''
|
||||
from __future__ import annotations
|
||||
import mimetypes
|
||||
import json
|
||||
import re
|
||||
import io
|
||||
import uuid
|
||||
|
||||
import bascenev1 as bs
|
||||
import _baplus
|
||||
|
|
@ -36,6 +41,7 @@ HEADERS = {
|
|||
'User-Agent': 'BombSquad Client'
|
||||
}
|
||||
|
||||
|
||||
class UploadConfirmation(ConfirmWindow):
|
||||
def __init__(
|
||||
self,
|
||||
|
|
@ -65,7 +71,8 @@ class UploadConfirmation(ConfirmWindow):
|
|||
def _upload_file(self):
|
||||
self.status = "uploading"
|
||||
print(self.root_widget)
|
||||
thread = Thread(target = handle_upload, args = (self.file_path, self.uploaded, self.root_widget,))
|
||||
thread = Thread(target=handle_upload, args=(
|
||||
self.file_path, self.uploaded, self.root_widget,))
|
||||
thread.start()
|
||||
|
||||
def uploaded(self, url, root_widget):
|
||||
|
|
@ -73,6 +80,7 @@ class UploadConfirmation(ConfirmWindow):
|
|||
from bauiv1lib.url import ShowURLWindow
|
||||
ShowURLWindow(url)
|
||||
|
||||
|
||||
class InputWindow(PromoCodeWindow):
|
||||
def __init__(
|
||||
self, modal: bool = True, origin_widget: bui.Widget | None = None, path=None):
|
||||
|
|
@ -98,15 +106,18 @@ class InputWindow(PromoCodeWindow):
|
|||
else:
|
||||
bui.textwidget(edit=self.message_widget, text="First select folder were to save file.")
|
||||
self.close()
|
||||
|
||||
def on_download(self, output_path):
|
||||
bui.screenmessage("File Downloaded to path")
|
||||
bui.screenmessage(output_path)
|
||||
bui.screenmessage("GO back and reopen to refresh")
|
||||
|
||||
def close(self):
|
||||
bui.containerwidget(
|
||||
edit=self._root_widget, transition=self._transition_out
|
||||
)
|
||||
|
||||
|
||||
class FileSelectorExtended(FileSelectorWindow):
|
||||
|
||||
def __init__(
|
||||
|
|
@ -117,7 +128,8 @@ class FileSelectorExtended(FileSelectorWindow):
|
|||
valid_file_extensions: Sequence[str] | None = None,
|
||||
allow_folders: bool = False,
|
||||
):
|
||||
super().__init__(path, callback = callback, show_base_path = show_base_path, valid_file_extensions = valid_file_extensions, allow_folders = allow_folders)
|
||||
super().__init__(path, callback=callback, show_base_path=show_base_path,
|
||||
valid_file_extensions=valid_file_extensions, allow_folders=allow_folders)
|
||||
self._import_button = bui.buttonwidget(
|
||||
parent=self._root_widget,
|
||||
button_type='square',
|
||||
|
|
@ -129,6 +141,7 @@ class FileSelectorExtended(FileSelectorWindow):
|
|||
label="Import",
|
||||
on_activate_call=self._open_import_menu,
|
||||
)
|
||||
|
||||
def _open_import_menu(self):
|
||||
InputWindow(origin_widget=self._import_button, path=self._path)
|
||||
|
||||
|
|
@ -179,20 +192,19 @@ class FileSelectorExtended(FileSelectorWindow):
|
|||
if new_path is not None:
|
||||
self._set_path(new_path)
|
||||
|
||||
|
||||
org_listdir = os.listdir
|
||||
|
||||
|
||||
def custom_listdir(path):
|
||||
if path == "/bombsquad":
|
||||
return ["mods", "replays"]
|
||||
return org_listdir(path)
|
||||
|
||||
|
||||
os.listdir = custom_listdir
|
||||
|
||||
|
||||
import uuid
|
||||
import io
|
||||
import re
|
||||
import json
|
||||
import urllib.request
|
||||
import mimetypes
|
||||
class MultiPartForm:
|
||||
"""Accumulate the data to be used when posting a form."""
|
||||
|
||||
|
|
@ -266,6 +278,7 @@ class MultiPartForm:
|
|||
buffer.write(b'--' + self.boundary + b'--\r\n')
|
||||
return buffer.getvalue()
|
||||
|
||||
|
||||
def handle_upload(file, callback, root_widget):
|
||||
file_name = file.split("/")[-1]
|
||||
with open(file, "rb") as f:
|
||||
|
|
@ -288,14 +301,14 @@ def handle_upload(file, callback, root_widget):
|
|||
with urllib.request.urlopen(r) as response:
|
||||
if response.getcode() == 200:
|
||||
# callback(json.loads(response.read().decode('utf-8'))["link"])
|
||||
_babase.pushcall(Call(callback,json.loads(response.read().decode('utf-8'))["link"], root_widget), from_other_thread = True)
|
||||
_babase.pushcall(Call(callback, json.loads(response.read().decode(
|
||||
'utf-8'))["link"], root_widget), from_other_thread=True)
|
||||
else:
|
||||
bui.screenmessage(f"Failed to Upload file. Status code: {response.getcode()}")
|
||||
except urllib.error.URLError as e:
|
||||
bui.screenmessage(f"Error occurred: {e}")
|
||||
|
||||
|
||||
|
||||
def handle_download(url, path, callback):
|
||||
req = urllib.request.Request(url, headers={'accept': '*/*'}, method='GET')
|
||||
try:
|
||||
|
|
@ -324,6 +337,8 @@ def handle_download(url, path, callback):
|
|||
print(f"Error occurred: {e}")
|
||||
|
||||
# ba_meta export plugin
|
||||
|
||||
|
||||
class bySmoothy(babase.Plugin):
|
||||
def on_app_running(self):
|
||||
pass
|
||||
|
|
@ -345,4 +360,5 @@ class bySmoothy(babase.Plugin):
|
|||
|
||||
def fileSelected(self, path):
|
||||
if path:
|
||||
UploadConfirmation(path,"init", text= "You want to upload " + path.split("/")[-1], ok_text= "Upload")
|
||||
UploadConfirmation(path, "init", text="You want to upload " +
|
||||
path.split("/")[-1], ok_text="Upload")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue