1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-18 08:16:07 +00:00

add ONLYOFFICE_FORCE_SAVE setting (#3934)

* add ONLYOFFICE_FORCE_SAVE setting

* update comment
This commit is contained in:
lian
2019-08-09 14:24:06 +08:00
committed by Daniel Pan
parent c9b99ad700
commit 11152071c6
4 changed files with 41 additions and 3 deletions

View File

@@ -6,3 +6,6 @@ ONLYOFFICE_APIJS_URL = getattr(settings, 'ONLYOFFICE_APIJS_URL', '')
ONLYOFFICE_FILE_EXTENSION = getattr(settings, 'ONLYOFFICE_FILE_EXTENSION', ())
ONLYOFFICE_EDIT_FILE_EXTENSION = getattr(settings, 'ONLYOFFICE_EDIT_FILE_EXTENSION', ())
VERIFY_ONLYOFFICE_CERTIFICATE = getattr(settings, 'VERIFY_ONLYOFFICE_CERTIFICATE', True)
# if True, file will be saved when user click save btn on file editing page
ONLYOFFICE_FORCE_SAVE = getattr(settings, 'ONLYOFFICE_FORCE_SAVE', False)

View File

@@ -11,10 +11,16 @@ from django.utils.encoding import force_bytes
from seaserv import seafile_api
from seahub.utils import get_file_type_and_ext, gen_file_get_url, \
get_site_scheme_and_netloc
get_site_scheme_and_netloc, normalize_cache_key
from seahub.settings import ENABLE_WATERMARK
from seahub.onlyoffice.settings import ONLYOFFICE_APIJS_URL
from seahub.onlyoffice.settings import ONLYOFFICE_APIJS_URL, \
ONLYOFFICE_FORCE_SAVE
def generate_onlyoffice_cache_key(repo_id, file_path):
prefix = "ONLYOFFICE_"
value = "%s_%s" % (repo_id, file_path)
return normalize_cache_key(value, prefix)
def get_onlyoffice_dict(username, repo_id, file_path,
file_id='', can_edit=False, can_download=True):
@@ -47,8 +53,18 @@ def get_onlyoffice_dict(username, repo_id, file_path,
else:
document_type = 'text'
cache_key = generate_onlyoffice_cache_key(repo_id, file_path)
doc_key = cache.get(cache_key)
# temporary solution when failed to get data from cache(django_pylibmc)
# when init process for the first time
if not doc_key:
doc_key = cache.get(cache_key)
if not doc_key:
doc_key = hashlib.md5(force_bytes(origin_repo_id + origin_file_path + file_id)).hexdigest()[:20]
doc_info = json.dumps({'repo_id': repo_id, 'file_path': file_path, 'username': username})
doc_key = hashlib.md5(force_bytes(origin_repo_id + origin_file_path + file_id)).hexdigest()[:20]
cache.set("ONLYOFFICE_%s" % doc_key, doc_info, None)
file_name = os.path.basename(file_path.rstrip('/'))
@@ -71,6 +87,7 @@ def get_onlyoffice_dict(username, repo_id, file_path,
'can_edit': can_edit,
'can_download': can_download,
'username': username,
'onlyoffice_force_save': ONLYOFFICE_FORCE_SAVE,
'enable_watermark': ENABLE_WATERMARK and not can_edit,
}

View File

@@ -10,6 +10,7 @@ from django.views.decorators.csrf import csrf_exempt
from seaserv import seafile_api
from seahub.onlyoffice.settings import VERIFY_ONLYOFFICE_CERTIFICATE
from seahub.onlyoffice.utils import generate_onlyoffice_cache_key
from seahub.utils import gen_inner_file_upload_url
# Get an instance of a logger
@@ -73,7 +74,11 @@ def onlyoffice_editor_callback(request):
post_data = json.loads(request.body)
status = int(post_data.get('status', -1))
# When forcesave is initiated, document editing service performs request to
# the callback handler with the link to the document as the url parameter and
# with the 6 value for the status parameter.
if status in (2, 6):
# Defines the link to the edited document to be saved with the document storage service.
# The link is present when the status value is equal to 2 or 3 only.
url = post_data.get('url')
@@ -90,6 +95,16 @@ def onlyoffice_editor_callback(request):
file_path = doc_info['file_path']
username = doc_info['username']
cache_key = generate_onlyoffice_cache_key(repo_id, file_path)
# cache document key when forcesave
if status == 6:
cache.set(cache_key, doc_key)
# remove document key from cache when document is ready for saving
# no one is editting
if status == 2:
cache.delete(cache_key)
fake_obj_id = {'online_office_update': True,}
update_token = seafile_api.get_fileserver_access_token(repo_id,
json.dumps(fake_obj_id), 'update', username)

View File

@@ -39,6 +39,9 @@ html, body { padding:0; margin:0; height:100%; }
"callbackUrl": "{{ callback_url }}",
"lang": "{{ LANGUAGE_CODE }}",
"mode": {% if can_edit %}"edit"{% else %}"view"{% endif %},
"customization": {
"forcesave": {% if onlyoffice_force_save %}true{% else %}false{% endif %},
},
"user": {
"name": "{{ username|email2nickname|escapejs }}"
}