<?php

namespace App\Http\Controllers\Api\Client;

use App\Model\QiniuModel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use Qiniu\Auth;

class MediaController extends Controller
{
    private $bucketList = [
        'develop'  => 'dev-offcncloud',
        'test'     => 'test-offcncloud',
        'master'   => 'offcncloud',
    ];

    /**
     * 获取媒资ID
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ControllerException
     */
    public function getMediaNum(Request $request){

        $result = handler_drive(function () use ($request) {
            return ["mediaID" => date('YmdHis',time()).generateRandomNum(8)];
        });
        return success($result);
    }

    /**
     * 获取上传媒资token
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ControllerException
     */
    public function getUploadMediaToken(Request $request){

        $result = handler_drive(function () use ($request) {
            $branch = empty(getenv('branch')) ? 'test' : getenv('branch');

            $token = QiniuModel::uploadToken($this->bucketList[$branch]);

            return ["token" => $token];
        });
        return success($result);

    }






}
