service/controllers/ContentController.php
/**
     * Handles file downloading
     *
     * @param  string $hash link hash
     * @return mixed
     */
Handles file downloading
@param  string $hash link hash
@return mixed
Handles file downloading @param string $hash link hash @return mixed
public function actionDownload($hash)
    {
        $link = Link::findByHash($hash)->one();
        if ($link !== null) {
            if (Yii::$app->service->instance->isStoringEnabled()) {
                $storedContent = StoredContent::findByLink($link);
                if ($storedContent != null && $storedContent->isComplete()) {
                    $content = null;
                    try {
                        $content = $storedContent->getContent();
                    } catch (\Exception $e) {
                        Yii::error($e);
                    }
                    if ($content !== null) {
                        $content->sendContent();
                    }
                }
            }
            if (!isset($content) || $content == null) {
                $provider = $link->getContentProvider();
                if ($provider !== null) {
                    if ($provider->isDownloadable()) {
                        try {
                            $content = $provider->getContent($link);
                        } catch (\Exception $e) {
                            Yii::error($e);
                            throw new HttpException(500, 'Internal server error occured. Please try again later.');
                        }
                    } else {
                        throw new HttpException(400, 'Provided content can\'t be downloaded.');
                    }
                } else {
                    throw new HttpException(400, 'Content provider not found.');
                }
                $content->sendContent();
            }
        } else {
            throw new NotFoundHttpException('Page not found.');
        }
    }
public function actionDownload ( $ hash ) { $ link = Link :: findByHash ( $ hash ) -> one ( ) ; if ( $ link !== null ) { if ( Yii :: $ app -> service -> instance -> isStoringEnabled ( ) ) { $ storedContent = StoredContent :: findByLink ( $ link ) ; if ( $ storedContent != null && $ storedContent -> isComplete ( ) ) { $ content = null ; try { $ content = $ storedContent -> getContent ( ) ; } catch ( \ Exception $ e ) { Yii :: error ( $ e ) ; } if ( $ content !== null ) { $ content -> sendContent ( ) ; } } } if ( ! isset ( $ content ) || $ content == null ) { $ provider = $ link -> getContentProvider ( ) ; if ( $ provider !== null ) { if ( $ provider -> isDownloadable ( ) ) { try { $ content = $ provider -> getContent ( $ link ) ; } catch ( \ Exception $ e ) { Yii :: error ( $ e ) ; throw new HttpException ( 500 , 'Internal server error occured. Please try again later.' ) ; } } else { throw new HttpException ( 400 , 'Provided content can\'t be downloaded.' ) ; } } else { throw new HttpException ( 400 , 'Content provider not found.' ) ; } $ content -> sendContent ( ) ; } } else { throw new NotFoundHttpException ( 'Page not found.' ) ; } }
Handles file downloading
 @param  string $hash link hash
 @return mixed
Handles file downloading @param string $hash link hash @return mixed
//Check if we have stored copy of content //No content found in storage. Use content provider. //Send content to client