1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-20 19:07:03 +08:00
xiaochong0302 00cb8bf963 1.拆解migration创建表脚本
2.增加post方式传递csrf_token
3.优化storage上传
2024-02-26 09:56:51 +08:00

71 lines
1.5 KiB
PHP

<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace App\Http\Home\Controllers;
use App\Services\MyStorage as StorageService;
use App\Validators\Validator as AppValidator;
/**
* @RoutePrefix("/upload")
*/
class UploadController extends Controller
{
public function initialize()
{
$authUser = $this->getAuthUser();
$validator = new AppValidator();
$validator->checkAuthUser($authUser->id);
}
/**
* @Post("/avatar/img", name="home.upload.avatar_img")
*/
public function uploadAvatarImageAction()
{
$service = new StorageService();
$file = $service->uploadAvatarImage();
if (!$file) {
return $this->jsonError(['msg' => '上传文件失败']);
}
$data = [
'url' => $service->getImageUrl($file->path),
'title' => $file->name,
];
return $this->jsonSuccess(['data' => $data]);
}
/**
* @Post("/editor/img", name="home.upload.editor_img")
*/
public function uploadEditorImageAction()
{
$service = new StorageService();
$file = $service->uploadContentImage();
if (!$file) {
return $this->jsonError([
'message' => '上传图片失败',
'error' => 1,
]);
}
return $this->jsonSuccess([
'url' => $service->getImageUrl($file->path),
'error' => 0,
]);
}
}