mirror of
https://github.com/openvk/openvk
synced 2025-01-09 01:09:46 +03:00
Show stub if video is not processed
This commit is contained in:
parent
f3f62a63ac
commit
fb141e259b
4 changed files with 66 additions and 4 deletions
|
@ -6,7 +6,9 @@ abstract class Media extends Postable
|
||||||
{
|
{
|
||||||
protected $fileExtension = "oct"; #octet stream xddd
|
protected $fileExtension = "oct"; #octet stream xddd
|
||||||
protected $upperNodeReferenceColumnName = "owner";
|
protected $upperNodeReferenceColumnName = "owner";
|
||||||
|
protected $processingPlaceholder = NULL;
|
||||||
|
protected $processingTime = 30;
|
||||||
|
|
||||||
function __destruct()
|
function __destruct()
|
||||||
{
|
{
|
||||||
#Remove data, if model wasn't presisted
|
#Remove data, if model wasn't presisted
|
||||||
|
@ -22,6 +24,11 @@ abstract class Media extends Postable
|
||||||
else
|
else
|
||||||
return OPENVK_ROOT . "/storage/";
|
return OPENVK_ROOT . "/storage/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function checkIfFileIsProcessed(): bool
|
||||||
|
{
|
||||||
|
throw new \LogicException("checkIfFileIsProcessed is not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
abstract protected function saveFile(string $filename, string $hash): bool;
|
abstract protected function saveFile(string $filename, string $hash): bool;
|
||||||
|
|
||||||
|
@ -41,6 +48,10 @@ abstract class Media extends Postable
|
||||||
|
|
||||||
function getURL(): string
|
function getURL(): string
|
||||||
{
|
{
|
||||||
|
if(!is_null($this->processingPlaceholder))
|
||||||
|
if(!$this->isProcessed())
|
||||||
|
return "/assets/packages/static/openvk/$this->processingPlaceholder.$this->fileExtension";
|
||||||
|
|
||||||
$hash = $this->getRecord()->hash;
|
$hash = $this->getRecord()->hash;
|
||||||
|
|
||||||
switch(OPENVK_ROOT_CONF["openvk"]["preferences"]["uploads"]["mode"]) {
|
switch(OPENVK_ROOT_CONF["openvk"]["preferences"]["uploads"]["mode"]) {
|
||||||
|
@ -68,6 +79,26 @@ abstract class Media extends Postable
|
||||||
{
|
{
|
||||||
return $this->getRecord()->description;
|
return $this->getRecord()->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function isProcessed(): bool
|
||||||
|
{
|
||||||
|
if(is_null($this->processingPlaceholder))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if($this->getRecord()->processed)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
$timeDiff = time() - $this->getRecord()->last_checked;
|
||||||
|
if($timeDiff < $this->processingTime)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$res = $this->checkIfFileIsProcessed();
|
||||||
|
$this->stateChanges("last_checked", time());
|
||||||
|
$this->stateChanges("processed", $res);
|
||||||
|
$this->save();
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
function isDeleted(): bool
|
function isDeleted(): bool
|
||||||
{
|
{
|
||||||
|
@ -89,7 +120,17 @@ abstract class Media extends Postable
|
||||||
|
|
||||||
$this->stateChanges("hash", $hash);
|
$this->stateChanges("hash", $hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function save(): void
|
||||||
|
{
|
||||||
|
if(!is_null($this->processingPlaceholder)) {
|
||||||
|
$this->stateChanges("processed", 0);
|
||||||
|
$this->stateChanges("last_checked", time());
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::save();
|
||||||
|
}
|
||||||
|
|
||||||
function delete(bool $softly = true): void
|
function delete(bool $softly = true): void
|
||||||
{
|
{
|
||||||
$deleteQuirk = ovkGetQuirk("blobs.erase-upon-deletion");
|
$deleteQuirk = ovkGetQuirk("blobs.erase-upon-deletion");
|
||||||
|
|
|
@ -14,6 +14,8 @@ class Video extends Media
|
||||||
|
|
||||||
protected $tableName = "videos";
|
protected $tableName = "videos";
|
||||||
protected $fileExtension = "ogv";
|
protected $fileExtension = "ogv";
|
||||||
|
|
||||||
|
protected $processingPlaceholder = "video/rendering";
|
||||||
|
|
||||||
protected function saveFile(string $filename, string $hash): bool
|
protected function saveFile(string $filename, string $hash): bool
|
||||||
{
|
{
|
||||||
|
@ -37,7 +39,7 @@ class Video extends Media
|
||||||
throw new \DomainException("$filename does not contain any meaningful video streams");
|
throw new \DomainException("$filename does not contain any meaningful video streams");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(!is_dir($dirId = $this->pathFromHash($hash)))
|
if(!is_dir($dirId = dirname($this->pathFromHash($hash))))
|
||||||
mkdir($dirId);
|
mkdir($dirId);
|
||||||
|
|
||||||
$dir = $this->getBaseDir();
|
$dir = $this->getBaseDir();
|
||||||
|
@ -53,7 +55,23 @@ class Video extends Media
|
||||||
usleep(200100);
|
usleep(200100);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function checkIfFileIsProcessed(): bool
|
||||||
|
{
|
||||||
|
if($this->getType() != Video::TYPE_DIRECT)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if(!file_exists($this->getFileName())) {
|
||||||
|
if((time() - $this->getRecord()->last_checked) > 3600) {
|
||||||
|
// TODO notify that video processor is probably dead
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function getName(): string
|
function getName(): string
|
||||||
{
|
{
|
||||||
return $this->getRecord()->name;
|
return $this->getRecord()->name;
|
||||||
|
@ -83,6 +101,9 @@ class Video extends Media
|
||||||
function getThumbnailURL(): string
|
function getThumbnailURL(): string
|
||||||
{
|
{
|
||||||
if($this->getType() === Video::TYPE_DIRECT) {
|
if($this->getType() === Video::TYPE_DIRECT) {
|
||||||
|
if(!$this->isProcessed())
|
||||||
|
return "/assets/packages/static/openvk/video/rendering.apng";
|
||||||
|
|
||||||
return preg_replace("%\.[A-z]++$%", ".gif", $this->getURL());
|
return preg_replace("%\.[A-z]++$%", ".gif", $this->getURL());
|
||||||
} else {
|
} else {
|
||||||
return $this->getVideoDriver()->getThumbnailURL();
|
return $this->getVideoDriver()->getThumbnailURL();
|
||||||
|
|
BIN
Web/static/video/rendering.apng
Normal file
BIN
Web/static/video/rendering.apng
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
BIN
Web/static/video/rendering.ogv
Normal file
BIN
Web/static/video/rendering.ogv
Normal file
Binary file not shown.
Loading…
Reference in a new issue