mirror of
https://github.com/ONLYOFFICE/onlyoffice-owncloud.git
synced 2025-04-18 13:24:05 +03:00
feat: reference data - find file id by link
This commit is contained in:
parent
2378351fed
commit
50e05b5259
@ -4,6 +4,7 @@
|
||||
- setting for setup unknown author display name
|
||||
- setting for sending notifications by email
|
||||
- opening docm, xlsm, pptm files
|
||||
- support IMPORTRANGE
|
||||
|
||||
## Changed
|
||||
- URL for requests to Conversion API
|
||||
|
@ -614,13 +614,14 @@ class EditorController extends Controller {
|
||||
*
|
||||
* @param array $referenceData - reference data
|
||||
* @param string $path - file path
|
||||
* @param string $link - file link
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @NoAdminRequired
|
||||
* @PublicPage
|
||||
*/
|
||||
public function reference($referenceData, $path = null) {
|
||||
public function reference($referenceData, $path = null, $link = null) {
|
||||
$this->logger->debug("reference: " . json_encode($referenceData) . " $path", ["app" => $this->appName]);
|
||||
|
||||
if (!$this->config->isUserAllowedToUse()) {
|
||||
@ -655,6 +656,15 @@ class EditorController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
if ($file === null
|
||||
&& !empty($link)
|
||||
) {
|
||||
$fileId = $this->getFileIdByLink($link);
|
||||
if (!empty($fileId)) {
|
||||
list($file, $error, $share) = $this->getFile($userId, $fileId);
|
||||
}
|
||||
}
|
||||
|
||||
if ($file === null) {
|
||||
$this->logger->error("Reference not found: $fileId $path", ["app" => $this->appName]);
|
||||
return ["error" => $this->trans->t("File not found")];
|
||||
@ -1572,6 +1582,38 @@ class EditorController extends Controller {
|
||||
return $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get File id from by link
|
||||
*
|
||||
* @param string $link - link to the file
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private function getFileIdByLink(string $link) {
|
||||
$path = parse_url($link, PHP_URL_PATH);
|
||||
$encodedPath = array_map("urlencode", explode("/", $path));
|
||||
$link = str_replace($path, implode("/", $encodedPath), $link);
|
||||
if (filter_var($link, FILTER_VALIDATE_URL) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!empty($this->config->getStorageUrl())) {
|
||||
$storageUrl = $this->config->getStorageUrl();
|
||||
} else {
|
||||
$storageUrl = $this->urlGenerator->getAbsoluteURL("/");
|
||||
}
|
||||
|
||||
if (parse_url($link, PHP_URL_HOST) !== parse_url($storageUrl, PHP_URL_HOST)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (preg_match('/\/onlyoffice\/(\d+)/', $link, $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print error page
|
||||
*
|
||||
|
@ -685,6 +685,7 @@
|
||||
};
|
||||
|
||||
OCA.Onlyoffice.onRequestReferenceData = function (event) {
|
||||
const link = event.data.link
|
||||
const referenceData = event.data.referenceData;
|
||||
const path = event.data.path;
|
||||
|
||||
@ -693,6 +694,7 @@
|
||||
{
|
||||
referenceData,
|
||||
path,
|
||||
link,
|
||||
},
|
||||
function onSuccess(response) {
|
||||
if (response.error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user