This commit is contained in:
StNicolay 2024-08-11 14:39:00 +03:00
parent 409f13b584
commit aa786de5b4
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D

View File

@ -1,13 +1,11 @@
from __future__ import annotations
import dataclasses
import os
import uuid
from typing import Protocol, Self
import create_folder_widget
import sync
import httpx
import pydantic
import state
import user
@ -26,7 +24,6 @@ from PyQt6.QtWidgets import (
QListWidget,
QListWidgetItem,
QMenu,
QMessageBox,
QPushButton,
QVBoxLayout,
QWidget,
@ -129,7 +126,7 @@ class FileListWidget(QListWidget):
item = self.current_response().items()[row]
item.double_click(self)
def current_response(self) -> ListResponse:
def current_response(self) -> ResponseProtocol:
if not self.responses:
self.update_response()
return self.responses[-1]
@ -154,28 +151,10 @@ class FileListWidget(QListWidget):
self.upload_file(file_path)
def upload_file(self, file_path):
file_name = os.path.basename(file_path)
try:
with open(file_path, "rb") as f:
files = {"file": (file_name, f)}
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))
response = self.current_response()
if not isinstance(response, ListResponse):
return
File.create(file_path, response.folder_id)
def add_item(self, item: DisplayProtocol):
widget = QListWidgetItem(item.name())