hyperfk8s/app/Logic/Admin/UploadLogic.php

84 lines
2.0 KiB
PHP
Executable File

<?php
//
//declare(strict_types=1);
///**
// * This file is part of the youyao/admin-api.
// *
// * (c) youyao <info@nuancebiotech.cn>
// * This source file is subject to the license under the project that is bundled.
// */
//namespace App\Logic\Admin;
//
//use App\Exception\BusinessException;
//use App\Model\User;
//use App\Repository\Admin\UserRepository;
//use Hyperf\Contract\ConfigInterface;
//use Hyperf\Di\Annotation\Inject;
//use Hyperf\HttpMessage\Upload\UploadedFile;
//use League\Flysystem\Filesystem;
//use Ramsey\Uuid\Uuid;
//
//class UploadLogic
//{
// /**
// * @Inject
// * @var Filesystem
// */
// private $filesystem;
//
// /**
// * @Inject
// * @var ConfigInterface
// */
// private $config;
//
// /**
// * @Inject
// * @var UserRepository
// */
// private $user;
//
// public function uploadAvatar(UploadedFile $file)
// {
// if (! $file->isValid()) {
// throw new BusinessException('文件无效');
// }
//
// $stream = fopen($file->getRealPath(), 'r+');
//
// $fileName = $this->getFileName($file);
// $this->filesystem->writeStream('uploads/' . $fileName, $stream);
//
// if (! fclose($stream)) {
// throw new BusinessException('上传失败,请稍后重试');
// }
//
// return $this->config->get('server.domain') . $fileName;
// }
//
// public function uploadUpdateAvatar(User $user, UploadedFile $file)
// {
// $url = $this->uploadAvatar($file);
//
// if (! $this->user->updateAvatar($user->id, $url)) {
// throw new BusinessException('更新失败,请稍后重试');
// }
//
// return $url;
// }
//
// private function getFileName(UploadedFile $file)
// {
// return 'avatar/' . Uuid::uuid4()->toString() . '.' . $this->getExtension($file->getExtension());
// }
//
// private function getExtension($extension)
// {
// if ($extension === 'blob') {
// return 'jpg';
// }
//
// return $extension;
// }
//}