Cleanup
This commit is contained in:
parent
409f13b584
commit
aa786de5b4
@ -1,13 +1,11 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import dataclasses
|
import dataclasses
|
||||||
import os
|
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Protocol, Self
|
from typing import Protocol, Self
|
||||||
|
|
||||||
import create_folder_widget
|
import create_folder_widget
|
||||||
import sync
|
import sync
|
||||||
import httpx
|
|
||||||
import pydantic
|
import pydantic
|
||||||
import state
|
import state
|
||||||
import user
|
import user
|
||||||
@ -26,7 +24,6 @@ from PyQt6.QtWidgets import (
|
|||||||
QListWidget,
|
QListWidget,
|
||||||
QListWidgetItem,
|
QListWidgetItem,
|
||||||
QMenu,
|
QMenu,
|
||||||
QMessageBox,
|
|
||||||
QPushButton,
|
QPushButton,
|
||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
QWidget,
|
QWidget,
|
||||||
@ -129,7 +126,7 @@ class FileListWidget(QListWidget):
|
|||||||
item = self.current_response().items()[row]
|
item = self.current_response().items()[row]
|
||||||
item.double_click(self)
|
item.double_click(self)
|
||||||
|
|
||||||
def current_response(self) -> ListResponse:
|
def current_response(self) -> ResponseProtocol:
|
||||||
if not self.responses:
|
if not self.responses:
|
||||||
self.update_response()
|
self.update_response()
|
||||||
return self.responses[-1]
|
return self.responses[-1]
|
||||||
@ -154,28 +151,10 @@ class FileListWidget(QListWidget):
|
|||||||
self.upload_file(file_path)
|
self.upload_file(file_path)
|
||||||
|
|
||||||
def upload_file(self, file_path):
|
def upload_file(self, file_path):
|
||||||
file_name = os.path.basename(file_path)
|
response = self.current_response()
|
||||||
try:
|
if not isinstance(response, ListResponse):
|
||||||
with open(file_path, "rb") as f:
|
return
|
||||||
files = {"file": (file_name, f)}
|
File.create(file_path, response.folder_id)
|
||||||
response = RequestClient().client.post(
|
|
||||||
"http://localhost:3000/files",
|
|
||||||
files=files,
|
|
||||||
params={
|
|
||||||
"parent_folder": self.current_response().folder_id,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if response.is_success:
|
|
||||||
QMessageBox.information(
|
|
||||||
self, "Success", "File uploaded successfully"
|
|
||||||
)
|
|
||||||
self.update_response()
|
|
||||||
else:
|
|
||||||
QMessageBox.warning(
|
|
||||||
self, "Error", f"Upload failed: {response.text}"
|
|
||||||
)
|
|
||||||
except httpx.HTTPError as e:
|
|
||||||
QMessageBox.critical(self, "HTTP Error", str(e))
|
|
||||||
|
|
||||||
def add_item(self, item: DisplayProtocol):
|
def add_item(self, item: DisplayProtocol):
|
||||||
widget = QListWidgetItem(item.name())
|
widget = QListWidgetItem(item.name())
|
||||||
|
Reference in New Issue
Block a user