mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-02-10 18:05:10 +08:00
feat(php): refresh file config
This commit is contained in:
@ -171,6 +171,11 @@ function routers()
|
||||
echo json_encode($response);
|
||||
return;
|
||||
}
|
||||
if (str_starts_with($path, '/config')) {
|
||||
$response = config();
|
||||
echo json_encode($response);
|
||||
return;
|
||||
}
|
||||
|
||||
http_response_code(HTTPStatus::NotFound->value);
|
||||
}
|
||||
|
||||
@ -707,3 +707,48 @@ function formats()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
function config()
|
||||
{
|
||||
try {
|
||||
$fileName = $_GET["fileName"];
|
||||
$directUrl = $_GET["directUrl"] == "true";
|
||||
$permissions = $_GET["permissions"];
|
||||
|
||||
if (!file_exists(getStoragePath($fileName))) {
|
||||
throw new Exception("File not found ".$fileName);
|
||||
}
|
||||
|
||||
$config = [
|
||||
"document" => [
|
||||
"title" => $fileName,
|
||||
"key" => getDocEditorKey($fileName),
|
||||
"url" => getDownloadUrl($fileName),
|
||||
"directUrl" => $directUrl ? getDownloadUrl($fileName, false) : null,
|
||||
"permissions" => json_decode($permissions),
|
||||
"referenceData" => [
|
||||
"fileKey" => json_encode([
|
||||
"fileName" => $fileName,
|
||||
"userAddress" => getCurUserHostAddress()
|
||||
]),
|
||||
"instanceId" => serverPath(),
|
||||
]
|
||||
],
|
||||
"editorConfig" => [
|
||||
"mode" => "edit",
|
||||
"callbackUrl" => getCallbackUrl($fileName)
|
||||
]
|
||||
];
|
||||
|
||||
$jwtManager = new JwtManager();
|
||||
if ($jwtManager->isJwtEnabled()) {
|
||||
$config["token"] = $jwtManager->jwtEncode($config);
|
||||
}
|
||||
|
||||
return $config;
|
||||
} catch (Exception $error) {
|
||||
return [
|
||||
'error' => $error->getMessage()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +78,8 @@ final class ExampleUsers
|
||||
"Can't rename files from the editor",
|
||||
"Can't view chat",
|
||||
"View file without collaboration",
|
||||
"Can’t submit forms"
|
||||
"Can’t submit forms",
|
||||
"Can’t refresh outdated file"
|
||||
];
|
||||
$this->users = [
|
||||
new Users(
|
||||
|
||||
@ -254,6 +254,7 @@ final class DocEditorView extends View
|
||||
|
||||
if ($user->id != "uid-0") {
|
||||
$historyLayout .= "// add mentions for not anonymous users
|
||||
config.events['onRequestRefreshFile'] = onRequestRefreshFile;
|
||||
config.events['onRequestUsers'] = onRequestUsers;
|
||||
config.events['onRequestSaveAs'] = onRequestSaveAs;
|
||||
// the user is mentioned in a comment
|
||||
|
||||
@ -116,6 +116,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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user