<?php

namespace App\Http\Controllers\Admin;

use App\Models\CollectMedia;
use Illuminate\Http\Request;
use App\Services\Oss\UploadManager;

class FileuploadController extends AdminController
{

    public function __construct()
    {
        // 
    }

    // 文件上传
    public function upload(Request $request, UploadManager $up)
    {
        $result = $up->upload($request);
        
        return response()->json($result);
    }

    // 百度编辑器文件上传
    public function ueditor(Request $request, UploadManager $up)
    {
        $result = $up->ueditor($request); 
        
        return response()->json($result); 
    }

    // 媒体库上传
    public function mediaUpload(Request $request, UploadManager $up)
    {
        $result = $up->upload($request);

        if ($result['state'] == 'SUCCESS') {
            CollectMedia::create(['path' => $result['path']]);
        }

        return response()->json($result);
    }
}
