Skip to content

Commit

Permalink
replace @ with ~ in urls
Browse files Browse the repository at this point in the history
  • Loading branch information
ylebre committed Oct 4, 2024
1 parent 5e71802 commit 7452d01
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
48 changes: 24 additions & 24 deletions solid/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
*/
return [
'routes' => [
['name' => 'page#profile', 'url' => '/@{userId}/', 'verb' => 'GET'],
['name' => 'page#profile', 'url' => '/~{userId}/', 'verb' => 'GET'],
['name' => 'page#approval', 'url' => '/sharing/{clientId}', 'verb' => 'GET'],
['name' => 'page#handleRevoke', 'url' => '/revoke/{clientId}', 'verb' => 'GET'],
['name' => 'page#handleApproval', 'url' => '/sharing/{clientId}', 'verb' => 'POST'],
['name' => 'page#dataJson', 'url' => '/@{userId}/data.json', 'verb' => 'GET' ],
['name' => 'page#dataJson', 'url' => '/~{userId}/data.json', 'verb' => 'GET' ],

['name' => 'server#cors', 'url' => '/{path}', 'verb' => 'OPTIONS', 'requirements' => array('path' => '.+') ],
['name' => 'server#authorize', 'url' => '/authorize', 'verb' => 'GET'],
Expand All @@ -25,31 +25,31 @@
['name' => 'server#register', 'url' => '/register', 'verb' => 'POST'],
['name' => 'server#registeredClient', 'url' => '/register/{clientId}', 'verb' => 'GET'],

['name' => 'profile#handleGet', 'url' => '/@{userId}/profile{path}', 'verb' => 'GET', 'requirements' => array('path' => '.+')],
['name' => 'profile#handlePut', 'url' => '/@{userId}/profile{path}', 'verb' => 'PUT', 'requirements' => array('path' => '.+')],
['name' => 'profile#handlePatch', 'url' => '/@{userId}/profile{path}', 'verb' => 'PATCH', 'requirements' => array('path' => '.+')],
['name' => 'profile#handleHead', 'url' => '/@{userId}/profile{path}', 'verb' => 'HEAD', 'requirements' => array('path' => '.+')],
['name' => 'profile#handleGet', 'url' => '/~{userId}/profile{path}', 'verb' => 'GET', 'requirements' => array('path' => '.+')],
['name' => 'profile#handlePut', 'url' => '/~{userId}/profile{path}', 'verb' => 'PUT', 'requirements' => array('path' => '.+')],
['name' => 'profile#handlePatch', 'url' => '/~{userId}/profile{path}', 'verb' => 'PATCH', 'requirements' => array('path' => '.+')],
['name' => 'profile#handleHead', 'url' => '/~{userId}/profile{path}', 'verb' => 'HEAD', 'requirements' => array('path' => '.+')],

['name' => 'storage#handleGet', 'url' => '/@{userId}/storage{path}', 'verb' => 'GET', 'requirements' => array('path' => '.+')],
['name' => 'storage#handlePost', 'url' => '/@{userId}/storage{path}', 'verb' => 'POST', 'requirements' => array('path' => '.+')],
['name' => 'storage#handlePut', 'url' => '/@{userId}/storage{path}', 'verb' => 'PUT', 'requirements' => array('path' => '.+')],
['name' => 'storage#handleDelete', 'url' => '/@{userId}/storage{path}', 'verb' => 'DELETE', 'requirements' => array('path' => '.+')],
['name' => 'storage#handlePatch', 'url' => '/@{userId}/storage{path}', 'verb' => 'PATCH', 'requirements' => array('path' => '.+')],
['name' => 'storage#handleHead', 'url' => '/@{userId}/storage{path}', 'verb' => 'HEAD', 'requirements' => array('path' => '.+')],
['name' => 'storage#handleGet', 'url' => '/~{userId}/storage{path}', 'verb' => 'GET', 'requirements' => array('path' => '.+')],
['name' => 'storage#handlePost', 'url' => '/~{userId}/storage{path}', 'verb' => 'POST', 'requirements' => array('path' => '.+')],
['name' => 'storage#handlePut', 'url' => '/~{userId}/storage{path}', 'verb' => 'PUT', 'requirements' => array('path' => '.+')],
['name' => 'storage#handleDelete', 'url' => '/~{userId}/storage{path}', 'verb' => 'DELETE', 'requirements' => array('path' => '.+')],
['name' => 'storage#handlePatch', 'url' => '/~{userId}/storage{path}', 'verb' => 'PATCH', 'requirements' => array('path' => '.+')],
['name' => 'storage#handleHead', 'url' => '/~{userId}/storage{path}', 'verb' => 'HEAD', 'requirements' => array('path' => '.+')],

['name' => 'calendar#handleGet', 'url' => '/@{userId}/calendar{path}', 'verb' => 'GET', 'requirements' => array('path' => '.+')],
['name' => 'calendar#handlePost', 'url' => '/@{userId}/calendar{path}', 'verb' => 'POST', 'requirements' => array('path' => '.+')],
['name' => 'calendar#handlePut', 'url' => '/@{userId}/calendar{path}', 'verb' => 'PUT', 'requirements' => array('path' => '.+')],
['name' => 'calendar#handleDelete', 'url' => '/@{userId}/calendar{path}', 'verb' => 'DELETE', 'requirements' => array('path' => '.+')],
['name' => 'calendar#handlePatch', 'url' => '/@{userId}/calendar{path}', 'verb' => 'PATCH', 'requirements' => array('path' => '.+')],
['name' => 'calendar#handleHead', 'url' => '/@{userId}/calendar{path}', 'verb' => 'HEAD', 'requirements' => array('path' => '.+')],
['name' => 'calendar#handleGet', 'url' => '/~{userId}/calendar{path}', 'verb' => 'GET', 'requirements' => array('path' => '.+')],
['name' => 'calendar#handlePost', 'url' => '/~{userId}/calendar{path}', 'verb' => 'POST', 'requirements' => array('path' => '.+')],
['name' => 'calendar#handlePut', 'url' => '/~{userId}/calendar{path}', 'verb' => 'PUT', 'requirements' => array('path' => '.+')],
['name' => 'calendar#handleDelete', 'url' => '/~{userId}/calendar{path}', 'verb' => 'DELETE', 'requirements' => array('path' => '.+')],
['name' => 'calendar#handlePatch', 'url' => '/~{userId}/calendar{path}', 'verb' => 'PATCH', 'requirements' => array('path' => '.+')],
['name' => 'calendar#handleHead', 'url' => '/~{userId}/calendar{path}', 'verb' => 'HEAD', 'requirements' => array('path' => '.+')],

['name' => 'contacts#handleGet', 'url' => '/@{userId}/contacts{path}', 'verb' => 'GET', 'requirements' => array('path' => '.+')],
['name' => 'contacts#handlePost', 'url' => '/@{userId}/contacts{path}', 'verb' => 'POST', 'requirements' => array('path' => '.+')],
['name' => 'contacts#handlePut', 'url' => '/@{userId}/contacts{path}', 'verb' => 'PUT', 'requirements' => array('path' => '.+')],
['name' => 'contacts#handleDelete', 'url' => '/@{userId}/contacts{path}', 'verb' => 'DELETE', 'requirements' => array('path' => '.+')],
['name' => 'contacts#handlePatch', 'url' => '/@{userId}/contacts{path}', 'verb' => 'PATCH', 'requirements' => array('path' => '.+')],
['name' => 'contacts#handleHead', 'url' => '/@{userId}/contacts{path}', 'verb' => 'HEAD', 'requirements' => array('path' => '.+')],
['name' => 'contacts#handleGet', 'url' => '/~{userId}/contacts{path}', 'verb' => 'GET', 'requirements' => array('path' => '.+')],
['name' => 'contacts#handlePost', 'url' => '/~{userId}/contacts{path}', 'verb' => 'POST', 'requirements' => array('path' => '.+')],
['name' => 'contacts#handlePut', 'url' => '/~{userId}/contacts{path}', 'verb' => 'PUT', 'requirements' => array('path' => '.+')],
['name' => 'contacts#handleDelete', 'url' => '/~{userId}/contacts{path}', 'verb' => 'DELETE', 'requirements' => array('path' => '.+')],
['name' => 'contacts#handlePatch', 'url' => '/~{userId}/contacts{path}', 'verb' => 'PATCH', 'requirements' => array('path' => '.+')],
['name' => 'contacts#handleHead', 'url' => '/~{userId}/contacts{path}', 'verb' => 'HEAD', 'requirements' => array('path' => '.+')],

['name' => 'solidWebhook#listWebhooks', 'url' => '/webhook/list', 'verb' => 'GET'],
['name' => 'solidWebhook#register', 'url' => '/webhook/register', 'verb' => 'POST'],
Expand Down
4 changes: 2 additions & 2 deletions solid/lib/Controller/CalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public function handlePut() { // $userId, $path) {
// throw an error about accessing put twice, so we will find out the userId and path from $_SERVER instead;

// because we got here, the request uri should look like:
// /index.php/apps/solid/@{userId}/storage{path}
$pathInfo = explode("@", $_SERVER['REQUEST_URI']);
// /index.php/apps/solid/~{userId}/storage{path}
$pathInfo = explode("~", $_SERVER['REQUEST_URI']);
$pathInfo = explode("/", $pathInfo[1], 2);
$userId = $pathInfo[0];
$path = $pathInfo[1];
Expand Down
4 changes: 2 additions & 2 deletions solid/lib/Controller/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ public function handlePut() { // $userId, $path) {
// throw an error about accessing put twice, so we will find out the userId and path from $_SERVER instead;

// because we got here, the request uri should look like:
// /index.php/apps/solid/@{userId}/storage{path}
$pathInfo = explode("@", $_SERVER['REQUEST_URI']);
// /index.php/apps/solid/~{userId}/storage{path}
$pathInfo = explode("~", $_SERVER['REQUEST_URI']);
$pathInfo = explode("/", $pathInfo[1], 2);
$userId = $pathInfo[0];
$path = $pathInfo[1];
Expand Down
4 changes: 2 additions & 2 deletions solid/lib/Controller/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ public function handlePut() { // $userId, $path) {
// throw an error about accessing put twice, so we will find out the userId and path from $_SERVER instead;

// because we got here, the request uri should look like:
// /index.php/apps/solid/@{userId}/storage{path}
$pathInfo = explode("@", $_SERVER['REQUEST_URI']);
// /index.php/apps/solid/~{userId}/storage{path}
$pathInfo = explode("~", $_SERVER['REQUEST_URI']);
$pathInfo = explode("/", $pathInfo[1], 2);
$userId = $pathInfo[0];
$path = $pathInfo[1];
Expand Down
12 changes: 6 additions & 6 deletions solid/lib/Controller/SolidWebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ private function initializeStorage($userId) {
}

private function parseTopic($topic) {
// topic = https://nextcloud.server/solid/@alice/storage/foo/bar
// topic = https://nextcloud.server/solid/~alice/storage/foo/bar
$appBaseUrl = $this->getAppBaseUrl(); // https://nextcloud.server/solid/
$internalUrl = str_replace($appBaseUrl, '', $topic); // @alice/storage/foo/bar
$internalUrl = str_replace($appBaseUrl, '', $topic); // ~alice/storage/foo/bar
$pathicles = explode("/", $internalUrl);
$userId = $pathicles[0]; // @alice
$userId = preg_replace("/^@/", "", $userId); // alice
$storageUrl = $this->getStorageUrl($userId); // https://nextcloud.server/solid/@alice/storage/
$userId = $pathicles[0]; // ~alice
$userId = preg_replace("/^~/", "", $userId); // alice
$storageUrl = $this->getStorageUrl($userId); // https://nextcloud.server/solid/~alice/storage/
$storagePath = str_replace($storageUrl, '/', $topic); // /foo/bar
return array(
"userId" => $userId,
Expand All @@ -194,7 +194,7 @@ private function createGetRequest($topic) {
}

private function checkReadAccess($topic) {
// split out $topic into $userId and $path https://nextcloud.server/solid/@alice/storage/foo/bar
// split out $topic into $userId and $path https://nextcloud.server/solid/~alice/storage/foo/bar
// - userId in this case is the pod owner (not the one doing the request). (alice)
// - path is the path within the storage pod (/foo/bar)
$target = $this->parseTopic($topic);
Expand Down
4 changes: 2 additions & 2 deletions solid/lib/Controller/StorageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ public function handlePut() { // $userId, $path) {
// throw an error about accessing put twice, so we will find out the userId and path from $_SERVER instead;

// because we got here, the request uri should look like:
// /index.php/apps/solid/@{userId}/storage{path}
$pathInfo = explode("@", $_SERVER['REQUEST_URI']);
// /index.php/apps/solid/~{userId}/storage{path}
$pathInfo = explode("~", $_SERVER['REQUEST_URI']);
$pathInfo = explode("/", $pathInfo[1], 2);
$userId = $pathInfo[0];
$path = $pathInfo[1];
Expand Down

0 comments on commit 7452d01

Please sign in to comment.