mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
feat(php): refresh file config
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
- php: refresh config
|
||||||
- ruby: refresh config
|
- ruby: refresh config
|
||||||
- python: refresh config
|
- python: refresh config
|
||||||
- java-spring: refresh config
|
- java-spring: refresh config
|
||||||
|
|||||||
@ -171,6 +171,11 @@ function routers()
|
|||||||
echo json_encode($response);
|
echo json_encode($response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (str_starts_with($path, '/config')) {
|
||||||
|
$response = config();
|
||||||
|
echo json_encode($response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
http_response_code(HTTPStatus::NotFound->value);
|
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 rename files from the editor",
|
||||||
"Can't view chat",
|
"Can't view chat",
|
||||||
"View file without collaboration",
|
"View file without collaboration",
|
||||||
"Can’t submit forms"
|
"Can’t submit forms",
|
||||||
|
"Can’t refresh outdated file"
|
||||||
];
|
];
|
||||||
$this->users = [
|
$this->users = [
|
||||||
new Users(
|
new Users(
|
||||||
|
|||||||
@ -254,6 +254,7 @@ final class DocEditorView extends View
|
|||||||
|
|
||||||
if ($user->id != "uid-0") {
|
if ($user->id != "uid-0") {
|
||||||
$historyLayout .= "// add mentions for not anonymous users
|
$historyLayout .= "// add mentions for not anonymous users
|
||||||
|
config.events['onRequestRefreshFile'] = onRequestRefreshFile;
|
||||||
config.events['onRequestUsers'] = onRequestUsers;
|
config.events['onRequestUsers'] = onRequestUsers;
|
||||||
config.events['onRequestSaveAs'] = onRequestSaveAs;
|
config.events['onRequestSaveAs'] = onRequestSaveAs;
|
||||||
// the user is mentioned in a comment
|
// 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
|
var onRequestReferenceData = function(event) { // user refresh external data source
|
||||||
innerAlert("onRequestReferenceData");
|
innerAlert("onRequestReferenceData");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user