1 | <?php |
||
27 | class Controller |
||
28 | { |
||
29 | /** |
||
30 | * @var CloudManagerInterface |
||
31 | */ |
||
32 | private $cloudManager; |
||
33 | |||
34 | /** |
||
35 | * @var EventDispatcherInterface |
||
36 | */ |
||
37 | private $eventDispatcher; |
||
38 | |||
39 | /** |
||
40 | * @param CloudManagerInterface $cloudManager |
||
41 | * @param EventDispatcherInterface $eventDispatcher |
||
42 | */ |
||
43 | 9 | public function __construct(CloudManagerInterface $cloudManager, EventDispatcherInterface $eventDispatcher) |
|
44 | { |
||
45 | 9 | $this->cloudManager = $cloudManager; |
|
46 | 9 | $this->eventDispatcher = $eventDispatcher; |
|
47 | 9 | } |
|
48 | |||
49 | /** |
||
50 | * Sign a set of given url parameters and return them as a JSON object. |
||
51 | * |
||
52 | * Specials keys are <em>method</em> and <em>path</em>. <em>method</em> is |
||
53 | * the http method and <em>path</em> the url part of the api request for |
||
54 | * which the signature is generated. The default <em>method</em> if not |
||
55 | * given is <em>GET</em>, the default <em>path</em> is <em>/videos.json</em>. |
||
56 | * All remaining url parameters are treated as parameters for the api |
||
57 | * request. |
||
58 | * |
||
59 | * @param string $cloud Cloud to use for performing API requests |
||
60 | * @param Request $request The current request |
||
61 | * |
||
62 | * @return JsonResponse The response |
||
63 | */ |
||
64 | 2 | public function signAction($cloud, Request $request) |
|
65 | { |
||
66 | 2 | $params = $request->query->all(); |
|
67 | |||
68 | 2 | if (isset($params['method'])) { |
|
69 | 1 | $method = $params['method']; |
|
70 | 1 | unset($params['method']); |
|
71 | } else { |
||
72 | 2 | $method = 'GET'; |
|
73 | } |
||
74 | |||
75 | 2 | if (isset($params['path'])) { |
|
76 | 1 | $path = $params['path']; |
|
77 | 1 | unset($params['path']); |
|
78 | } else { |
||
79 | 2 | $path = '/videos.json'; |
|
80 | } |
||
81 | |||
82 | 2 | $httpClient = $this->cloudManager->getCloud($cloud)->getHttpClient(); |
|
83 | 2 | $cloudId = $httpClient->getCloudId(); |
|
84 | 2 | $account = $httpClient->getAccount(); |
|
85 | 2 | $signer = PandaSigner::getInstance($cloudId, $account); |
|
86 | |||
87 | 2 | return new JsonResponse($signer->signParams($method, $path, $params)); |
|
88 | } |
||
89 | |||
90 | /** |
||
91 | * Authorize a file upload. |
||
92 | * |
||
93 | * The name of the file to upload and its size are passed as POST parameters. |
||
94 | * The response contains a JSON encoded object. It includes a property |
||
95 | * upload_url to which the caller should send its video file. |
||
96 | * |
||
97 | * @param string $cloud Cloud to use for performing API requests |
||
98 | * @param Request $request The current request |
||
99 | * |
||
100 | * @return JsonResponse The response |
||
101 | */ |
||
102 | 1 | public function authoriseUploadAction($cloud, Request $request) |
|
103 | { |
||
104 | 1 | $payload = json_decode($request->request->get('payload')); |
|
105 | 1 | $upload = $this->cloudManager |
|
106 | 1 | ->getCloud($cloud) |
|
107 | 1 | ->registerUpload( |
|
108 | 1 | $payload->filename, |
|
109 | 1 | $payload->filesize, |
|
110 | 1 | null, |
|
111 | 1 | true |
|
112 | ); |
||
113 | |||
114 | 1 | return new JsonResponse(array('upload_url' => $upload->location)); |
|
115 | } |
||
116 | |||
117 | /** |
||
118 | * Endpoint for notification requests. |
||
119 | * |
||
120 | * @param Request $request The current request |
||
121 | * |
||
122 | * @return Response An empty response with status code 200 |
||
123 | */ |
||
124 | 6 | public function notifyAction(Request $request) |
|
135 | } |
||
136 |