banki.test/controllers/ApiController.php

38 lines
937 B
PHP
Raw Normal View History

<?php
namespace app\controllers;
use app\models\Parameter;
2024-08-20 06:47:29 +02:00
use app\models\Image;
use yii\data\ActiveDataProvider;
use yii\rest\IndexAction;
2024-08-20 06:47:29 +02:00
use yii\web\NotFoundHttpException;
use yii\web\Request;
use yii\web\Response;
class ApiController extends \yii\rest\Controller
{
public function actionIndex()
{
return Parameter::find()->with(['icon', 'iconGray'])->all();
}
2024-08-20 06:47:29 +02:00
public function actionImage(Request $request)
{
$img = Image::find()->where([ 'sha256' => $request->getQueryParam('sha256') ])->one();
if (!$img) {
throw new NotFoundHttpException();
}
\Yii::$app->response->format = Response::FORMAT_RAW;
\Yii::$app->response->headers->set('Content-Type', $img->mime);
return file_get_contents(env('UPLOADS_PATH') . '/' . $img->sha256);
}
public function verbs()
{
return [
'index' => [ 'GET' ],
];
}
}