From 4bfdeddd22669a91e0b80931291fbe4a84096d9f Mon Sep 17 00:00:00 2001 From: Ilya Prokopenko Date: Tue, 23 May 2023 19:28:21 +0700 Subject: [PATCH] Video: Fast addition of a video with its file name For example, how would you know there were spoilers for Steins;Gate if the video was titled "Unnamed Video.ogv"? --- VKAPI/Handlers/Wall.php | 2 +- Web/Models/Entities/Video.php | 4 ++-- Web/Presenters/CommentPresenter.php | 2 +- Web/Presenters/TopicsPresenter.php | 2 +- Web/Presenters/WallPresenter.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/VKAPI/Handlers/Wall.php b/VKAPI/Handlers/Wall.php index 41af5c0d..adddaccf 100644 --- a/VKAPI/Handlers/Wall.php +++ b/VKAPI/Handlers/Wall.php @@ -418,7 +418,7 @@ final class Wall extends VKAPIRequestHandler } if($_FILES["video"]["error"] === UPLOAD_ERR_OK) - $video = Video::fastMake($this->getUser()->getId(), $message, $_FILES["video"], $anon); + $video = Video::fastMake($this->getUser()->getId(), $_FILES["video"]["name"], $message, $_FILES["video"], $anon); } catch(\DomainException $ex) { $this->fail(-156, "The media file is corrupted"); } catch(ISE $ex) { diff --git a/Web/Models/Entities/Video.php b/Web/Models/Entities/Video.php index ee53b378..bddb00a4 100644 --- a/Web/Models/Entities/Video.php +++ b/Web/Models/Entities/Video.php @@ -195,11 +195,11 @@ class Video extends Media $this->save(); } - static function fastMake(int $owner, string $description = "", array $file, bool $unlisted = true, bool $anon = false): Video + static function fastMake(int $owner, string $name = "Unnamed Video.ogv", string $description = "", array $file, bool $unlisted = true, bool $anon = false): Video { $video = new Video; $video->setOwner($owner); - $video->setName("Unnamed Video.ogv"); + $video->setName(ovk_proc_strtr($name, 61)); $video->setDescription(ovk_proc_strtr($description, 300)); $video->setAnonymous($anon); $video->setCreated(time()); diff --git a/Web/Presenters/CommentPresenter.php b/Web/Presenters/CommentPresenter.php index 50c72248..93d2a816 100644 --- a/Web/Presenters/CommentPresenter.php +++ b/Web/Presenters/CommentPresenter.php @@ -74,7 +74,7 @@ final class CommentPresenter extends OpenVKPresenter } if($_FILES["_vid_attachment"]["error"] === UPLOAD_ERR_OK) { - $video = Video::fastMake($this->user->id, $this->postParam("text"), $_FILES["_vid_attachment"]); + $video = Video::fastMake($this->user->id, $_FILES["_vid_attachment"]["name"], $this->postParam("text"), $_FILES["_vid_attachment"]); } } catch(ISE $ex) { $this->flashFail("err", "Не удалось опубликовать комментарий", "Файл медиаконтента повреждён или слишком велик."); diff --git a/Web/Presenters/TopicsPresenter.php b/Web/Presenters/TopicsPresenter.php index 528b51ad..e081382a 100644 --- a/Web/Presenters/TopicsPresenter.php +++ b/Web/Presenters/TopicsPresenter.php @@ -105,7 +105,7 @@ final class TopicsPresenter extends OpenVKPresenter } if($_FILES["_vid_attachment"]["error"] === UPLOAD_ERR_OK) { - $video = Video::fastMake($this->user->id, $this->postParam("text"), $_FILES["_vid_attachment"]); + $video = Video::fastMake($this->user->id, $_FILES["_vid_attachment"]["name"], $this->postParam("text"), $_FILES["_vid_attachment"]); } } catch(ISE $ex) { $this->flash("err", "Не удалось опубликовать комментарий", "Файл медиаконтента повреждён или слишком велик."); diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index 928026f8..5c9326db 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -258,7 +258,7 @@ final class WallPresenter extends OpenVKPresenter } if($_FILES["_vid_attachment"]["error"] === UPLOAD_ERR_OK) - $video = Video::fastMake($this->user->id, $this->postParam("text"), $_FILES["_vid_attachment"], $anon); + $video = Video::fastMake($this->user->id, $_FILES["_vid_attachment"]["name"], $this->postParam("text"), $_FILES["_vid_attachment"], $anon); } catch(\DomainException $ex) { $this->flashFail("err", tr("failed_to_publish_post"), tr("media_file_corrupted")); } catch(ISE $ex) {