Exemplo n.º 1
0
 public function getLink($imageId)
 {
     if (!Auth::user()->check()) {
         return ['status' => 'error'];
     }
     $detailId = Input::has('img') ? Input::get('img') : 0;
     $image = VIImage::select('id', 'short_name', 'image_details.detail_id')->join('image_details', 'image_details.image_id', '=', 'images.id')->where('id', $imageId)->where('detail_id', $detailId)->first();
     if (!is_object($image)) {
         return ['status' => 'error'];
     }
     $rand = rand(1, rand(12, 38));
     $token = Str::random(rand(30, 55));
     $token = substr($token, 0, $rand) . md5(time() . $image->detail_id . md5($image->short_name)) . substr($token, $rand);
     Download::insert(['image_id' => $image->id, 'user_id' => Auth::user()->get()->id, 'image_detail_id' => $image->detail_id, 'token' => $token]);
     return ['status' => 'ok', 'url' => URL . '/d/' . $image->id . '/' . $token . '/' . $image->short_name . '.jpg'];
 }