Skip to content

Commit

Permalink
Allow disabling uploads/encodes
Browse files Browse the repository at this point in the history
  • Loading branch information
danwdart committed Jan 17, 2018
1 parent 830a6e3 commit 90e5f8e
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 88 deletions.
3 changes: 3 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ ADMIN_USERNAME=admin
ADMIN_PASSWORD=admin
[email protected]
ADMIN_FULL_NAME=Admin User

# Set to true to disable uploads
NO_UPLOADS=false
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TWITTER_CONSUMER_SECRET=
SCHEME=http
VHOST=dev.projectchaplin.com
VHOST_PORT=80
VHOST_SHORT=p7c
VHOST_SHORT=pc
VHOST_NODE=node.projectchaplin.com
VHOST_NODE_PORT=80

Expand All @@ -65,3 +65,6 @@ ADMIN_USERNAME=admin
ADMIN_PASSWORD=admin
ADMIN_EMAIL=[email protected]
ADMIN_FULL_NAME=Admin User

# Set to true to disable uploads
NO_UPLOADS=false
4 changes: 4 additions & 0 deletions servers/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ services:
- TWITTER_CONSUMER_KEY=${TWITTER_CONSUMER_KEY}
- TWITTER_CONSUMER_SECRET=${TWITTER_CONSUMER_SECRET}
- SCHEME=${SCHEME}
- NO_UPLOADS=${NO_UPLOADS}
volumes:
- uploads:/var/www/public/uploads
depends_on:
Expand Down Expand Up @@ -70,6 +71,7 @@ services:
- SMTP_PORT=${SMTP_PORT}
- SMTP_USER=${SMTP_USER}
- SMTP_PASSWORD=${SMTP_PASSWORD}
- NO_UPLOADS=${NO_UPLOADS}
volumes:
- uploads:/var/www/public/uploads
depends_on:
Expand Down Expand Up @@ -100,6 +102,7 @@ services:
- SMTP_USER=${SMTP_USER}
- SMTP_PASSWORD=${SMTP_PASSWORD}
- YOUTUBE_API_TOKEN=${YOUTUBE_API_TOKEN}
- NO_UPLOADS=${NO_UPLOADS}
volumes:
- uploads:/var/www/public/uploads
depends_on:
Expand Down Expand Up @@ -132,6 +135,7 @@ services:
- VIMEO_CLIENT_SECRET=${VIMEO_CLIENT_SECRET}
- VIMEO_CLIENT_ID=${VIMEO_CLIENT_ID}
- VIMEO_ACCESS_TOKEN=${VIMEO_ACCESS_TOKEN}
- NO_UPLOADS=${NO_UPLOADS}
volumes:
- uploads:/var/www/public/uploads
depends_on:
Expand Down
29 changes: 29 additions & 0 deletions src/php/Chaplin/Module/Api/Controller/VideoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,17 @@ public function watchyoutubeAction()
$strLinkified = $linkify->process($strDescription);

$this->view->description = nl2br($strLinkified);

$this->view->nouploads = "true" === getenv("NO_UPLOADS");
}

public function importyoutubeAction()
{
if ("true" === getenv("NO_UPLOADS")) {
$this->_redirect('/');
return;
}

$strVideoId = $this->_request->getParam('id', null);
if(is_null($strVideoId)) {
$this->_redirect('/');
Expand Down Expand Up @@ -261,10 +268,17 @@ public function watchvimeoAction()
$strLinkified = $linkify->process($strDescription);

$this->view->description = nl2br($strLinkified);

$this->view->nouploads = ("true" === getenv("NO_UPLOADS"));
}

public function importvimeoAction()
{
if ("true" === getenv("NO_UPLOADS")) {
$this->_redirect('/');
return;
}

$strVideoId = $this->_request->getParam('id', null);
if(is_null($strVideoId)) {
$this->_redirect('/');
Expand Down Expand Up @@ -385,6 +399,11 @@ public function voteAction()

public function uploadAction()
{
if ("true" === getenv("NO_UPLOADS")) {
$this->_redirect('/');
return;
}

$form = new FormUpload();

if(!$this->_request->isPost()) {
Expand Down Expand Up @@ -509,6 +528,11 @@ public function nameAction()

public function editAction()
{
if ("true" === getenv("NO_UPLOADS")) {
$this->_redirect('/');
return;
}

$this->view->strTitle = 'Edit Video - Chaplin';
$modelUser = Auth::getInstance()
->hasIdentity()?
Expand Down Expand Up @@ -550,6 +574,11 @@ public function editAction()

public function deleteAction()
{
if ("true" === getenv("NO_UPLOADS")) {
$this->_redirect('/');
return;
}

$modelUser = Auth::getInstance()
->hasIdentity()?
Auth::getInstance()
Expand Down
3 changes: 3 additions & 0 deletions src/php/Chaplin/Module/Api/views/layouts/_header.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ if(Chaplin_Auth::getInstance()->hasIdentity()) :
$modelUser = Chaplin_Auth::getInstance()->getIdentity()->getUser();
$bIsLoggedIn = true;
endif;
$bNoUploads = ("true" === getenv("NO_UPLOADS"));
?>

<div class="wrap">
<a href="/"><div class="logo">
Chaplin
</div></a>
<div class="right">
<?php if (!$bNoUploads): ?>
<a href="/video/upload" class="upload button"><i class="fa fa-upload"></i> Upload</a>
<?php endif; ?>
<!--<a href="/broadcast" class="broadcast button"><i class="fa fa-video-camera"></i> Broadcast</a>-->

<span class="dropdown">
Expand Down
35 changes: 0 additions & 35 deletions src/php/Chaplin/Module/Api/views/layouts/_headerplain.phtml

This file was deleted.

51 changes: 0 additions & 51 deletions src/php/Chaplin/Module/Api/views/layouts/plain.phtml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
<br/>
<span class="text-sm"><?php echo $this->description; ?></span>
<br/>
<?php if (!$this->nouploads) : ?>
<a class="btn btn-success" href="/video/importvimeo/id/<?php echo substr($this->entryVideo['uri'], 8);?>"><i class="fa fa-download"></i> Import</a>
<?php endif; ?>
<?php if ($this->isLocal) : ?>
<a class="btn btn-primary" href="<?php echo $this->videoURL;?>"><i class="fa fa-download"></i> Download</a>
<?php endif; ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
<br/>
<span class="text-sm"><?php echo $this->description; ?></span>
<br/>
<?php if (!$this->nouploads) : ?>
<a class="btn btn-success" href="/video/importyoutube/id/<?php echo $this->entryVideo->id;?>"><i class="fa fa-download"></i> Import</a>
<?php endif; ?>
<?php if ($this->isLocal) : ?>
<a class="btn btn-primary" href="<?php echo $this->videoURL;?>"><i class="fa fa-download"></i> Download</a>
<?php endif; ?>
Expand Down
8 changes: 8 additions & 0 deletions src/php/Chaplin/Service/Encoder/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class Chaplin_Service_Encoder_API

public function convertFile($strFile, $strOut, $ret)
{
if ("true" === getenv("NO_UPLOADS")) {
return;
}

//TODO: stream status
$strCommand = sprintf(
self::CMD_CONVERT_FILE,
Expand All @@ -46,6 +50,10 @@ public function convertFile($strFile, $strOut, $ret)

public function getThumbnail($strFile, $strOut, $ret)
{
if ("true" === getenv("NO_UPLOADS")) {
return;
}

$strCommand = sprintf(
self::CMD_GET_THUMBNAIL,
$strFile,
Expand Down
14 changes: 13 additions & 1 deletion src/php/Chaplin/Service/Vimeo/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public function getDownloadURL($strURL)

public function downloadVideo($strURL, $strPathToSave, &$ret)
{
if ("true" === getenv("NO_UPLOADS")) {
return;
}

$strCommandLine = self::LOCATION.
" --recode-video webm -o ".
escapeshellarg($strPathToSave."/%(id)s.%(ext)s").
Expand All @@ -147,6 +151,10 @@ public function downloadVideo($strURL, $strPathToSave, &$ret)

public function downloadThumbnail($strVideoId, $strPathToSave)
{
if ("true" === getenv("NO_UPLOADS")) {
return;
}

$entryVideo = $this->getVideoById($strVideoId);

$strFilename = $strPathToSave.'/'.$strVideoId.'.webm.png';
Expand All @@ -161,6 +169,10 @@ public function downloadThumbnail($strVideoId, $strPathToSave)

public function importVideo(Chaplin_Model_User $modelUser, $strURL)
{
if ("true" === getenv("NO_UPLOADS")) {
return;
}

$strVideoId = $strURL;

$entryVideo = $this->getVideoById($strVideoId);
Expand Down Expand Up @@ -197,7 +209,7 @@ public function importVideo(Chaplin_Model_User $modelUser, $strURL)
$modelVideo,
$strVideoId
);

Chaplin_Gateway::getInstance()->getVideo_Vimeo()->save($modelYoutube);

return $modelVideo;
Expand Down
12 changes: 12 additions & 0 deletions src/php/Chaplin/Service/YouTube/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ public function getDownloadURL($strURL)

public function downloadVideo($strURL, $strPathToSave, &$ret)
{
if ("true" === getenv("NO_UPLOADS")) {
return;
}

$strCommandLine = self::LOCATION.
" -4 --format=webm -o ".
escapeshellarg($strPathToSave."/%(id)s.%(ext)s").
Expand All @@ -122,6 +126,10 @@ public function downloadVideo($strURL, $strPathToSave, &$ret)

public function downloadThumbnail($strVideoId, $strPathToSave)
{
if ("true" === getenv("NO_UPLOADS")) {
return;
}

$entryVideo = $this->getVideoById($strVideoId);

$strFilename = $strPathToSave.'/'.$entryVideo->id.'.webm.png';
Expand All @@ -136,6 +144,10 @@ public function downloadThumbnail($strVideoId, $strPathToSave)

public function importVideo(Chaplin_Model_User $modelUser, $strURL)
{
if ("true" === getenv("NO_UPLOADS")) {
return;
}

$strVideoId = $strURL;

$entryVideo = $this->getVideoById($strVideoId);
Expand Down

0 comments on commit 90e5f8e

Please sign in to comment.