Skip to content

Commit

Permalink
Fix - Check file paths before trying to upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Itz-fork authored Sep 28, 2021
1 parent 9605eba commit 6b799f5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
15 changes: 10 additions & 5 deletions gofile2/async_gofile2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 ""
Expand Down
3 changes: 3 additions & 0 deletions gofile2/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 7 additions & 2 deletions gofile2/gofile2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")

0 comments on commit 6b799f5

Please sign in to comment.