diff --git a/session.py b/session.py index 4963ff6..392b265 100644 --- a/session.py +++ b/session.py @@ -318,12 +318,16 @@ class Session(YowsupApp): image.caption = '' if image.isEncrypted(): self.logger.debug('Received encrypted image message') - ipath = "uploads/" + str(image.timestamp) + image.getExtension() - self.logger.debug('Received encrypted image message22') + if self.backend.specConf is not None and self.backend.specConf.__getitem__("service.web_directory") is not None and self.backend.specConf.__getitem__("service.web_url") is not None : + ipath = "/" + str(image.timestamp) + image.getExtension() + + with open(self.backend.specConf.__getitem__("service.web_directory") + ipath,"wb") as f: + f.write(image.getMediaContent()) + url = self.backend.specConf.__getitem__("service.web_url") + ipath + else: + self.logger.warn('Received encrypted image: web storage not set in config!') + url = image.url - with open("/srv/www/htdocs/" + ipath,"wb") as f: - f.write(image.getMediaContent()) - url = "http://www/" + ipath else: url = image.url if participant is not None: # Group message diff --git a/transwhat.py b/transwhat.py index 4273ca5..7612419 100755 --- a/transwhat.py +++ b/transwhat.py @@ -35,7 +35,7 @@ import threadutils sys.path.insert(0, os.getcwd()) from Spectrum2.iochannel import IOChannel - +from config import SpectrumConfig from whatsappbackend import WhatsAppBackend from yowsup.common import YowConstants from yowsup.stacks import YowStack @@ -64,6 +64,11 @@ logging.basicConfig( level = logging.DEBUG if args.debug else logging.INFO ) +if args.config is not None: + specConf = SpectrumConfig(args.config) +else: + specConf = None + # Handler def handleTransportData(data): try: @@ -84,7 +89,7 @@ def connectionClosed(): # Main io = IOChannel(args.host, args.port, handleTransportData, connectionClosed) -plugin = WhatsAppBackend(io, args.j) +plugin = WhatsAppBackend(io, args.j, specConf) plugin.handleBackendConfig({ 'features': [ diff --git a/whatsappbackend.py b/whatsappbackend.py index 93ea1fd..f47bc7d 100644 --- a/whatsappbackend.py +++ b/whatsappbackend.py @@ -30,10 +30,11 @@ from registersession import RegisterSession import logging class WhatsAppBackend(SpectrumBackend): - def __init__(self, io, spectrum_jid): + def __init__(self, io, spectrum_jida, specConf): SpectrumBackend.__init__(self) self.logger = logging.getLogger(self.__class__.__name__) self.io = io + self.specConf = specConf self.sessions = { } self.spectrum_jid = spectrum_jid # Used to prevent duplicate messages