Skip to content

Commit

Permalink
send file content (works with other storage systems) (#581)
Browse files Browse the repository at this point in the history
* send file content (works with other storage systems)

* add changelog, add tests, add lock file

* add files

* test other methods
  • Loading branch information
nadar authored Oct 14, 2020
1 parent f52bb7b commit 142900b
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ In order to read more about upgrading and BC breaks have a look at the [UPGRADE
+ [#577](https://github.com/luyadev/luya-module-admin/pull/577) Queue Scheduler Job loads only the target attribute into the model.
+ [#579](https://github.com/luyadev/luya-module-admin/pull/579) Updated Portuguese translation files.
+ [#580](https://github.com/luyadev/luya-module-admin/pull/580) Fix issue where the OpenApi parser does not return models which are instance of `yii\base\Model`.
+ [#581](https://github.com/luyadev/luya-module-admin/pull/581) Ensure the proxy api to synchronise files uses the `sendContentAsFile` in order to support 3rd party storage systems like AWS.

## 3.6.1 (1. October 2020)

Expand Down
35 changes: 18 additions & 17 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/apis/ProxyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private function ensureBuild($machine, $buildToken)
throw new ForbiddenHttpException("The expiration time ".date("d.m.Y H:i:s", $build->expiration_time)." has exceeded.");
}

if ($build->proxyMachine->identifier !== $machine) {
if (!$build->proxyMachine || $build->proxyMachine->identifier !== $machine) {
throw new ForbiddenHttpException("Invalid machine identifier for current build.");
}

Expand Down Expand Up @@ -208,11 +208,11 @@ public function actionFileProvider($machine, $buildToken, $fileId)

$file = Yii::$app->storage->getFile($fileId);
/* @var $file \luya\admin\file\Item */
if ($file->fileExists) {
return Yii::$app->response->sendFile($file->serverSource, null, ['mimeType' => $file->mimeType])->send();
if ($file && $file->fileExists) {
return Yii::$app->response->sendContentAsFile($file->getContent(), $file->serverSource, null, ['mimeType' => $file->mimeType])->send();
}

throw new NotFoundHttpException("The requested file '".$file->serverSource."' does not exist in the storage folder.");
throw new NotFoundHttpException("The requested file '".$fileId."' does not exist in the storage folder.");
}
}

Expand All @@ -236,11 +236,11 @@ public function actionImageProvider($machine, $buildToken, $imageId)

$image = Yii::$app->storage->getImage($imageId);
/* @var $image \luya\admin\image\Item */
if ($image->fileExists) {
if ($image && $image->fileExists) {
return Yii::$app->response->sendFile($image->serverSource)->send();
}

throw new NotFoundHttpException("The requested image '".$image->serverSource."' does not exist in the storage folder.");
throw new NotFoundHttpException("The requested image '".$imageId."' does not exist in the storage folder.");
}
}

Expand Down
59 changes: 43 additions & 16 deletions src/models/ProxyBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* @property string $config
* @property integer $is_complet
* @property integer $expiration_time
*
* @property ProxyMachine $proxyMachine
* @property array $arrayConfig
*
* @author Basil Suter <basil@nadar.io>
Expand All @@ -41,7 +43,7 @@ public function rules()
[['machine_id', 'timestamp', 'expiration_time'], 'integer'],
[['is_complet'], 'boolean'],
[['config'], 'string'],
[['build_token'], 'string', 'max' => 255],
[['build_token'], 'string', 'max' => 190],
[['build_token'], 'unique'],
];
}
Expand All @@ -62,6 +64,11 @@ public function attributeLabels()
];
}

/**
* ProxyMachine relation
*
* @return ProxyMachine
*/
public function getProxyMachine()
{
return $this->hasOne(ProxyMachine::class, ['id' => 'machine_id']);
Expand All @@ -77,6 +84,11 @@ public static function ngRestApiEndpoint()

private $_arrayConfig;

/**
* Get an array from the config json
*
* @return array
*/
public function getArrayConfig()
{
if ($this->_arrayConfig === null) {
Expand All @@ -86,18 +98,29 @@ public function getArrayConfig()
return $this->_arrayConfig;
}

/**
* Get rowsPerRequest from json config
*
* @return integer
*/
public function getRowsPerRequest()
{
return $this->arrayConfig['rowsPerRequest'];
}

/**
* Get the full configuration for a given table
*
* @param string $table
* @return array|false False if the table is not found
*/
public function getTableConfig($table)
{
return isset($this->arrayConfig['tables'][$table]) ? $this->arrayConfig['tables'][$table] : false;
}

/**
* @return array An array define the field types of each field
* {@inheritDoc}
*/
public function ngRestAttributeTypes()
{
Expand All @@ -109,22 +132,26 @@ public function ngRestAttributeTypes()
'expiration_time' => 'datetime',
];
}

/**
* Define the NgRestConfig for this model with the ConfigBuilder object.
*
* @param \luya\admin\ngrest\ConfigBuilder $config The current active config builder object.
* @return \luya\admin\ngrest\ConfigBuilder
* {@inheritDoc}
*/
public function ngRestConfig($config)
public function ngRestScopes()
{
$config->aw->load([
'class' => DetailViewActiveWindow::class,
]);

// define fields for types based from ngrestAttributeTypes
$this->ngRestConfigDefine($config, 'list', ['machine_id', 'build_token', 'expiration_time', 'is_complet']);

return $config;
return [
[['list'], ['machine_id', 'build_token', 'expiration_time', 'is_complet']]
];
}

/**
* {@inheritDoc}
*/
public function ngRestActiveWindows()
{
return [
[
'class' => DetailViewActiveWindow::class,
]
];
}
}
Loading

0 comments on commit 142900b

Please sign in to comment.