mirror of
https://github.com/Syncplay/syncplay
synced 2025-02-28 08:50:26 +00:00
Implemented filename privacy settings
This commit is contained in:
parent
c3bd9e4630
commit
91a0998ee4
@ -9,6 +9,8 @@ from syncplay.protocols import SyncClientProtocol
|
|||||||
from syncplay import utils, constants
|
from syncplay import utils, constants
|
||||||
from syncplay.messages import getMessage
|
from syncplay.messages import getMessage
|
||||||
import threading
|
import threading
|
||||||
|
from syncplay.constants import PRIVACY_SENDHASHED_MODE, PRIVACY_DONTSEND_MODE,\
|
||||||
|
PRIVACY_HIDDENFILENAME
|
||||||
try:
|
try:
|
||||||
import libMal
|
import libMal
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -287,15 +289,33 @@ class SyncplayClient(object):
|
|||||||
size = os.path.getsize(path)
|
size = os.path.getsize(path)
|
||||||
except OSError: #file not accessible (stream?)
|
except OSError: #file not accessible (stream?)
|
||||||
size = 0
|
size = 0
|
||||||
|
filename, size = self.__executePrivacySettings(filename, size)
|
||||||
self.userlist.currentUser.setFile(filename, duration, size)
|
self.userlist.currentUser.setFile(filename, duration, size)
|
||||||
self.sendFile()
|
self.sendFile()
|
||||||
self._malUpdater.fileChangeHook(filename, duration)
|
self._malUpdater.fileChangeHook(filename, duration)
|
||||||
|
|
||||||
|
def __hashFilename(self, filename):
|
||||||
|
return hashlib.sha256(filename).hexdigest()[:12]
|
||||||
|
|
||||||
|
def __hashFilesize(self, size):
|
||||||
|
hashlib.sha256(str(size)).hexdigest()
|
||||||
|
|
||||||
|
def __executePrivacySettings(self, filename, size):
|
||||||
|
if (self._config['filenamePrivacyMode'] == PRIVACY_SENDHASHED_MODE):
|
||||||
|
filename = self.__hashFilename(filename)
|
||||||
|
elif (self._config['filenamePrivacyMode'] == PRIVACY_DONTSEND_MODE):
|
||||||
|
filename = PRIVACY_HIDDENFILENAME
|
||||||
|
if (self._config['filesizePrivacyMode'] == PRIVACY_SENDHASHED_MODE):
|
||||||
|
size = self.__hashFilesize(size)
|
||||||
|
elif (self._config['filesizePrivacyMode'] == PRIVACY_DONTSEND_MODE):
|
||||||
|
size = 0
|
||||||
|
return filename, size
|
||||||
|
|
||||||
def sendFile(self):
|
def sendFile(self):
|
||||||
file_ = self.userlist.currentUser.file
|
file_ = self.userlist.currentUser.file
|
||||||
if(self._protocol and self._protocol.logged and file_):
|
if(self._protocol and self._protocol.logged and file_):
|
||||||
self._protocol.sendFileSetting(file_)
|
self._protocol.sendFileSetting(file_)
|
||||||
|
|
||||||
def setUsername(self, username):
|
def setUsername(self, username):
|
||||||
self.userlist.currentUser.username = username
|
self.userlist.currentUser.username = username
|
||||||
|
|
||||||
|
@ -85,3 +85,4 @@ SERVER_MAX_TEMPLATE_LENGTH = 10000
|
|||||||
PRIVACY_SENDRAW_MODE = "SendRaw"
|
PRIVACY_SENDRAW_MODE = "SendRaw"
|
||||||
PRIVACY_SENDHASHED_MODE = "SendHashed"
|
PRIVACY_SENDHASHED_MODE = "SendHashed"
|
||||||
PRIVACY_DONTSEND_MODE = "DoNotSend"
|
PRIVACY_DONTSEND_MODE = "DoNotSend"
|
||||||
|
PRIVACY_HIDDENFILENAME = "**Hidden filename**"
|
||||||
|
Loading…
Reference in New Issue
Block a user