- 在 Grouping 模型和控制器中添加删除和更新方法 - 实现完整的图片上传、删除、预览和批量操作功能 - 添加图片清理功能用于删除冗余图片文件 - 实现 Markdown 文件按分组查询、搜索和标题更新功能 - 添加回收站功能支持软删除和恢复操作 - 实现系统设置和注册码生成功能 - 配置新的 API 路由包括图片、系统和回收站相关接口 - 更新前端开发服务器代理地址从 8084 到 80 端口
81 lines
2.7 KiB
PHP
81 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
use App\Models\Trash;
|
|
use App\Utils\Response as ApiResponse;
|
|
|
|
class TrashController
|
|
{
|
|
/**
|
|
* 获取回收站列表
|
|
*/
|
|
public function getTrashItems(Request $request, Response $response)
|
|
{
|
|
$model = new Trash();
|
|
$items = $model->getTrashItems();
|
|
|
|
$response->getBody()->write(ApiResponse::json(ApiResponse::success($items)));
|
|
return $response->withHeader('Content-Type', 'application/json; charset=utf-8');
|
|
}
|
|
|
|
/**
|
|
* 恢复项目
|
|
*/
|
|
public function restoreItem(Request $request, Response $response, $args)
|
|
{
|
|
$type = $args['type'];
|
|
$id = $args['id'];
|
|
|
|
try {
|
|
$model = new Trash();
|
|
$model->restoreItem($id, $type);
|
|
|
|
$response->getBody()->write(ApiResponse::json(ApiResponse::success(null, '恢复成功')));
|
|
return $response->withHeader('Content-Type', 'application/json; charset=utf-8');
|
|
} catch (\Exception $e) {
|
|
$response->getBody()->write(ApiResponse::json(ApiResponse::error('恢复失败: ' . $e->getMessage())));
|
|
return $response->withHeader('Content-Type', 'application/json; charset=utf-8')->withStatus(500);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 永久删除项目
|
|
*/
|
|
public function permanentlyDeleteItem(Request $request, Response $response, $args)
|
|
{
|
|
$type = $args['type'];
|
|
$id = $args['id'];
|
|
|
|
try {
|
|
$model = new Trash();
|
|
$model->permanentlyDeleteItem($id, $type);
|
|
|
|
$response->getBody()->write(ApiResponse::json(ApiResponse::success(null, '永久删除成功')));
|
|
return $response->withHeader('Content-Type', 'application/json; charset=utf-8');
|
|
} catch (\Exception $e) {
|
|
$response->getBody()->write(ApiResponse::json(ApiResponse::error('删除失败: ' . $e->getMessage())));
|
|
return $response->withHeader('Content-Type', 'application/json; charset=utf-8')->withStatus(500);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 清空回收站
|
|
*/
|
|
public function cleanTrash(Request $request, Response $response)
|
|
{
|
|
try {
|
|
$model = new Trash();
|
|
$model->cleanTrash();
|
|
|
|
$response->getBody()->write(ApiResponse::json(ApiResponse::success(null, '清空成功')));
|
|
return $response->withHeader('Content-Type', 'application/json; charset=utf-8');
|
|
} catch (\Exception $e) {
|
|
$response->getBody()->write(ApiResponse::json(ApiResponse::error('清空失败: ' . $e->getMessage())));
|
|
return $response->withHeader('Content-Type', 'application/json; charset=utf-8')->withStatus(500);
|
|
}
|
|
}
|
|
}
|