mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
Merge pull request #365 from ONLYOFFICE/feature/save-files-format
Feature/save files format
This commit is contained in:
@ -23,7 +23,7 @@ import config
|
||||
from . import fileUtils, jwtManager
|
||||
|
||||
# convert file and give url to a new file
|
||||
def getConverterUri(docUri, fromExt, toExt, docKey, isAsync, filePass = None, lang = None):
|
||||
def getConvertedData(docUri, fromExt, toExt, docKey, isAsync, filePass = None, lang = None):
|
||||
if not fromExt: # check if the extension from the request matches the real file extension
|
||||
fromExt = fileUtils.getFileExt(docUri) # if not, overwrite the extension value
|
||||
|
||||
@ -66,7 +66,7 @@ def getResponseUri(json):
|
||||
processError(error)
|
||||
|
||||
if isEnd:
|
||||
return json.get('fileUrl')
|
||||
return { 'uri': json.get('fileUrl'), 'fileType': json.get('fileType') }
|
||||
|
||||
# display an error that occurs during conversion
|
||||
def processError(error):
|
||||
|
||||
@ -58,11 +58,11 @@ def processSave(body, filename, usAddr):
|
||||
# convert downloaded file to the file with the current extension if these extensions aren't equal
|
||||
if (curExt != downloadExt):
|
||||
try:
|
||||
newUri = serviceConverter.getConverterUri(download, downloadExt, curExt, docManager.generateRevisionId(download), False) # convert file and give url to a new file
|
||||
if not newUri:
|
||||
convertedData = serviceConverter.getConvertedData(download, downloadExt, curExt, docManager.generateRevisionId(download), False) # convert file and give url to a new file
|
||||
if not convertedData:
|
||||
newFilename = docManager.getCorrectName(fileUtils.getFileNameWithoutExt(filename) + downloadExt, usAddr) # get the correct file name if it already exists
|
||||
else:
|
||||
download = newUri
|
||||
download = convertedData['uri']
|
||||
except Exception:
|
||||
newFilename = docManager.getCorrectName(fileUtils.getFileNameWithoutExt(filename) + downloadExt, usAddr)
|
||||
|
||||
@ -116,11 +116,11 @@ def processForceSave(body, filename, usAddr):
|
||||
# convert downloaded file to the file with the current extension if these extensions aren't equal
|
||||
if (curExt != downloadExt):
|
||||
try:
|
||||
newUri = serviceConverter.getConverterUri(download, downloadExt, curExt, docManager.generateRevisionId(download), False) # convert file and give url to a new file
|
||||
if not newUri:
|
||||
convertedData = serviceConverter.getConvertedData(download, downloadExt, curExt, docManager.generateRevisionId(download), False) # convert file and give url to a new file
|
||||
if not convertedData:
|
||||
newFilename = True
|
||||
else:
|
||||
download = newUri
|
||||
download = convertedData['uri']
|
||||
except Exception:
|
||||
newFilename = True
|
||||
|
||||
|
||||
@ -71,15 +71,15 @@ def convert(request):
|
||||
if docManager.isCanConvert(fileExt): # check if the file extension is available for converting
|
||||
key = docManager.generateFileKey(filename, request) # generate the file key
|
||||
|
||||
newUri = serviceConverter.getConverterUri(fileUri, fileExt, newExt, key, True, filePass, lang) # get the url of the converted file
|
||||
convertedData = serviceConverter.getConvertedData(fileUri, fileExt, newExt, key, True, filePass, lang) # get the url of the converted file
|
||||
|
||||
if not newUri: # if the converter url is not received, the original file name is passed to the response
|
||||
if not convertedData: # if the converter url is not received, the original file name is passed to the response
|
||||
response.setdefault('step', '0')
|
||||
response.setdefault('filename', filename)
|
||||
else:
|
||||
correctName = docManager.getCorrectName(fileUtils.getFileNameWithoutExt(filename) + newExt, request) # otherwise, create a new name with the necessary extension
|
||||
correctName = docManager.getCorrectName(fileUtils.getFileNameWithoutExt(filename) + '.' + convertedData['fileType'], request) # otherwise, create a new name with the necessary extension
|
||||
path = docManager.getStoragePath(correctName, request)
|
||||
docManager.downloadFileFromUri(newUri, path, True) # save the file from the new url in the storage directory
|
||||
docManager.downloadFileFromUri(convertedData['uri'], path, True) # save the file from the new url in the storage directory
|
||||
docManager.removeFile(filename, request) # remove the original file
|
||||
response.setdefault('filename', correctName) # pass the name of the converted file to the response
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user