Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/Db/Wopi.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
class Wopi extends \OCA\Richdocuments\Db {
// Tokens expire after this many seconds (not defined by WOPI specs).
const TOKEN_LIFETIME_SECONDS = 36000;
// If the expiry is closer than this time, it will be refreshed.
const TOKEN_REFRESH_THRESHOLD_SECONDS = 3600;

const ATTR_CAN_VIEW = 0;
const ATTR_CAN_UPDATE = 1;
Expand Down Expand Up @@ -93,11 +95,28 @@ public function getWopiForToken($token) {
return false;
}

if ($row['expiry'] - self::TOKEN_REFRESH_THRESHOLD_SECONDS <= \time()) {
$this->refreshTokenExpiry($token);
}

return [
'owner' => $row['owner_uid'],
'editor' => $row['editor_uid'],
'attributes' => $row['attributes'],
'server_host' => $row['server_host']
];
}

/**
* Refresh token life time
*
* @param string $token
* @return boolean
*/
protected function refreshTokenExpiry($token) {
$count = \OC::$server->getDatabaseConnection()->executeUpdate('UPDATE `*PREFIX*richdocuments_wopi` SET `expiry` = ? WHERE `token` = ?',
[\time() + self::TOKEN_LIFETIME_SECONDS, $token]
);
return $count > 0;
}
}