<?php

namespace app\controller\api;

use app\extra\basic\Base;
use app\extra\tools\UploadExtend;
use app\middleware\WxMiddleware;
use LinFly\Annotation\Route\Controller;
use LinFly\Annotation\Route\Route;
use support\Request;
use support\Response;
use LinFly\Annotation\Route\Middleware;

#[Controller(prefix: "/wx_api/upload"),Middleware(WxMiddleware::class)]
class Uploads extends Base
{


    /**
     * 上传文件
     * @param Request $request
     * @return Response
     */
    #[Route(path: "data",methods: "post")]
    public function uploadData(Request $request): Response
    {
        try {
            $resp = UploadExtend::uploadFile();
            if (!isset($resp[0]['url'])) return errorTrans("error.upload");
            return successTrans("success.data",[
                "fileName"  => $resp[0]['origin_name'],
                "src"       => $resp[0]['url'],
            ],200);
        } catch (\Throwable $th) {
            return error($th->getMessage());
        }
    }

}