feat: API for getting images
This commit is contained in:
parent
c0edeca406
commit
1fc412ba57
|
@ -2,8 +2,12 @@
|
|||
|
||||
namespace app\controllers;
|
||||
use app\models\Parameter;
|
||||
use app\models\Image;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\rest\IndexAction;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\web\Request;
|
||||
use yii\web\Response;
|
||||
|
||||
class ApiController extends \yii\rest\Controller
|
||||
{
|
||||
|
@ -12,6 +16,18 @@ class ApiController extends \yii\rest\Controller
|
|||
return Parameter::find()->with(['icon', 'iconGray'])->all();
|
||||
}
|
||||
|
||||
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 [
|
||||
|
|
Loading…
Reference in New Issue