Skip to content

Commit

Permalink
Database and settings updated
Browse files Browse the repository at this point in the history
  • Loading branch information
yashoswalyo committed Oct 17, 2022
1 parent 65045f1 commit b620f6f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 3 additions & 1 deletion helpers/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def getUserMergeSettings(uid: int):
return None


def setUserMergeSettings(uid: int, name: str, mode, edit_metadata, allowed, thumbnail):
def setUserMergeSettings(uid: int, name: str, mode, edit_metadata,banned, allowed, thumbnail):
modes = Config.MODES
if uid:
try:
Expand All @@ -114,6 +114,7 @@ def setUserMergeSettings(uid: int, name: str, mode, edit_metadata, allowed, thum
"edit_metadata": edit_metadata,
},
"isAllowed": allowed,
"isBanned": banned,
"thumbnail": thumbnail,
}
)
Expand All @@ -128,6 +129,7 @@ def setUserMergeSettings(uid: int, name: str, mode, edit_metadata, allowed, thum
"edit_metadata": edit_metadata,
},
"isAllowed": allowed,
"isBanned": banned,
"thumbnail": thumbnail,
},
)
Expand Down
25 changes: 23 additions & 2 deletions helpers/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# (c) dishapatel010

import pickle
import os.path
import os
import threading
import time
from helpers.database import setUserMergeSettings, getUserMergeSettings
# from magic import Magic
SIZE_UNITS = ["B", "KB", "MB", "GB", "TB", "PB"]


Expand All @@ -19,6 +21,21 @@ def get_readable_file_size(size_in_bytes) -> str:
except IndexError:
return "File too large"

def get_mime_type(file_path):
mime = 1
mime_type = mime.from_file(file_path)
mime_type = mime_type or "text/plain"
return mime_type

def get_path_size(path: str):
if os.path.isfile(path):
return os.path.getsize(path)
total_size = 0
for root, dirs, files in os.walk(path):
for f in files:
abs_path = os.path.join(root, f)
total_size += os.path.getsize(abs_path)
return total_size

def get_readable_time(seconds: int) -> str:
result = ""
Expand All @@ -38,13 +55,14 @@ def get_readable_time(seconds: int) -> str:
result += f"{seconds}s"
return result
class UserSettings(object):
def __init__(self, uid: int, name: str):
def __init__(self, uid: int, name:str):
self.user_id: int = uid
self.name: str = name
self.merge_mode: int = 1
self.edit_metadata: bool = False
self.allowed: bool = False
self.thumbnail = None
self.banned:bool = False
self.get()
# def __init__(self,uid:int,name:str,merge_mode:int=1,edit_metadata=False) -> None:

Expand All @@ -56,6 +74,7 @@ def get(self):
self.edit_metadata = cur["user_settings"]["edit_metadata"]
self.allowed = cur["isAllowed"]
self.thumbnail = cur["thumbnail"]
self.banned = cur["isBanned"]
return {
"uid": self.user_id,
"name": self.name,
Expand All @@ -64,6 +83,7 @@ def get(self):
"edit_metadata": self.edit_metadata,
},
"isAllowed": self.allowed,
"isBanned": self.banned,
"thumbnail": self.thumbnail,
}
else: return self.set()
Expand All @@ -74,6 +94,7 @@ def set(self):
name=self.name,
mode=self.merge_mode,
edit_metadata=self.edit_metadata,
banned=self.banned,
allowed=self.allowed,
thumbnail=self.thumbnail,
)
Expand Down

0 comments on commit b620f6f

Please sign in to comment.