python: option to send directUrl

This commit is contained in:
Vladimir Kurguzov
2022-11-01 23:09:36 +03:00
committed by Sergey Linnik
parent 7c22ba4e9e
commit ae3def67f5
6 changed files with 81 additions and 25 deletions

View File

@ -152,7 +152,7 @@ def getMeta(storagePath):
return None
# get the document history of a given file
def getHistoryObject(storagePath, filename, docKey, docUrl, req):
def getHistoryObject(storagePath, filename, docKey, docUrl, isEnableDirectUrl, req):
histDir = getHistoryDir(storagePath)
version = getFileVersion(histDir)
if version > 0: # if the file was modified (the file version is greater than 0)
@ -184,7 +184,8 @@ def getHistoryObject(storagePath, filename, docKey, docUrl, req):
}
dataObj['url'] = docUrl if i == version else getPublicHistUri(filename, i, "prev" + fileUtils.getFileExt(filename), req) # write file url to the data object
dataObj['directUrl'] = docManager.getDownloadUrl(filename, req, False) if i == version else getPublicHistUri(filename, i, "prev" + fileUtils.getFileExt(filename), req, False) # write file direct url to the data object
if isEnableDirectUrl:
dataObj['directUrl'] = docManager.getDownloadUrl(filename, req, False) if i == version else getPublicHistUri(filename, i, "prev" + fileUtils.getFileExt(filename), req, False) # write file direct url to the data object
if i > 1: # check if the version number is greater than 1 (the file was modified)
changes = json.loads(readFile(getChangesHistoryPath(prevVerDir))) # get the path to the changes.json file
@ -201,6 +202,10 @@ def getHistoryObject(storagePath, filename, docKey, docUrl, req):
'key': prev['key'],
'url': prev['url'],
'directUrl': prev['directUrl']
} if isEnableDirectUrl else { # write key and url information about previous file version
'fileType': prev['fileType'],
'key': prev['key'],
'url': prev['url']
}
dataObj['previous'] = prevInfo # write information about previous file version to the data object
dataObj['changesUrl'] = getPublicHistUri(filename, i - 1, "diff.zip", req) # write the path to the diff.zip archive with differences in this file version

View File

@ -171,6 +171,7 @@ def rename(request):
# edit a file
def edit(request):
filename = fileUtils.getFileName(request.GET['filename'])
isEnableDirectUrl = request.GET['directUrl'].lower() in ("true") if 'directUrl' in request.GET else False
ext = fileUtils.getFileExt(filename)
@ -234,7 +235,7 @@ def edit(request):
'document': {
'title': filename,
'url': docManager.getDownloadUrl(filename, request),
'directUrl': directUrl,
'directUrl': directUrl if isEnableDirectUrl else "",
'fileType': ext[1:],
'key': docKey,
'info': infObj,
@ -295,6 +296,9 @@ def edit(request):
'fileType': 'png',
'url': docManager.getServerUrl(True, request) + 'static/images/logo.png',
'directUrl': docManager.getServerUrl(False, request) + 'static/images/logo.png'
} if isEnableDirectUrl else {
'fileType': 'png',
'url': docManager.getServerUrl(True, request) + 'static/images/logo.png'
}
# a document which will be compared with the current document
@ -302,6 +306,9 @@ def edit(request):
'fileType': 'docx',
'url': docManager.getServerUrl(True, request) + 'static/sample.docx',
'directUrl': docManager.getServerUrl(False, request) + 'static/sample.docx'
} if isEnableDirectUrl else {
'fileType': 'docx',
'url': docManager.getServerUrl(True, request) + 'static/sample.docx'
}
# recipient data for mail merging
@ -309,6 +316,9 @@ def edit(request):
'fileType': 'csv',
'url': docManager.getServerUrl(True, request) + 'csv',
'directUrl': docManager.getServerUrl(False, request) + 'csv'
} if isEnableDirectUrl else {
'fileType': 'csv',
'url': docManager.getServerUrl(True, request) + 'csv'
}
# users data for mentions
@ -320,7 +330,7 @@ def edit(request):
dataCompareFile['token'] = jwtManager.encode(dataCompareFile) # encode the dataCompareFile object into a token
dataMailMergeRecipients['token'] = jwtManager.encode(dataMailMergeRecipients) # encode the dataMailMergeRecipients object into a token
hist = historyManager.getHistoryObject(storagePath, filename, docKey, fileUri, request) # get the document history
hist = historyManager.getHistoryObject(storagePath, filename, docKey, fileUri, isEnableDirectUrl, request) # get the document history
context = { # the data that will be passed to the template
'cfg': json.dumps(edConfig), # the document config in json format

View File

@ -24,6 +24,8 @@
"""
import re
import sys
import config
import json
@ -32,6 +34,12 @@ from django.shortcuts import render
from src.utils import users
from src.utils import docManager
def getDirectUrlParam(request):
if ('directUrl' in request.GET):
return request.GET['directUrl'].lower() in ("true")
else:
return False;
def default(request): # default parameters that will be passed to the template
context = {
'users': users.USERS,
@ -40,6 +48,7 @@ def default(request): # default parameters that will be passed to the template
'editExt': json.dumps(config.DOC_SERV_EDITED), # file extensions that can be edited
'convExt': json.dumps(config.DOC_SERV_CONVERT), # file extensions that can be converted
'files': docManager.getStoredFiles(request), # information about stored files
'fillExt': json.dumps(config.DOC_SERV_FILLFORMS)
'fillExt': json.dumps(config.DOC_SERV_FILLFORMS),
'directUrl': str(getDirectUrlParam(request)).lower
}
return render(request, 'index.html', context) # execute the "index.html" template with context data and return http response in json format