|
1 | 1 | <?php |
| 2 | + |
| 3 | +use OC\AllConfig; |
| 4 | +use OC\AppConfig; |
| 5 | +use OCA\Solid\AppInfo\Application; |
| 6 | +use OCP\IConfig; |
| 7 | +use OCP\IRequest; |
| 8 | + |
2 | 9 | /** |
3 | 10 | * Create your routes in here. The name is the lowercase name of the controller |
4 | 11 | * without the controller part, the stuff after the hash is the method. |
|
7 | 14 | * The controller class has to be registered in the application.php file since |
8 | 15 | * it's instantiated in there |
9 | 16 | */ |
| 17 | + |
| 18 | + |
| 19 | +$routes = [ |
| 20 | + ['name' => 'page#approval', 'url' => '/sharing/{clientId}', 'verb' => 'GET'], |
| 21 | + ['name' => 'page#handleRevoke', 'url' => '/revoke/{clientId}', 'verb' => 'DELETE'], |
| 22 | + ['name' => 'page#handleRevoke', 'url' => '/revoke/{clientId}', 'verb' => 'POST'], |
| 23 | + |
| 24 | + ['name' => 'page#handleApproval', 'url' => '/sharing/{clientId}', 'verb' => 'POST'], |
| 25 | + ['name' => 'page#customscheme', 'url' => '/customscheme', 'verb' => 'GET'], |
| 26 | + |
| 27 | + ['name' => 'server#cors', 'url' => '/{path}', 'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']], |
| 28 | + ['name' => 'server#authorize', 'url' => '/authorize', 'verb' => 'GET'], |
| 29 | + ['name' => 'server#jwks', 'url' => '/jwks', 'verb' => 'GET'], |
| 30 | + ['name' => 'server#session', 'url' => '/session', 'verb' => 'GET'], |
| 31 | + ['name' => 'server#logout', 'url' => '/logout', 'verb' => 'GET'], |
| 32 | + ['name' => 'server#token', 'url' => '/token', 'verb' => 'POST'], |
| 33 | + ['name' => 'server#userinfo', 'url' => '/userinfo', 'verb' => 'GET'], |
| 34 | + ['name' => 'server#register', 'url' => '/register', 'verb' => 'POST'], |
| 35 | + ['name' => 'server#registeredClient', 'url' => '/register/{clientId}', 'verb' => 'GET'], |
| 36 | + |
| 37 | + ['name' => 'solidWebhook#listWebhooks', 'url' => '/webhook/list', 'verb' => 'GET'], |
| 38 | + ['name' => 'solidWebhook#register', 'url' => '/webhook/register', 'verb' => 'POST'], |
| 39 | + ['name' => 'solidWebhook#unregister', 'url' => '/webhook/unregister', 'verb' => 'POST'], |
| 40 | + |
| 41 | + ['name' => 'solidWebsocket#register', 'url' => '/websocket/register', 'verb' => 'POST'], |
| 42 | + |
| 43 | + ['name' => 'app#appLauncher', 'url' => '/', 'verb' => 'GET'], |
| 44 | +]; |
| 45 | + |
| 46 | +$userIdRoutes = [ |
| 47 | + ['name' => 'page#profile', 'url' => '/@{userId}/', 'verb' => 'GET'], |
| 48 | + |
| 49 | + ['name' => 'profile#handleGet', 'url' => '/@{userId}/profile{path}', 'verb' => 'GET', 'requirements' => ['path' => '.+'], ], |
| 50 | + ['name' => 'profile#handlePut', 'url' => '/@{userId}/profile{path}', 'verb' => 'PUT', 'requirements' => ['path' => '.+'], ], |
| 51 | + ['name' => 'profile#handlePatch', 'url' => '/@{userId}/profile{path}', 'verb' => 'PATCH', 'requirements' => ['path' => '.+'], ], |
| 52 | + ['name' => 'profile#handleHead', 'url' => '/@{userId}/profile{path}', 'verb' => 'HEAD', 'requirements' => ['path' => '.+'], ], |
| 53 | + |
| 54 | + ['name' => 'storage#handleGet', 'url' => '/@{userId}/storage{path}', 'verb' => 'GET', 'requirements' => ['path' => '.+'], ], |
| 55 | + ['name' => 'storage#handlePost', 'url' => '/@{userId}/storage{path}', 'verb' => 'POST', 'requirements' => ['path' => '.+'], ], |
| 56 | + ['name' => 'storage#handlePut', 'url' => '/@{userId}/storage{path}', 'verb' => 'PUT', 'requirements' => ['path' => '.+'], ], |
| 57 | + ['name' => 'storage#handleDelete', 'url' => '/@{userId}/storage{path}', 'verb' => 'DELETE', 'requirements' => ['path' => '.+'], ], |
| 58 | + ['name' => 'storage#handlePatch', 'url' => '/@{userId}/storage{path}', 'verb' => 'PATCH', 'requirements' => ['path' => '.+'], ], |
| 59 | + ['name' => 'storage#handleHead', 'url' => '/@{userId}/storage{path}', 'verb' => 'HEAD', 'requirements' => ['path' => '.+'], ], |
| 60 | + |
| 61 | + ['name' => 'calendar#handleGet', 'url' => '/@{userId}/calendar{path}', 'verb' => 'GET', 'requirements' => ['path' => '.+'], ], |
| 62 | + ['name' => 'calendar#handlePost', 'url' => '/@{userId}/calendar{path}', 'verb' => 'POST', 'requirements' => ['path' => '.+'], ], |
| 63 | + ['name' => 'calendar#handlePut', 'url' => '/@{userId}/calendar{path}', 'verb' => 'PUT', 'requirements' => ['path' => '.+'], ], |
| 64 | + ['name' => 'calendar#handleDelete', 'url' => '/@{userId}/calendar{path}', 'verb' => 'DELETE', 'requirements' => ['path' => '.+'], ], |
| 65 | + ['name' => 'calendar#handlePatch', 'url' => '/@{userId}/calendar{path}', 'verb' => 'PATCH', 'requirements' => ['path' => '.+'], ], |
| 66 | + ['name' => 'calendar#handleHead', 'url' => '/@{userId}/calendar{path}', 'verb' => 'HEAD', 'requirements' => ['path' => '.+'], ], |
| 67 | + |
| 68 | + ['name' => 'contacts#handleGet', 'url' => '/@{userId}/contacts{path}', 'verb' => 'GET', 'requirements' => ['path' => '.+'], ], |
| 69 | + ['name' => 'contacts#handlePost', 'url' => '/@{userId}/contacts{path}', 'verb' => 'POST', 'requirements' => ['path' => '.+'], ], |
| 70 | + ['name' => 'contacts#handlePut', 'url' => '/@{userId}/contacts{path}', 'verb' => 'PUT', 'requirements' => ['path' => '.+'], ], |
| 71 | + ['name' => 'contacts#handleDelete', 'url' => '/@{userId}/contacts{path}', 'verb' => 'DELETE', 'requirements' => ['path' => '.+'], ], |
| 72 | + ['name' => 'contacts#handlePatch', 'url' => '/@{userId}/contacts{path}', 'verb' => 'PATCH', 'requirements' => ['path' => '.+'], ], |
| 73 | + ['name' => 'contacts#handleHead', 'url' => '/@{userId}/contacts{path}', 'verb' => 'HEAD', 'requirements' => ['path' => '.+'], ], |
| 74 | +]; |
| 75 | + |
| 76 | +// @TODO: All routes NOT generated by the UrlGenerator ANYWHERE in the code need to be checked! |
| 77 | + |
| 78 | +if (Application::$userSubDomainsEnabled) { |
| 79 | + $userIdRoutes = array_map(function ($route) { |
| 80 | + if ($route['name'] === 'page#profile') { |
| 81 | + // The profile route should be `/me` instead of `/@{userId}/` |
| 82 | + $route['url'] = '/me'; |
| 83 | + } else { |
| 84 | + // When UserSubDomains are enabled, all routes that start with |
| 85 | + // `/@{userId}/` should just be `/`, as the userId is present |
| 86 | + // in the subdomain. |
| 87 | + $route['url'] = preg_replace('#^/@{userId}/#', '/', $route['url']); |
| 88 | + } |
| 89 | + |
| 90 | + // The required userId is set to the userId from the subdomain |
| 91 | + $host = OC::$server->get(IRequest::class)->getServerHost(); |
| 92 | + $userId = explode('.', $host)[0]; |
| 93 | + $route['defaults'] = ['userId' => $userId]; |
| 94 | + |
| 95 | + return $route; |
| 96 | + }, $userIdRoutes); |
| 97 | +} |
| 98 | + |
10 | 99 | return [ |
11 | | - 'routes' => [ |
12 | | - ['name' => 'page#profile', 'url' => '/@{userId}/', 'verb' => 'GET'], |
13 | | - ['name' => 'page#approval', 'url' => '/sharing/{clientId}', 'verb' => 'GET'], |
14 | | - ['name' => 'page#handleRevoke', 'url' => '/revoke/{clientId}', 'verb' => 'DELETE'], |
15 | | - ['name' => 'page#handleRevoke', 'url' => '/revoke/{clientId}', 'verb' => 'POST'], |
16 | | - |
17 | | - ['name' => 'page#handleApproval', 'url' => '/sharing/{clientId}', 'verb' => 'POST'], |
18 | | - ['name' => 'page#customscheme', 'url' => '/customscheme', 'verb' => 'GET'], |
19 | | - |
20 | | - ['name' => 'server#cors', 'url' => '/{path}', 'verb' => 'OPTIONS', 'requirements' => array('path' => '.+') ], |
21 | | - ['name' => 'server#authorize', 'url' => '/authorize', 'verb' => 'GET'], |
22 | | - ['name' => 'server#jwks', 'url' => '/jwks', 'verb' => 'GET'], |
23 | | - ['name' => 'server#session', 'url' => '/session', 'verb' => 'GET'], |
24 | | - ['name' => 'server#logout', 'url' => '/logout', 'verb' => 'GET'], |
25 | | - ['name' => 'server#token', 'url' => '/token', 'verb' => 'POST'], |
26 | | - ['name' => 'server#userinfo', 'url' => '/userinfo', 'verb' => 'GET'], |
27 | | - ['name' => 'server#register', 'url' => '/register', 'verb' => 'POST'], |
28 | | - ['name' => 'server#registeredClient', 'url' => '/register/{clientId}', 'verb' => 'GET'], |
29 | | - |
30 | | - ['name' => 'profile#handleGet', 'url' => '/@{userId}/profile{path}', 'verb' => 'GET', 'requirements' => array('path' => '.+')], |
31 | | - ['name' => 'profile#handlePut', 'url' => '/@{userId}/profile{path}', 'verb' => 'PUT', 'requirements' => array('path' => '.+')], |
32 | | - ['name' => 'profile#handlePatch', 'url' => '/@{userId}/profile{path}', 'verb' => 'PATCH', 'requirements' => array('path' => '.+')], |
33 | | - ['name' => 'profile#handleHead', 'url' => '/@{userId}/profile{path}', 'verb' => 'HEAD', 'requirements' => array('path' => '.+')], |
34 | | - |
35 | | - ['name' => 'storage#handleGet', 'url' => '/@{userId}/storage{path}', 'verb' => 'GET', 'requirements' => array('path' => '.+')], |
36 | | - ['name' => 'storage#handlePost', 'url' => '/@{userId}/storage{path}', 'verb' => 'POST', 'requirements' => array('path' => '.+')], |
37 | | - ['name' => 'storage#handlePut', 'url' => '/@{userId}/storage{path}', 'verb' => 'PUT', 'requirements' => array('path' => '.+')], |
38 | | - ['name' => 'storage#handleDelete', 'url' => '/@{userId}/storage{path}', 'verb' => 'DELETE', 'requirements' => array('path' => '.+')], |
39 | | - ['name' => 'storage#handlePatch', 'url' => '/@{userId}/storage{path}', 'verb' => 'PATCH', 'requirements' => array('path' => '.+')], |
40 | | - ['name' => 'storage#handleHead', 'url' => '/@{userId}/storage{path}', 'verb' => 'HEAD', 'requirements' => array('path' => '.+')], |
41 | | - |
42 | | - ['name' => 'calendar#handleGet', 'url' => '/@{userId}/calendar{path}', 'verb' => 'GET', 'requirements' => array('path' => '.+')], |
43 | | - ['name' => 'calendar#handlePost', 'url' => '/@{userId}/calendar{path}', 'verb' => 'POST', 'requirements' => array('path' => '.+')], |
44 | | - ['name' => 'calendar#handlePut', 'url' => '/@{userId}/calendar{path}', 'verb' => 'PUT', 'requirements' => array('path' => '.+')], |
45 | | - ['name' => 'calendar#handleDelete', 'url' => '/@{userId}/calendar{path}', 'verb' => 'DELETE', 'requirements' => array('path' => '.+')], |
46 | | - ['name' => 'calendar#handlePatch', 'url' => '/@{userId}/calendar{path}', 'verb' => 'PATCH', 'requirements' => array('path' => '.+')], |
47 | | - ['name' => 'calendar#handleHead', 'url' => '/@{userId}/calendar{path}', 'verb' => 'HEAD', 'requirements' => array('path' => '.+')], |
48 | | - |
49 | | - ['name' => 'contacts#handleGet', 'url' => '/@{userId}/contacts{path}', 'verb' => 'GET', 'requirements' => array('path' => '.+')], |
50 | | - ['name' => 'contacts#handlePost', 'url' => '/@{userId}/contacts{path}', 'verb' => 'POST', 'requirements' => array('path' => '.+')], |
51 | | - ['name' => 'contacts#handlePut', 'url' => '/@{userId}/contacts{path}', 'verb' => 'PUT', 'requirements' => array('path' => '.+')], |
52 | | - ['name' => 'contacts#handleDelete', 'url' => '/@{userId}/contacts{path}', 'verb' => 'DELETE', 'requirements' => array('path' => '.+')], |
53 | | - ['name' => 'contacts#handlePatch', 'url' => '/@{userId}/contacts{path}', 'verb' => 'PATCH', 'requirements' => array('path' => '.+')], |
54 | | - ['name' => 'contacts#handleHead', 'url' => '/@{userId}/contacts{path}', 'verb' => 'HEAD', 'requirements' => array('path' => '.+')], |
55 | | - |
56 | | - ['name' => 'solidWebhook#listWebhooks', 'url' => '/webhook/list', 'verb' => 'GET'], |
57 | | - ['name' => 'solidWebhook#register', 'url' => '/webhook/register', 'verb' => 'POST'], |
58 | | - ['name' => 'solidWebhook#unregister', 'url' => '/webhook/unregister', 'verb' => 'POST'], |
59 | | - |
60 | | - ['name' => 'solidWebsocket#register', 'url' => '/websocket/register', 'verb' => 'POST'], |
61 | | - |
62 | | - ['name' => 'app#appLauncher', 'url' => '/', 'verb' => 'GET'], |
63 | | - ] |
| 100 | + 'routes' => array_merge($routes, $userIdRoutes), |
64 | 101 | ]; |
0 commit comments