diff --git a/gofile2/async_gofile2.py b/gofile2/async_gofile2.py index 68ae071..2f7ea57 100644 --- a/gofile2/async_gofile2.py +++ b/gofile2/async_gofile2.py @@ -2,7 +2,9 @@ # Re-built by Itz-fork # Project: Gofile2 import aiohttp -from .errors import is_valid_token, InvalidToken, JobFailed, ResponseError +import os + +from .errors import is_valid_token, InvalidToken, JobFailed, ResponseError, InvalidPath class Async_Gofile: @@ -91,11 +93,14 @@ async def upload(self, file: str, folderId: str = "", description: str = "", pas password (optional) - Password for the folder. Not applicable if you specify a folderId tags (optional) - Tags for the folder. If multiple tags, seperate them with comma. Not applicable if you specify a folderId expire (optional) - Expiration date of the folder. Must be in the form of unix timestamp. Not applicable if you specify a folderId - """ - if password and len(password) < 4: - raise ValueError("Password Length must be greater than 4") - + """ async with self.r_session as session: + # Check time + if not os.path.isfile(file): + raise InvalidPath(f"No such file - {file}") + if password and len(password) < 4: + raise ValueError("Password Length must be greater than 4") + server = await self.get_Server(pre_session=session) server = server["server"] token = self.token if self.token else "" diff --git a/gofile2/errors.py b/gofile2/errors.py index 190c1f9..6e67944 100644 --- a/gofile2/errors.py +++ b/gofile2/errors.py @@ -13,6 +13,9 @@ class JobFailed(Exception): class ResponseError(Exception): pass +class InvalidPath(Exception): + pass + # Function to check if token is valid or not (using request lib as this is just a sync function) def is_valid_token(url, token): get_account_resp = requests.get(url=f"{url}getAccountDetails?token={token}&allDetails=true").json() diff --git a/gofile2/gofile2.py b/gofile2/gofile2.py index 737b67d..5a33a79 100644 --- a/gofile2/gofile2.py +++ b/gofile2/gofile2.py @@ -2,7 +2,9 @@ # Re-built by Itz-fork # Project: Gofile2 import requests -from .errors import is_valid_token, InvalidToken, JobFailed, ResponseError +import os + +from .errors import is_valid_token, InvalidToken, JobFailed, ResponseError, InvalidPath class Gofile: @@ -83,6 +85,9 @@ def upload(self,file: str, folderId: str = None, description: str = None, passwo tags (optional) - Tags for the folder. If multiple tags, seperate them with comma. Not applicable if you specify a folderId expire (optional) - Expiration date of the folder. Must be in the form of unix timestamp. Not applicable if you specify a folderId """ + if not os.path.isfile(file): + raise InvalidPath(f"No such file - {file}") + token = self.token if password != None and len(password) < 4: raise ValueError("Password Length must be greater than 4") @@ -184,4 +189,4 @@ def delete_content(self, contentId): ).json() return self._api_resp_handler(del_content_resp) except Exception as e: - raise JobFailed(f"Error Happend: {e} \n\nReport this at ----> https://github.com/Itz-fork/Gofile2/issues") + raise JobFailed(f"Error Happend: {e} \n\nReport this at ----> https://github.com/Itz-fork/Gofile2/issues") \ No newline at end of file