From 3dfea64ad96b47f9d2ed75d0f7d9813d8834fac3 Mon Sep 17 00:00:00 2001 From: bohwaz Date: Sat, 3 Sep 2022 06:25:02 +0200 Subject: [PATCH] Make it work with Mobile client --- NEXTCLOUD.md | 4 ++++ config.dist.php | 4 ++-- lib/KaraDAV/Server.php | 4 ++-- lib/KaraDAV/Users.php | 2 +- www/_router.php | 7 ++++++- www/files.css | 9 +++++++++ www/files.js | 2 +- www/login.php | 2 +- 8 files changed, 26 insertions(+), 8 deletions(-) diff --git a/NEXTCLOUD.md b/NEXTCLOUD.md index 766e504..75f2af2 100644 --- a/NEXTCLOUD.md +++ b/NEXTCLOUD.md @@ -27,6 +27,10 @@ The second API is different but is explained in the documentation, it involves e Those endpoints are requested by the clients and one or the other client will fail if they don't return something that looks valid. +## Mobile app + +* `getcontentlength` must be present and be a number, even for collections + ## Desktop client ### Requests performed diff --git a/config.dist.php b/config.dist.php index 817b544..1054c07 100644 --- a/config.dist.php +++ b/config.dist.php @@ -25,6 +25,6 @@ $name = $_SERVER['SERVER_NAME']; $port = !in_array($_SERVER['SERVER_PORT'], [80, 443]) ? ':' . $_SERVER['SERVER_PORT'] : ''; $root = '/'; -define('KaraDAV\WWW_URL', sprintf('http%s://%s%s%s', $https, $name, $port, $root)); +#define('KaraDAV\WWW_URL', sprintf('http%s://%s%s%s', $https, $name, $port, $root)); -//const WWW_URL = 'http://192.168.43.171:8080/'; \ No newline at end of file +const WWW_URL = 'http://192.168.43.171:8081/'; \ No newline at end of file diff --git a/lib/KaraDAV/Server.php b/lib/KaraDAV/Server.php index 038540f..77fe9a5 100644 --- a/lib/KaraDAV/Server.php +++ b/lib/KaraDAV/Server.php @@ -169,7 +169,7 @@ class Server extends WebDAV_NextCloud switch ($name) { case 'DAV::getcontentlength': - return is_dir($target) ? '' : filesize($target); + return is_dir($target) ? 0 : filesize($target); case 'DAV::getcontenttype': return mime_content_type($target); case 'DAV::resourcetype': @@ -206,7 +206,7 @@ class Server extends WebDAV_NextCloud return new \DateTime('@' . filectime($target)); // NextCloud stuff case self::PROP_OC_ID: - return md5($target); + return $this->nc_direct_id($uri); case self::PROP_OC_PERMISSIONS: return implode('', [self::PERM_READ, self::PERM_WRITE, self::PERM_CREATE, self::PERM_DELETE, self::PERM_RENAME_MOVE]); case self::PROP_OC_SIZE: diff --git a/lib/KaraDAV/Users.php b/lib/KaraDAV/Users.php index 4202ed7..461db55 100644 --- a/lib/KaraDAV/Users.php +++ b/lib/KaraDAV/Users.php @@ -152,7 +152,7 @@ class Users $session = $this->appSessionCreate(); $current = $this->current(); - return sprintf(Server::NC_AUTH_REDIRECT_URL, WWW_URL, $session->token, $session->password); + return sprintf(Server::NC_AUTH_REDIRECT_URL, WWW_URL, $current->login, $session->token . ':' . $session->password); } public function appSessionValidateToken(string $token): ?stdClass diff --git a/www/_router.php b/www/_router.php index 6d7a419..0e2fa18 100644 --- a/www/_router.php +++ b/www/_router.php @@ -15,7 +15,12 @@ if (PHP_SAPI == 'cli-server') { return false; } - file_put_contents('php://stderr', $uri . "\n"); + $method = $_SERVER['REQUEST_METHOD'] ?? $_SERVER['REDIRECT_REQUEST_METHOD']; + file_put_contents('php://stderr', sprintf("%s %s\n", $method, $uri)); + + if ($method != 'GET' && $method != 'HEAD') { + file_put_contents('php://stderr', file_get_contents('php://input') . "\n"); + } } $s = new Server; diff --git a/www/files.css b/www/files.css index b5c7217..7d6e1c0 100644 --- a/www/files.css +++ b/www/files.css @@ -112,6 +112,7 @@ dialog.preview { padding: 0; border-radius: 0; background: #ddd; + overflow: hidden; } iframe, .md_preview { @@ -127,7 +128,15 @@ iframe, .md_preview { } .preview form { + height: calc(100% - 2em); + display: flex; + align-items: center; + justify-content: center; +} + +.preview form div { height: 100%; + margin: 0; display: flex; align-items: center; justify-content: center; diff --git a/www/files.js b/www/files.js index d5c53c8..388d39e 100644 --- a/www/files.js +++ b/www/files.js @@ -12,7 +12,7 @@ function html(unsafe) .replace(/'/g, "'"); } -const url = location.href; +const url = location.pathname; const PREVIEW_TYPES = /^image\/(png|webp|svg|jpeg|jpg|gif|png)|^application\/pdf|^text\/|^audio\/|^video\//; diff --git a/www/login.php b/www/login.php index 2ffed44..022a84d 100644 --- a/www/login.php +++ b/www/login.php @@ -64,7 +64,7 @@ echo ' Login
-
+