diff --git a/README.md b/README.md
index d9702acb..70eab09d 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,4 @@
-### the Files Lock app
-
+# Temporary files lock

@@ -25,3 +24,101 @@ Administrators can also lock files using the `./occ` command:

+## API
+
+### Capability
+
+If locking is available the app will expose itself through the capabilties endpoint under the files key:
+```
+curl http://admin:admin@nextcloud.local/ocs/v1.php/cloud/capabilities\?format\=json -H 'OCS-APIRequest: true' \
+ | jq .ocs.data.capabilities.files
+{
+ ...
+ "locking": "1.0",
+ ...
+}
+```
+
+### Fetching lock details
+
+WebDAV returns the following additional properties if requests through a `PROPFIND`:
+
+- `{http://nextcloud.org/ns}lock`: `true` if the file is locked, otherwise `false`
+- `{http://nextcloud.org/ns}lock-owner`: User id of the lock owner
+- `{http://nextcloud.org/ns}lock-owner-displayname`: Display name of the lock owner
+- `{http://nextcloud.org/ns}lock-time`: Timestamp of the log creation time
+
+### Locking a file
+
+`PUT /apps/files_lock/lock/{fileId}`
+
+```bash
+curl -X PUT 'http://admin:admin@nextcloud.local/ocs/v2.php/apps/files_lock/lock/123' -H 'OCS-APIREQUEST: true'`
+```
+
+#### Success
+```
+
+
+
+ ok
+ 200
+ OK
+
+
+```
+
+#### Failure
+```
+
+
+
+ failure
+ 500
+
+
+
+ -1
+ OCA\FilesLock\Exceptions\AlreadyLockedException
+ File is already locked by admin
+
+
+```
+
+
+### Unlocking a file
+
+`DELETE /apps/files_lock/lock/{fileId}`
+
+```bash
+curl -X DELETE 'http://admin:admin@nextcloud.local/ocs/v2.php/apps/files_lock/lock/123' -H 'OCS-APIREQUEST: true'
+```
+
+#### Success
+```
+
+
+
+ ok
+ 200
+ OK
+
+
+```
+
+#### Failure
+```
+
+
+
+ failure
+ 500
+
+
+
+ -1
+ OCA\FilesLock\Exceptions\LockNotFoundException
+
+
+
+```
diff --git a/appinfo/info.xml b/appinfo/info.xml
index a2b8c119..33221228 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -37,7 +37,6 @@ Allow your users to temporary lock their files to avoid conflicts while working
-
+
-
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 351bfa8b..1770ab1b 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -28,7 +28,7 @@
return [
- 'routes' => [
+ 'ocs' => [
['name' => 'Lock#locking', 'url' => '/lock/{fileId}', 'verb' => 'PUT'],
['name' => 'Lock#unlocking', 'url' => '/lock/{fileId}', 'verb' => 'DELETE'],
]
diff --git a/js/files.js b/js/files.js
index 29049e6f..947993ff 100644
--- a/js/files.js
+++ b/js/files.js
@@ -116,7 +116,7 @@
if (locked !== undefined && locked) {
$.ajax({
method: 'DELETE',
- url: OC.generateUrl('/apps/files_lock/lock/' + fileId)
+ url: OC.linkToOCS('/apps/files_lock/lock', 2) + fileId
}).done(function(res) {
model.set('locked', false)
}).fail(function(res) {
@@ -125,7 +125,7 @@
} else {
$.ajax({
method: 'PUT',
- url: OC.generateUrl('/apps/files_lock/lock/' + fileId)
+ url: OC.linkToOCS('/apps/files_lock/lock', 2) + fileId
}).done(function(res) {
model.set('locked', true)
model.set('lockOwner', OC.getCurrentUser().uid)
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 7fac78f0..7feadf6e 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -35,6 +35,7 @@
use OCA\DAV\Connector\Sabre\CachingTree;
use OCA\DAV\Connector\Sabre\ObjectTree;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
+use OCA\FilesLock\Capability;
use OCA\FilesLock\Listeners\LoadAdditionalScripts;
use OCA\FilesLock\Plugins\FilesLockPlugin;
use OCA\FilesLock\Service\FileService;
@@ -91,6 +92,7 @@ public function __construct(array $params = array()) {
* @param IRegistrationContext $context
*/
public function register(IRegistrationContext $context): void {
+ $context->registerCapability(Capability::class);
$context->registerEventListener(
LoadAdditionalScriptsEvent::class,
LoadAdditionalScripts::class
diff --git a/lib/Capability.php b/lib/Capability.php
new file mode 100644
index 00000000..ccae5296
--- /dev/null
+++ b/lib/Capability.php
@@ -0,0 +1,17 @@
+ [
+ 'locking' => '1.0',
+ ]
+ ];
+ }
+
+}
diff --git a/lib/Controller/LockController.php b/lib/Controller/LockController.php
index ed869a07..6f039dea 100644
--- a/lib/Controller/LockController.php
+++ b/lib/Controller/LockController.php
@@ -35,9 +35,9 @@
use OCA\FilesLock\Service\FileService;
use OCA\FilesLock\Service\LockService;
use OCA\FilesLock\Tools\Traits\TLogger;
-use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\OCSController;
use OCP\IRequest;
use OCP\IUserSession;
@@ -47,7 +47,7 @@
*
* @package OCA\FilesLock\Controller
*/
-class LockController extends Controller {
+class LockController extends OCSController {
use TLogger;