/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
backend/controllers/data/gpt/FileController.php
80 строк
2 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace backend\controllers\data\gpt; use common\components\OpenAIComponent; use common\controllers\base\ParentCrudController; use common\models\File; use common\models\Project; use OpenAI\Client; use Yii; /** * Контроллер для работы с файлами * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2025 */ class FileController extends ParentCrudController { /** * @inheritdoc */ protected $modelClassPath = 'backend\components\crud\gpt\file'; /** * @inheritdoc */ protected $classPrefix = 'File'; /** * @inheritdoc */ protected $parentModelName = 'common\models\Project'; /** * @inheritdoc */ protected $relationKey = ['project_id' => 'id']; /** * @inheritdoc */ protected $canAdd = false; /** * Скачать файл * * @param $id * @return \yii\console\Response|\yii\web\Response * @throws \yii\base\InvalidConfigException * @throws \yii\web\RangeNotSatisfiableHttpException */ public function actionDownload($id) { Yii::$app->request->validateSig(); $file = File::findOne($id); $p = Project::findOne($file->project_id); $openAI = Yii::createObject([ 'class' => OpenAIComponent::class, 'project_id' => $p->key ]); /** @var Client $client */ $client = $openAI->getClient(); $content = $client->files()->download($file->key); return Yii::$app->response->sendContentAsFile( $content, $file->fname, [ 'mimeType' => $file->ftype, 'inline' => false ] ); } }