Skip to content

Commit

Permalink
feat(php): refresh file config
Browse files Browse the repository at this point in the history
  • Loading branch information
sshakndr committed Dec 13, 2024
1 parent 31649e7 commit b68b543
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Change Log

- php: refresh config
- ruby: refresh config
- python: refresh config
- java-spring: refresh config
Expand Down
5 changes: 5 additions & 0 deletions web/documentserver-example/php/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
45 changes: 45 additions & 0 deletions web/documentserver-example/php/src/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
];
}
}
3 changes: 2 additions & 1 deletion web/documentserver-example/php/src/helpers/ExampleUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public function __construct()
"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(
Expand Down
1 change: 1 addition & 0 deletions web/documentserver-example/php/src/views/DocEditorView.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public function __construct($request, $tempName = "docEditor")

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
Expand Down
12 changes: 12 additions & 0 deletions web/documentserver-example/php/templates/docEditor.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit b68b543

Please sign in to comment.