Compare commits
No commits in common. "d6ecae08bd33fb067825ff64cffd32401f49b7d0" and "409f13b584ba2ac8cdbd6cc88b1e78994e76656d" have entirely different histories.
d6ecae08bd
...
409f13b584
@ -8,7 +8,11 @@ from state import State
|
||||
if __name__ == "__main__":
|
||||
dotenv.load_dotenv()
|
||||
url = os.environ.get("DRIVE_HOST_URL")
|
||||
if not url:
|
||||
url = "localhost:3000"
|
||||
else:
|
||||
url = url.strip()
|
||||
app = QApplication(sys.argv)
|
||||
window = State()
|
||||
window = State(url)
|
||||
window.show()
|
||||
sys.exit(app.exec())
|
||||
|
@ -58,7 +58,7 @@ class RegisterWidget(QWidget):
|
||||
|
||||
try:
|
||||
response = RequestClient().client.post(
|
||||
"/users/register",
|
||||
"http://localhost:3000/users/register",
|
||||
data={
|
||||
"username": username,
|
||||
"email": email,
|
||||
@ -79,7 +79,6 @@ class RegisterWidget(QWidget):
|
||||
self, "Error", f"Registration failed: {response.text}"
|
||||
)
|
||||
except httpx.HTTPError as e:
|
||||
print(e)
|
||||
QMessageBox.critical(self, "HTTP Error", str(e))
|
||||
|
||||
|
||||
@ -117,14 +116,12 @@ class LoginWidget(QWidget):
|
||||
password = self.password_input.text()
|
||||
|
||||
if not username or not password:
|
||||
QMessageBox.warning(
|
||||
self, "Input Error", "Email and Password are required"
|
||||
)
|
||||
QMessageBox.warning(self, "Input Error", "Email and Password are required")
|
||||
return
|
||||
|
||||
try:
|
||||
response = RequestClient().client.post(
|
||||
"/users/authorize",
|
||||
"http://localhost:3000/users/authorize",
|
||||
data={"username": username, "password": password},
|
||||
)
|
||||
if response.is_success:
|
||||
@ -132,12 +129,8 @@ class LoginWidget(QWidget):
|
||||
if access_token:
|
||||
self.switcher.login(access_token)
|
||||
else:
|
||||
QMessageBox.warning(
|
||||
self, "Error", "No access token received"
|
||||
)
|
||||
QMessageBox.warning(self, "Error", "No access token received")
|
||||
else:
|
||||
QMessageBox.warning(
|
||||
self, "Error", f"Login failed: {response.text}"
|
||||
)
|
||||
QMessageBox.warning(self, "Error", f"Login failed: {response.text}")
|
||||
except httpx.HTTPError as e:
|
||||
QMessageBox.critical(self, "HTTP Error", str(e))
|
||||
|
@ -1,11 +1,13 @@
|
||||
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
|
||||
@ -24,6 +26,7 @@ from PyQt6.QtWidgets import (
|
||||
QListWidget,
|
||||
QListWidgetItem,
|
||||
QMenu,
|
||||
QMessageBox,
|
||||
QPushButton,
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
@ -126,7 +129,7 @@ class FileListWidget(QListWidget):
|
||||
item = self.current_response().items()[row]
|
||||
item.double_click(self)
|
||||
|
||||
def current_response(self) -> ResponseProtocol:
|
||||
def current_response(self) -> ListResponse:
|
||||
if not self.responses:
|
||||
self.update_response()
|
||||
return self.responses[-1]
|
||||
@ -151,10 +154,28 @@ class FileListWidget(QListWidget):
|
||||
self.upload_file(file_path)
|
||||
|
||||
def upload_file(self, file_path):
|
||||
response = self.current_response()
|
||||
if not isinstance(response, ListResponse):
|
||||
return
|
||||
File.create(file_path, response.folder_id)
|
||||
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))
|
||||
|
||||
def add_item(self, item: DisplayProtocol):
|
||||
widget = QListWidgetItem(item.name())
|
||||
|
@ -9,9 +9,9 @@ class RequestClient:
|
||||
|
||||
def __new__(cls) -> Self:
|
||||
if cls._client is None:
|
||||
url = os.environ.get("DRIVE_HOST_URL")
|
||||
if url is None:
|
||||
url = "https://drive.stnicolay.ru"
|
||||
url = os.environ.get("DRIVE_HOST_URL").strip()
|
||||
if not url:
|
||||
url = "localhost:3000"
|
||||
cls._client = httpx.Client(base_url=url)
|
||||
return super().__new__(cls)
|
||||
|
||||
|
@ -1,18 +1,20 @@
|
||||
import auth
|
||||
import file_widgets
|
||||
import httpx
|
||||
import keyring
|
||||
import request_client
|
||||
import sync
|
||||
from PyQt6.QtWidgets import QMainWindow, QStackedWidget, QMessageBox
|
||||
from PyQt6.QtWidgets import QMainWindow, QStackedWidget
|
||||
|
||||
|
||||
class State(QMainWindow):
|
||||
def __init__(self):
|
||||
def __init__(self, url: str):
|
||||
super().__init__()
|
||||
|
||||
self.setWindowTitle("Auth App")
|
||||
|
||||
self.stack = QStackedWidget()
|
||||
self.client = httpx.Client(base_url=url)
|
||||
self.register_widget = auth.RegisterWidget(self)
|
||||
self.login_widget = auth.LoginWidget(self)
|
||||
|
||||
@ -36,22 +38,15 @@ class State(QMainWindow):
|
||||
self.stack.setCurrentWidget(self.register_widget)
|
||||
|
||||
def login(self, token: str):
|
||||
try:
|
||||
keyring.set_password("auth_app", "access_token", token)
|
||||
request_client.RequestClient().set_token(token)
|
||||
sync.SyncData.sync_all(
|
||||
# "/home/stnicolay/backups",
|
||||
# uuid.UUID("0191397f-ae77-7b2a-bed7-9d28ed56a90a"),
|
||||
)
|
||||
self.file_widget = file_widgets.MainFileWidget(self)
|
||||
self.stack.addWidget(self.file_widget)
|
||||
self.stack.setCurrentWidget(self.file_widget)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
keyring.delete_password("auth_app", "access_token")
|
||||
QMessageBox.information(
|
||||
None, "Error logging in", "Error logging in"
|
||||
)
|
||||
keyring.set_password("auth_app", "access_token", token)
|
||||
request_client.RequestClient().set_token(token)
|
||||
sync.SyncData.sync_all(
|
||||
# "/home/stnicolay/backups",
|
||||
# uuid.UUID("0191397f-ae77-7b2a-bed7-9d28ed56a90a"),
|
||||
)
|
||||
self.file_widget = file_widgets.MainFileWidget(self)
|
||||
self.stack.addWidget(self.file_widget)
|
||||
self.stack.setCurrentWidget(self.file_widget)
|
||||
|
||||
def logout(self):
|
||||
keyring.delete_password("auth_app", "access_token")
|
||||
|
Reference in New Issue
Block a user