<?php


namespace App\Http\Controllers\Api\User;


use App\Http\Controllers\Controller;
use App\Service\AdminConfigService;
use App\Service\OssService;
use Illuminate\Http\Request;

class ConfigController extends Controller
{
    /**
     * 获取配置
     *
     * @param Request $request
     * @return mixed
     */
    public function show(Request $request)
    {
        $type = $request->input('type', 1);
        $user = $request->user();
        $result = app(AdminConfigService::class)->getAdminConfig($user->admin_users_id, $type);
        return $this->success('success', $result);
    }

    /**
     * 上传策略
     *
     * @param \Illuminate\Http\Request $request
     * @return mixed
     */
    public function policy(Request $request)
    {
        $user = $request->user();
        $module = $request->input('module', 'user');
        # 区分图片上传路径和视频上传路径
        # 10M
        $size = 1024 * 1024 * 5;
        $module = 'ai_avatar';
        $ossConfig = app(AdminConfigService::class)->getAdminUserOssConfig();
        $result = (new OssService($ossConfig))->policy('files/' . $module . '/' . 'admin' . '/', $size);
        return $this->success('success', $result);
    }
}
