getCacheKey()), 'Request ID are not allowed to be duplicated'); $this->start(); } public function increment(int $size): void { $this->uploadedSize += $size; Cache::put($this->getCacheKey(), $this->query(), now()->addHours(6)); } public function start() { Cache::put($this->getCacheKey(), 0, now()->addMinutes(30)); } public function completed() { Cache::put($this->getCacheKey(), 100.00, now()->addMinutes(30)); } public function query(): float { return intval(($this->uploadedSize / $this->totalSize) * 100); } protected function getCacheKey() { return sprintf("%s:%s:%s", self::CACHE_PREFIX, Auth::id(), $this->requestId); } /** * @param string $uuid * @return array */ #[ArrayShape(['status' => "string", 'progress' => "mixed"])] public static function queryByRequestId(string $uuid): array { $progress = Cache::get(sprintf("%s:%s:%s", self::CACHE_PREFIX, Auth::id(), $uuid)); $status = "none"; if (is_numeric($progress)) { if ($progress == 100) { $status = "completed"; } else { $status = "uploading"; } } return [ 'status' => $status, 'progress' => $progress ?: 0 ]; } }