Skip to content

Commit

Permalink
add 批量 获取fileinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaBaoFa committed Oct 31, 2024
1 parent b05afb0 commit 4c06853
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/Base/Trait/DaoTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ public function listQuerySetting(?array $params, bool $isScope): Builder
* ['category', 'in', ['A', 'B', 'C']]
* ]
* ]
* ];
*/
* ];.
*/
public function handleWith(Builder $query, ?array &$params = null): Builder
{
if (isset($params['_with'])) {
Expand Down
3 changes: 1 addition & 2 deletions app/Controller/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use App\Annotation\Auth;
use App\Base\BaseController;
use App\Request\CommentRequest;
use App\Request\MessageRequest;
use App\Service\CommentService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
Expand Down Expand Up @@ -50,6 +49,6 @@ public function index(CommentRequest $request): ResponseInterface
#[PostMapping('addStar')]
public function addStar(CommentRequest $request): ResponseInterface
{
return $this->service->addStar((int)$request->input('id')) ? $this->response->success() : $this->response->fail();
return $this->service->addStar((int) $request->input('id')) ? $this->response->success() : $this->response->fail();
}
}
12 changes: 12 additions & 0 deletions app/Controller/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ public function getFilesByHash(UploadRequest $request): ResponseInterface
return $this->response->success($this->service->getFileInfoByHash($request->input('hash')) ?? []);
}

/**
* 通过HASH值获取文件.
* @throws NotFoundExceptionInterface
* @throws RedisException
* @throws ContainerExceptionInterface
*/
#[GetMapping('getFileByHashes'),Auth]
public function getFilesByHashes(UploadRequest $request): ResponseInterface
{
return $this->response->success($this->service->getFileInfoByHashes($request->input('hashes')) ?? []);
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
Expand Down
3 changes: 0 additions & 3 deletions app/Dao/CommentDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
namespace App\Dao;

use App\Base\BaseDao;
use App\Constants\AuditCode;
use App\Model\Announcement;
use App\Model\Comment;
use Hyperf\Collection\Arr;
use Hyperf\Database\Model\Builder;
Expand Down Expand Up @@ -46,7 +44,6 @@ public function handleSearch(Builder $query, array $params): Builder
fn (Builder $query, $commentableType) => $query->where('commentable_type', $commentableType)
);


$query->when(
Arr::get($params, 'created_at'),
function (Builder $query, $publishedAt) {
Expand Down
1 change: 0 additions & 1 deletion app/Dao/ExhLibTagDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function handleSearch(Builder $query, array $params): Builder
fn (Builder $query, $name) => $query->where('name', 'like', '%' . $name . '%')
);


$query->when(
Arr::get($params, 'created_at'),
function (Builder $query, $createdAt) {
Expand Down
3 changes: 2 additions & 1 deletion app/Model/ExhLibObj.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Carbon\Carbon;
use Hyperf\Database\Model\Collection;
use Hyperf\Database\Model\Relations\BelongsToMany;
use Hyperf\Database\Model\Relations\MorphMany;

use function App\Helper\user;

Expand Down Expand Up @@ -103,7 +104,7 @@ public function collectUsers(): BelongsToMany
return $this->belongsToMany(User::class, 'user_collect_obj', 'obj_id', 'user_id');
}

public function comments(): \Hyperf\Database\Model\Relations\MorphMany
public function comments(): MorphMany
{
return $this->morphMany(Comment::class, 'commentable');
}
Expand Down
1 change: 1 addition & 0 deletions app/Request/CommentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function indexRules(): array
'parent_id' => ['nullable', 'int', 'exists:comments,id'],
];
}

/**
* 字段映射名称
* return array.
Expand Down
8 changes: 8 additions & 0 deletions app/Request/UploadRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ public function getFilesByHashRules(): array
];
}

public function getFilesByHashesRules(): array
{
return [
'hashes' => 'required|array',
'hashes.*' => 'string|min:32|max:32|exists:upload_files,hash',
];
}

public function uploaderCallbackRules(): array
{
return [
Expand Down
2 changes: 1 addition & 1 deletion app/Service/AnnouncementService.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function auditIndex(array $params): array
public function info(int $id): array
{
$model = $this->find($id);
!$model && throw new BusinessException(ErrorCode::NOT_FOUND);
! $model && throw new BusinessException(ErrorCode::NOT_FOUND);
return $model->toArray();
}

Expand Down
9 changes: 9 additions & 0 deletions app/Service/FileSystemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ public function getFileInfoByHash(string $hash): array
return $file;
}

public function getFileInfoByHashes(array $hashes): array
{
$files = [];
foreach ($hashes as $hash) {
$files[] = $this->getFileInfoByHash($hash);
}
return $files;
}

#[CacheEvict(prefix: 'fileInfoByHash', value: 'fileHash_#{hash}')]
public function updateByHash(string $hash, array $data): bool
{
Expand Down
3 changes: 2 additions & 1 deletion app/Service/NewsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public function update(mixed $id, array $data): bool
public function info(int $id): array
{
$model = $this->find($id);
!$model && throw new BusinessException(ErrorCode::NOT_FOUND);
! $model && throw new BusinessException(ErrorCode::NOT_FOUND);
return $model->toArray();
}

public function handleData($data): array
{
if (! Arr::has($data, 'published_at')) {
Expand Down

0 comments on commit 4c06853

Please sign in to comment.