112 lines
2.9 KiB
PHP
112 lines
2.9 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Api;
|
||
|
|
|
||
|
|
use App\BaseApp\BaseController;
|
||
|
|
use App\Service\common\UtilsService;
|
||
|
|
use App\Service\MaterialService;
|
||
|
|
use Exception;
|
||
|
|
use Illuminate\Http\JsonResponse;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 素材库
|
||
|
|
*
|
||
|
|
* 素材记录只有两个来源:上传接口写入、从 OSS 反向同步补录,
|
||
|
|
* 所以没有「手工新增」,也不需要下拉选项 —— 把继承来的 create / option 排掉。
|
||
|
|
*/
|
||
|
|
class MaterialController extends BaseController
|
||
|
|
{
|
||
|
|
protected array $exceptRoute = ['create', 'option'];
|
||
|
|
|
||
|
|
public function __construct()
|
||
|
|
{
|
||
|
|
parent::__construct();
|
||
|
|
$this->service = MaterialService::getInstance();
|
||
|
|
// 只放行素材名与文件夹:对象键、体积、哈希都是同步结果,不接受手工改
|
||
|
|
$this->updateField = ['id', 'name', 'folder_id'];
|
||
|
|
$this->notRequest = ['name', 'folder_id'];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 素材概览统计
|
||
|
|
*
|
||
|
|
* @Method GET
|
||
|
|
* @throws Exception
|
||
|
|
*/
|
||
|
|
public function stat(): JsonResponse
|
||
|
|
{
|
||
|
|
return jok($this->service->stat(), '统计获取成功');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 从 OSS 增量同步对象
|
||
|
|
*
|
||
|
|
* @Method POST
|
||
|
|
* @throws Exception
|
||
|
|
*/
|
||
|
|
public function syncFromOss(): JsonResponse
|
||
|
|
{
|
||
|
|
$this->insertField = ['oss_config_id'];
|
||
|
|
$this->notRequest = ['prefix', 'marker', 'limit'];
|
||
|
|
$params = $this->checkRequiredFields(request()->post());
|
||
|
|
return jok($this->service->syncFromOss($params), '同步完成');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 全库引用扫描
|
||
|
|
*
|
||
|
|
* @Method POST
|
||
|
|
* @throws Exception
|
||
|
|
*/
|
||
|
|
public function scanReferences(): JsonResponse
|
||
|
|
{
|
||
|
|
// 表多、正文长时会跑几十秒,先把执行时限和内存放开
|
||
|
|
cc_set_time_limit();
|
||
|
|
return jok($this->service->scanReferences(request()->post()), '扫描完成');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 无引用素材清单
|
||
|
|
*
|
||
|
|
* @Method GET
|
||
|
|
* @throws Exception
|
||
|
|
*/
|
||
|
|
public function unusedList(): JsonResponse
|
||
|
|
{
|
||
|
|
return jok($this->service->unusedList(request()->query()), '列表获取成功');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 回收:删远端对象并软删记录
|
||
|
|
*
|
||
|
|
* @Method POST
|
||
|
|
* @throws Exception
|
||
|
|
*/
|
||
|
|
public function reclaim(): JsonResponse
|
||
|
|
{
|
||
|
|
$ids = request()->post('ids');
|
||
|
|
if (empty($ids) || !is_array($ids)) {
|
||
|
|
UtilsService::getInstance()->notFound('参数错误');
|
||
|
|
}
|
||
|
|
return jok($this->service->reclaim($ids), '回收完成');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 批量移动到文件夹
|
||
|
|
*
|
||
|
|
* @Method POST
|
||
|
|
* @throws Exception
|
||
|
|
*/
|
||
|
|
public function moveToFolder(): JsonResponse
|
||
|
|
{
|
||
|
|
$ids = request()->post('ids');
|
||
|
|
if (empty($ids) || !is_array($ids)) {
|
||
|
|
UtilsService::getInstance()->notFound('参数错误');
|
||
|
|
}
|
||
|
|
return jok(
|
||
|
|
$this->service->moveToFolder($ids, (int) request()->post('folder_id', 0)),
|
||
|
|
'移动成功'
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|