/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $device = Device::current(); if (Input::hasFile('file')) { $inputFile = Input::file('file'); $package = Package::createFromInputFile($inputFile, $device->user_id); } else { $package = Package::findOrFailFromArg(Input::get('package'), $device->user_id); } $ids = explode(',', Input::get('devices')); if (count($ids) == 1 && !is_numeric($ids[0])) { $token = Token::whereValue($ids[0])->valid()->first(); if ($token) { $devices = Device::whereId($token->owner)->get(); } else { return Response::error(trans('errors.expired_device_qrcode') . $ids[0], 400); } } if (empty($devices)) { $devices = Device::whereIn('id', $ids)->where(function ($query) use($device) { $query->whereUserId($device->user_id)->orWhere(function ($query) use($device) { $authed_device_ids = DUAuth::whereUserId($device->user_id)->lists('device_id'); $query->whereIn('id', $authed_device_ids); }); })->get(); } try { $push = Push::send($devices, $package, $device->user_id); return Response::json($push); } catch (\Exception $e) { return Response::exception($e); } }
/** * 上传 * @return \Illuminate\Http\JsonResponse */ public function postUpload() { $inputFile = Input::file('file'); try { $package = Package::createFromInputFile($inputFile, Auth::id()); return Response::json($package); } catch (Exception $e) { return Response::exception($e); } // //判断是否重复 // if (!File::exists($target_path)) { // $inputFile->move($target_dir, $inputFile->getClientOriginalName()); // } // // $apk = new \ApkParser\Parser($apkFile); // $manifest = $apk->getManifest(); // $iconResourceId = $apk->getManifest()->getApplication()->getIcon(); // $resources = $apk->getResources($iconResourceId); // //TODO 判断图标大小 // $iconResource = $resources[count($resources) - 1]; // File::put($target_dir . '/' . 'icon.png', stream_get_contents($apk->getStream($iconResource))); // $package = new Package(); // //TODO 判断应用名语言 // $package->app_name = $apk->getResources($manifest->getApplication()->getLabel())[0]; // $package->version_name = $manifest->getVersionName(); // $package->version_code = $manifest->getVersionCode(); // $package->package_name = $manifest->getPackageName(); // $package->sdk_level = $manifest->getMinSdkLevel(); // $package->path = $target_path . '/' . $inputFile->getClientOriginalName(); // $package->icon = $target_path . '/icon.png'; // $package->user_id = \Auth::id(); // $package->save(); // // return Response::json($package); }