@@ 162-176 (lines=15) @@ | ||
159 | * |
|
160 | * @return string json status |
|
161 | */ |
|
162 | public function actionUpload($type) |
|
163 | { |
|
164 | Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
165 | ||
166 | if (!Yii::$app->user->can('upload')) { |
|
167 | return ['success' => false, 'message' => Yii::t('app', 'Not authorized')]; |
|
168 | } |
|
169 | ||
170 | $model = new Content(['type_id' => $type]); |
|
171 | if (($res = $model->type->upload(UploadedFile::getInstanceByName('content'))) !== false) { |
|
172 | return ['success' => true, 'filepath' => $res['tmppath'], 'duration' => $res['duration'], 'filename' => $res['filename']]; |
|
173 | } |
|
174 | ||
175 | return ['success' => false, 'message' => $model->type->getLoadError()]; |
|
176 | } |
|
177 | ||
178 | /** |
|
179 | * Receives an url to download on server -- sideloading. |
|
@@ 188-202 (lines=15) @@ | ||
185 | * |
|
186 | * @return string json status |
|
187 | */ |
|
188 | public function actionSideload($type, $url) |
|
189 | { |
|
190 | Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
|
191 | ||
192 | if (!Yii::$app->user->can('upload')) { |
|
193 | return ['success' => false, 'message' => Yii::t('app', 'Not authorized')]; |
|
194 | } |
|
195 | ||
196 | $model = new Content(['type_id' => $type]); |
|
197 | if (($res = $model->type->sideload($url)) !== false) { |
|
198 | return ['success' => true, 'filepath' => $res['tmppath'], 'duration' => $res['duration'], 'filename' => $res['filename']]; |
|
199 | } |
|
200 | ||
201 | return ['success' => false, 'message' => $model->type->getLoadError()]; |
|
202 | } |
|
203 | ||
204 | /** |
|
205 | * Updates an existing Content model. |