|
12 | 12 | use OCA\GlobalSiteSelector\AppInfo\Application; |
13 | 13 | use OCA\GlobalSiteSelector\Exceptions\MasterUrlException; |
14 | 14 | use OCA\GlobalSiteSelector\GlobalSiteSelector; |
| 15 | +use OCA\GlobalSiteSelector\Service\GlobalScaleService; |
15 | 16 | use OCA\GlobalSiteSelector\Service\SlaveService; |
16 | 17 | use OCA\GlobalSiteSelector\Slave; |
17 | 18 | use OCA\GlobalSiteSelector\TokenHandler; |
|
21 | 22 | use OCA\GlobalSiteSelector\Vendor\Firebase\JWT\Key; |
22 | 23 | use OCP\AppFramework\Http; |
23 | 24 | use OCP\AppFramework\Http\DataResponse; |
| 25 | +use OCP\AppFramework\Http\JSONResponse; |
24 | 26 | use OCP\AppFramework\Http\RedirectResponse; |
25 | 27 | use OCP\AppFramework\OCSController; |
26 | 28 | use OCP\IConfig; |
|
41 | 43 | * @package OCA\GlobalSiteSelector\Controller |
42 | 44 | */ |
43 | 45 | class SlaveController extends OCSController { |
44 | | - |
45 | 46 | public function __construct( |
46 | 47 | $appName, |
47 | 48 | IRequest $request, |
48 | | - private GlobalSiteSelector $gss, |
49 | | - private IUserSession $userSession, |
50 | | - private IURLGenerator $urlGenerator, |
51 | | - private ICrypto $crypto, |
52 | | - private TokenHandler $tokenHandler, |
53 | | - private IUserManager $userManager, |
54 | | - private UserBackend $userBackend, |
55 | | - private ISession $session, |
56 | | - private SlaveService $slaveService, |
57 | | - private IConfig $config, |
58 | | - private LoggerInterface $logger, |
| 49 | + private readonly GlobalSiteSelector $gss, |
| 50 | + private readonly IUserSession $userSession, |
| 51 | + private readonly IURLGenerator $urlGenerator, |
| 52 | + private readonly ICrypto $crypto, |
| 53 | + private readonly TokenHandler $tokenHandler, |
| 54 | + private readonly IUserManager $userManager, |
| 55 | + private readonly UserBackend $userBackend, |
| 56 | + private readonly ISession $session, |
| 57 | + private readonly SlaveService $slaveService, |
| 58 | + private readonly GlobalScaleService $globalScaleService, |
| 59 | + private readonly IConfig $config, |
| 60 | + private readonly LoggerInterface $logger, |
59 | 61 | ) { |
60 | 62 | parent::__construct($appName, $request); |
61 | 63 | } |
62 | 64 |
|
| 65 | + |
| 66 | + /** |
| 67 | + * @PublicPage |
| 68 | + * @NoCSRFRequired |
| 69 | + */ |
| 70 | + public function discovery(): DataResponse { |
| 71 | + // public data, reachable from outside. |
| 72 | + return new DataResponse(['token' => $this->globalScaleService->getLocalToken()]); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * @PublicPage |
| 77 | + * @NoCSRFRequired |
| 78 | + */ |
| 79 | + public function sharedFile(?string $jwt): DataResponse { |
| 80 | + if ($jwt === null) { |
| 81 | + return new DataResponse(['message' => 'missing jwt'], Http::STATUS_NOT_FOUND); |
| 82 | + } |
| 83 | + $key = $this->gss->getJwtKey(); |
| 84 | + $decoded = (array)JWT::decode($jwt, new Key($key, Application::JWT_ALGORITHM)); |
| 85 | + $fileId = $decoded['fileId'] ?? 0; |
| 86 | + $instance = $decoded['instance'] ?? ''; |
| 87 | + |
| 88 | + if ($fileId === 0 || $instance === '') { |
| 89 | + return new DataResponse(['message' => 'missing argument'], Http::STATUS_NOT_FOUND); |
| 90 | + } |
| 91 | + |
| 92 | + $files = $this->globalScaleService->getRelatedFilesDetails((int)$fileId); |
| 93 | + $shares = $this->globalScaleService->getFederatedShareIdFromRemote($files, $instance); |
| 94 | + |
| 95 | + return new DataResponse($shares); |
| 96 | + } |
| 97 | + |
| 98 | + |
63 | 99 | /** |
64 | 100 | * @PublicPage |
65 | 101 | * @NoCSRFRequired |
|
0 commit comments