Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling the creation of zmd files in CodiMD #49

Merged
merged 2 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/bridge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def init(cls, config, log, secret):
cls.sslverify = config.get('bridge', 'sslverify', fallback='True').upper() in ('TRUE', 'YES')
cls.saveinterval = int(config.get('bridge', 'saveinterval', fallback='200'))
cls.unlockinterval = int(config.get('bridge', 'unlockinterval', fallback='90'))
cls.disablezip = config.get('bridge', 'disablezip', fallback='False').upper() in ('TRUE', 'YES')
cls.hashsecret = secret
cls.log = wopic.log = log
wopic.sslverify = cls.sslverify
Expand All @@ -83,6 +84,7 @@ def loadplugin(cls, appname, appurl, appinturl, apikey):
cls.plugins[p] = __import__('bridge.' + p, globals(), locals(), [p])
cls.plugins[p].log = cls.log
cls.plugins[p].sslverify = cls.sslverify
cls.plugins[p].disablezip = cls.disablezip
cls.plugins[p].init(appurl, appinturl, apikey)
cls.log.info('msg="Imported plugin for application" app="%s" plugin="%s"' % (p, cls.plugins[p]))
except Exception as e:
Expand All @@ -109,7 +111,7 @@ def isextsupported(fileext):

def _gendocid(wopisrc):
'''Generate a URL safe hash of the wopisrc to be used as document id by the app'''
dig = hmac.new(WB.hashsecret.encode(), msg=wopisrc.split('/')[-1].encode(), digestmod=hashlib.sha1).digest()
dig = hmac.new(WB.hashsecret.encode(), msg=wopisrc.split('/')[-1].encode(), digestmod=hashlib.blake2b).digest()
return urlsafe_b64encode(dig).decode()[:-1]


Expand Down
7 changes: 5 additions & 2 deletions src/bridge/codimd.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class AppFailure(Exception):
apikey = None
log = None
sslverify = None
disablezip = None


def init(_appurl, _appinturl, _apikey):
Expand Down Expand Up @@ -253,8 +254,10 @@ def savetostorage(wopisrc, acctok, isclose, wopilock):

# check if we have attachments
wasbundle = os.path.splitext(wopilock['filename'])[1] == '.zmd'
bundlefile, attresponse = _getattachments(mddoc.decode(), wopilock['filename'].replace('.zmd', '.md'),
(wasbundle and not isclose))
bundlefile = attresponse = None
if not disablezip or wasbundle: # in disablezip mode, preserve existing .zmd files but don't create new ones
bundlefile, attresponse = _getattachments(mddoc.decode(), wopilock['filename'].replace('.zmd', '.md'),
(wasbundle and not isclose))

# WOPI PutFile for the file or the bundle if it already existed
if (wasbundle ^ (not bundlefile)) or not isclose:
Expand Down
3 changes: 3 additions & 0 deletions wopiserver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ wopikey = /etc/grid-security/host.key
# Minimal time interval before a closed file is WOPI-unlocked [seconds]
#unlockinterval = 90

# CodiMD: disable creating zipped bundles when files contain pictures
#disablezip = False


[io]
# Size used for buffered reads [bytes]
Expand Down