disk($disk); } $disk = $disks[$disk]; if ($deadline === true) { $deadline = Carbon::today()->addDay(3)->addHour(1)->timestamp; } elseif ($deadline !== false) { $deadline = Time::parse($deadline)->timestamp; } if ($deadline) { $symbol = strpos($uri, '?') ? '&' : '?'; $uri = trim($uri, '/') . $symbol . 'timestamp=' . $deadline; } return $disk->url($uri); } } if (! function_exists('account_avatar')) { /** * 单次获取账户头像 * * @param int $accountId * @param int $deadline * @param bool $size * @return string */ function account_avatar($accountId, $deadline = true, $size = 64) { $path = cdn('data', \App\Domains\Account\Services\AccountService::generateAvatarPath($accountId), $deadline, $size); return $path; } } if (! function_exists('save_cover')) { /** * 保存封面 * * @param string $type * @param int $id * @param UploadedFile $file * @return void */ function save_cover($type, $id, $file) { if ($file instanceof UploadedFile && !$file->isValid()) { throw new \App\Exceptions\InvalidArgumentException('文件不正确或已损坏'); } if (!in_array($file->guessExtension(), ['jpg', 'jpeg', 'gif', 'png', 'bmp'])) { throw new \App\Exceptions\InvalidArgumentException('只支持jpg,jpeg,gif,png,bmp文件格式'); } $filename = "/$type/$id.jpg"; Event::fire(new FileUploadEvent($file, [ 'filename' => $filename, 'type' => $type, 'typeid' => $id, 'cover' => true, ], $disk = 'data')); $url = cdn('data', $filename, time()); return $url; } } if (! function_exists('get_cover')) { /** * 保存封面 * * @param string $type * @param int $id * @param UploadedFile $file * @return void */ function get_cover($type, $id, $deadline = true, $size = '640') { $filename = "/$type/$id.jpg"; $path = cdn('data', $filename, $deadline, $size); return $path; } } if (! function_exists('config_path')) { /** * Get the configuration path. * * @param string $path * @return string */ function config_path($path = '') { $path = 'config' . DIRECTORY_SEPARATOR . ($path ? DIRECTORY_SEPARATOR.$path : $path); return base_path($path); } }