feat(python): refresh file config

This commit is contained in:
sshakndr
2024-12-13 12:49:15 +07:00
parent 6511fbbf55
commit 12495facdb
5 changed files with 60 additions and 3 deletions

View File

@ -1,5 +1,6 @@
# Change Log
- python: refresh config
- java-spring: refresh config
- java: refresh config
- go: refresh config

View File

@ -83,7 +83,8 @@ def routers():
path('saveas', actions.saveAs),
path('track', actions.track),
path('upload', actions.upload),
path('formats', actions.formats)
path('formats', actions.formats),
path('config', actions.config)
]
main += static(
settings.STATIC_URL,

View File

@ -90,7 +90,8 @@ descr_user_0 = [
"Can't view chat",
"Can't protect file",
"View file without collaboration",
"Cant submit forms"
"Cant submit forms",
"Can't refresh outdated file"
]
USERS = [

View File

@ -691,3 +691,45 @@ def formats(request: HttpRequest) -> HttpResponse:
}
return HttpResponse(json.dumps(data), content_type='application/json')
@http.GET()
def config(request: HttpRequest) -> HttpResponse:
try:
filename = fileUtils.getFileName(request.GET['fileName'])
directUrl = fileUtils.getFileName(request.GET['directUrl']) == "true"
permissions = fileUtils.getFileName(request.GET['permissions'])
if not os.path.exists(docManager.getStoragePath(filename, request)):
raise Exception("File not found")
user = users.getUserFromReq(request)
config = {
'document': {
'title': filename,
'key': docManager.generateFileKey(filename, request),
'url': docManager.getDownloadUrl(filename, request),
'permissions': json.loads(permissions),
'directUrl': docManager.getDownloadUrl(filename, request, False) if directUrl else None,
'referenceData': {
'instanceId': docManager.getServerUrl(False, request),
'fileKey': json.dumps({'fileName': filename,
'userAddress': request.META['REMOTE_ADDR']}) if user.id != 'uid-0' else None
},
},
'editorConfig': {
'mode': 'edit',
'callbackUrl': docManager.getCallbackUrl(filename, request)
}
}
if jwtManager.isEnabled():
config['token'] = jwtManager.encode(config)
return HttpResponse(json.dumps(config), content_type='application/json')
except Exception as error:
return ErrorResponse(
message=f'{type(error)}: {error}',
status=HTTPStatus.INTERNAL_SERVER_ERROR
)

View File

@ -191,6 +191,18 @@
});
};
var onRequestRefreshFile = function(event) {
let xhr = new XMLHttpRequest();
xhr.open("GET", "config?fileName=" + encodeURIComponent(config.document.title) +
"&directUrl=" + !!config.document.directUrl +
"&permissions=" + encodeURIComponent(JSON.stringify(config.document.permissions)));
xhr.send();
xhr.onload = function () {
innerAlert(xhr.responseText);
docEditor.refreshFile(JSON.parse(xhr.responseText));
};
};
var onRequestReferenceData = function(event) { // user refresh external data source
innerAlert("onRequestReferenceData");
@ -364,7 +376,7 @@
};
if (config.editorConfig.user.id) {
config.events['onRequestRefreshFile'] = onRequestRefreshFile;
config.events['onRequestClose'] = onRequestClose
// add mentions for not anonymous users
config.events['onRequestUsers'] = onRequestUsers;