From fb141e259be87b4ba2166242e2b63775f18eddc4 Mon Sep 17 00:00:00 2001 From: Celestora Date: Tue, 12 Apr 2022 22:01:12 +0300 Subject: [PATCH] Show stub if video is not processed --- Web/Models/Entities/Media.php | 45 ++++++++++++++++++++++++++++++-- Web/Models/Entities/Video.php | 25 ++++++++++++++++-- Web/static/video/rendering.apng | Bin 0 -> 2831 bytes Web/static/video/rendering.ogv | Bin 0 -> 5448 bytes 4 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 Web/static/video/rendering.apng create mode 100644 Web/static/video/rendering.ogv diff --git a/Web/Models/Entities/Media.php b/Web/Models/Entities/Media.php index d86e6441..b836955e 100644 --- a/Web/Models/Entities/Media.php +++ b/Web/Models/Entities/Media.php @@ -6,7 +6,9 @@ abstract class Media extends Postable { protected $fileExtension = "oct"; #octet stream xddd protected $upperNodeReferenceColumnName = "owner"; - + protected $processingPlaceholder = NULL; + protected $processingTime = 30; + function __destruct() { #Remove data, if model wasn't presisted @@ -22,6 +24,11 @@ abstract class Media extends Postable else return OPENVK_ROOT . "/storage/"; } + + protected function checkIfFileIsProcessed(): bool + { + throw new \LogicException("checkIfFileIsProcessed is not implemented"); + } abstract protected function saveFile(string $filename, string $hash): bool; @@ -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"]) { @@ -68,6 +79,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 { @@ -89,7 +120,17 @@ 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"); diff --git a/Web/Models/Entities/Video.php b/Web/Models/Entities/Video.php index f57159b7..7bf1b010 100644 --- a/Web/Models/Entities/Video.php +++ b/Web/Models/Entities/Video.php @@ -14,6 +14,8 @@ class Video extends Media protected $tableName = "videos"; protected $fileExtension = "ogv"; + + protected $processingPlaceholder = "video/rendering"; 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"); try { - if(!is_dir($dirId = $this->pathFromHash($hash))) + if(!is_dir($dirId = dirname($this->pathFromHash($hash)))) mkdir($dirId); $dir = $this->getBaseDir(); @@ -53,7 +55,23 @@ class Video extends Media usleep(200100); 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(); diff --git a/Web/static/video/rendering.apng b/Web/static/video/rendering.apng new file mode 100644 index 0000000000000000000000000000000000000000..417aa4268ba9c6595f6fb69f843396120d3331c3 GIT binary patch literal 2831 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A1{5*9c;^X_;wb| z85p<@db&7}644aOh!RVdxM9T4%^4z@Xs9z{GHb!-1hef{}wkK$(G& zA!$_6Xb_C1f?=8wX6)~mV>tJyYVW^~|MR!szWnz8mmiyt%gJW%e7m?Z?(DX-`}a4N z{XhTge)8{|pL^capFN-TbI--k>0kcTeA{#Jd-~5ky6ekJ=9w11t&DT-6?Ldce0wzS z?YG6hZ$G|KEnEEU-*>Bb%lF?CJfCKH`;Yryna2N{nK-!Xqe^$it>3-gY)!0hWc8i( zzh{1w+V-yg%Z&c8>(hSEw>^L2pZr;yivX%cbas$gPW?`_C1B+4CVdlCi~n)=ndq`KR79@0kzMqjKZO zU77TV(77*xUj3bax>$eu{MvJWzs$FnIm)G=Gv{rS@$Yr_ZhqVKy7)=otMW6(hi9G7 zd{-NMY1Z3*i~D)oZ`a$&bG$jtrLbnhw{!PQ6+e1@G&}u*wf0+eSxUm4yzTk>_sy5` zs0&Y!({9*Mu+5s!{;$%GZ|m;4-|m0+|FvP-+2Rs|x~)(3KKcL2+iQBilVeRft3X`E z*HYcEZ^!1mt+l#sv)FC_9LWbof(;+Ulmz9fON4vwOV4m;IK&@1er@@gK7alJD?4Tmp!~B}<=^&xwTw@%D!u-s{Q3P||7X5`E;irj{EKhZ zXYF5qZe0Al|Em2Akn=yhQ7T!+ePwavw^@bj|IUADyF2Eb@%d|(=ZyYqZ$9szus8nu z@4w$KIy=n0%Exf;B$vXRh7ZgS=B@$N3lWT?RmEs+Ioeijy`JGJv Qfh}AHPgg&ebxsLQ08N&c-T(jq literal 0 HcmV?d00001 diff --git a/Web/static/video/rendering.ogv b/Web/static/video/rendering.ogv new file mode 100644 index 0000000000000000000000000000000000000000..938dc15449d0c0454e54281b6d553b79076d43d4 GIT binary patch literal 5448 zcmbuCXEa=I*TxN^1knki4E{>=km%885M)M62oY_R7`;aCo#+uk)acRM=q=HE8$D{2 zAqa^!?~uIZ)AOwLKG&Mrzx&$z?0cOv`^<;?sfC3W7B<#jyh z+c_HJU<0tYu$Zv0{jdPbHy4^=A{7=E;O2vc^>yay^)COT>s>H4EF{@w;~g3F|52F# zpDjr+RW)N**h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