Show stub if video is not processed

This commit is contained in:
Celestora 2022-04-12 22:01:12 +03:00
parent f3f62a63ac
commit fb141e259b
4 changed files with 66 additions and 4 deletions

View file

@ -6,6 +6,8 @@ abstract class Media extends Postable
{
protected $fileExtension = "oct"; #octet stream xddd
protected $upperNodeReferenceColumnName = "owner";
protected $processingPlaceholder = NULL;
protected $processingTime = 30;
function __destruct()
{
@ -23,6 +25,11 @@ abstract class Media extends Postable
return OPENVK_ROOT . "/storage/";
}
protected function checkIfFileIsProcessed(): bool
{
throw new \LogicException("checkIfFileIsProcessed is not implemented");
}
abstract protected function saveFile(string $filename, string $hash): bool;
protected function pathFromHash(string $hash): string
@ -41,6 +48,10 @@ abstract class Media extends Postable
function getURL(): string
{
if(!is_null($this->processingPlaceholder))
if(!$this->isProcessed())
return "/assets/packages/static/openvk/$this->processingPlaceholder.$this->fileExtension";
$hash = $this->getRecord()->hash;
switch(OPENVK_ROOT_CONF["openvk"]["preferences"]["uploads"]["mode"]) {
@ -69,6 +80,26 @@ abstract class Media extends Postable
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
{
return (bool) $this->getRecord()->deleted;
@ -90,6 +121,16 @@ abstract class Media extends Postable
$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
{
$deleteQuirk = ovkGetQuirk("blobs.erase-upon-deletion");

View file

@ -15,6 +15,8 @@ class Video extends Media
protected $tableName = "videos";
protected $fileExtension = "ogv";
protected $processingPlaceholder = "video/rendering";
protected function saveFile(string $filename, string $hash): bool
{
if(!Shell::commandAvailable("ffmpeg") || !Shell::commandAvailable("ffprobe"))
@ -37,7 +39,7 @@ class Video extends Media
throw new \DomainException("$filename does not contain any meaningful video streams");
try {
if(!is_dir($dirId = $this->pathFromHash($hash)))
if(!is_dir($dirId = dirname($this->pathFromHash($hash))))
mkdir($dirId);
$dir = $this->getBaseDir();
@ -54,6 +56,22 @@ class Video extends Media
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
{
return $this->getRecord()->name;
@ -83,6 +101,9 @@ class Video extends Media
function getThumbnailURL(): string
{
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());
} else {
return $this->getVideoDriver()->getThumbnailURL();

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.