Support Direct download API
This commit is contained in:
parent
3dfea64ad9
commit
076abc46ba
15
README.md
15
README.md
|
@ -13,9 +13,8 @@ This server features:
|
||||||
* Multiple user accounts
|
* Multiple user accounts
|
||||||
* Share files for users using WebDAV: delete, create, update, mkdir, get, list
|
* Share files for users using WebDAV: delete, create, update, mkdir, get, list
|
||||||
* Compatible with WebDAV clients
|
* Compatible with WebDAV clients
|
||||||
* Supports NextCloud Android app
|
* Support for HTTP ranges (partial download)
|
||||||
* Supports NextCloud desktop app
|
|
||||||
* Also [NextCloud CLI client](https://docs.nextcloud.com/desktop/3.5/advancedusage.html)
|
|
||||||
* User-friendly directory listings for file browsing with a web browser:
|
* User-friendly directory listings for file browsing with a web browser:
|
||||||
* Upload directly from browser
|
* Upload directly from browser
|
||||||
* Rename
|
* Rename
|
||||||
|
@ -25,12 +24,20 @@ This server features:
|
||||||
* Preview of images, text, MarkDown and PDF
|
* Preview of images, text, MarkDown and PDF
|
||||||
* User-management through web UI
|
* User-management through web UI
|
||||||
|
|
||||||
|
## NextCloud compatibility
|
||||||
|
|
||||||
|
* Android app
|
||||||
|
* Desktop app (tested on Debian)
|
||||||
|
* [NextCloud CLI client](https://docs.nextcloud.com/desktop/3.5/advancedusage.html)
|
||||||
|
* Support for [Direct download API](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-api-overview.html#direct-download)
|
||||||
|
|
||||||
## Future development
|
## Future development
|
||||||
|
|
||||||
This might get supported in future (maybe):
|
This might get supported in future (maybe):
|
||||||
|
|
||||||
* [Chunk upload](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/chunking.html)
|
* [Chunk upload](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/chunking.html)
|
||||||
* Support for [NextCloud Trashbin](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/trashbin.html)
|
* [NextCloud Trashbin](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/trashbin.html)
|
||||||
|
* [NextCloud sharing](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-share-api.html) (maybe?)
|
||||||
* [Extended MKCOL](https://www.rfc-editor.org/rfc/rfc5689) if CalDAV support is implemented
|
* [Extended MKCOL](https://www.rfc-editor.org/rfc/rfc5689) if CalDAV support is implemented
|
||||||
* CalDAV/CardDAV support: maybe, why not, we'll see, in the mean time see [Sabre/DAV](https://sabre.io/dav/) for that.
|
* CalDAV/CardDAV support: maybe, why not, we'll see, in the mean time see [Sabre/DAV](https://sabre.io/dav/) for that.
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,6 @@ $name = $_SERVER['SERVER_NAME'];
|
||||||
$port = !in_array($_SERVER['SERVER_PORT'], [80, 443]) ? ':' . $_SERVER['SERVER_PORT'] : '';
|
$port = !in_array($_SERVER['SERVER_PORT'], [80, 443]) ? ':' . $_SERVER['SERVER_PORT'] : '';
|
||||||
$root = '/';
|
$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:8081/';
|
#const WWW_URL = 'http://192.168.43.171:8081/';
|
|
@ -74,6 +74,17 @@ class Server extends WebDAV_NextCloud
|
||||||
return $this->users->current()->login ?? null;
|
return $this->users->current()->login ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function nc_set_user(string $login): bool
|
||||||
|
{
|
||||||
|
$ok = $this->users->setCurrent($login);
|
||||||
|
|
||||||
|
if ($ok) {
|
||||||
|
$this->user = $this->users->current();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ok;
|
||||||
|
}
|
||||||
|
|
||||||
public function nc_get_quota(): array
|
public function nc_get_quota(): array
|
||||||
{
|
{
|
||||||
return (array) $this->users->quota($this->users->current());
|
return (array) $this->users->quota($this->users->current());
|
||||||
|
@ -105,6 +116,17 @@ class Server extends WebDAV_NextCloud
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function nc_direct_get_secret(string $uri, string $login): string
|
||||||
|
{
|
||||||
|
$user = $this->users->get($login);
|
||||||
|
|
||||||
|
if (!$user) {
|
||||||
|
throw new WebDAV_Exception('No user with that name', 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash('sha256', $uri . $user->login . $user->password);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getLock(string $uri, ?string $token = null): ?string
|
protected function getLock(string $uri, ?string $token = null): ?string
|
||||||
{
|
{
|
||||||
// It is important to check also for a lock on parent directory as we support depth=1
|
// It is important to check also for a lock on parent directory as we support depth=1
|
||||||
|
@ -237,7 +259,7 @@ class Server extends WebDAV_NextCloud
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $properties) {
|
if (null === $properties) {
|
||||||
$properties = self::BASIC_PROPERTIES + ['DAV::getetag'];
|
$properties = array_merge(self::BASIC_PROPERTIES, ['DAV::getetag', self::PROP_OC_ID]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$out = [];
|
$out = [];
|
||||||
|
|
|
@ -6,6 +6,8 @@ use stdClass;
|
||||||
|
|
||||||
class Users
|
class Users
|
||||||
{
|
{
|
||||||
|
protected ?stdClass $current = null;
|
||||||
|
|
||||||
static public function generatePassword(): string
|
static public function generatePassword(): string
|
||||||
{
|
{
|
||||||
$password = base64_encode(random_bytes(16));
|
$password = base64_encode(random_bytes(16));
|
||||||
|
@ -73,11 +75,29 @@ class Users
|
||||||
|
|
||||||
public function current(): ?stdClass
|
public function current(): ?stdClass
|
||||||
{
|
{
|
||||||
|
if ($this->current) {
|
||||||
|
return $this->current;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($_COOKIE[session_name()]) && !isset($_SESSION)) {
|
if (isset($_COOKIE[session_name()]) && !isset($_SESSION)) {
|
||||||
session_start();
|
session_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->makeUserObjectGreatAgain($_SESSION['user'] ?? null);
|
$this->current = $this->makeUserObjectGreatAgain($_SESSION['user'] ?? null);
|
||||||
|
|
||||||
|
return $this->current;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCurrent(string $login): bool
|
||||||
|
{
|
||||||
|
$user = $this->get($login);
|
||||||
|
|
||||||
|
if (!$user) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->current = $user;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function login(?string $login, ?string $password, ?string $app_password = null): ?stdClass
|
public function login(?string $login, ?string $password, ?string $app_password = null): ?stdClass
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
Options -Indexes -Multiviews
|
Options -Indexes -Multiviews
|
||||||
DirectoryIndex disabled
|
DirectoryIndex disabled
|
||||||
|
|
||||||
FallbackResource /_router.php
|
RewriteEngine On
|
||||||
|
RewriteBase /
|
||||||
# see https://stackoverflow.com/a/66136226
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
ErrorDocument 404 /_router.php
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
RewriteRule ^.*$ /_router.php [L]
|
||||||
|
|
|
@ -23,6 +23,10 @@ if (PHP_SAPI == 'cli-server') {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($_SERVER['REDIRECT_REQUEST_METHOD'])) {
|
||||||
|
$_SERVER['REQUEST_METHOD'] = $_SERVER['REDIRECT_REQUEST_METHOD'];
|
||||||
|
}
|
||||||
|
|
||||||
$s = new Server;
|
$s = new Server;
|
||||||
|
|
||||||
if (!$s->route($uri)) {
|
if (!$s->route($uri)) {
|
||||||
|
|
Loading…
Reference in a new issue