/** * Fetch a mod in JSON format from its ID. * * @api * * @return json */ public function getMod($id) { try { $mod = Mod::find($id); return Response::json($mod->toArray()); } catch (Exception $e) { return Response::json(['error' => $e->getMessage()]); } }
public function getContact() { $correction_type = false; $correction_id = false; $correction_object = false; $input = Input::only('modpack', 'mod'); if ($input['modpack']) { $correction_type = 'Modpack'; $correction_id = $input['modpack']; $correction_object = Modpack::find($correction_id); } if ($input['mod']) { $correction_type = 'Mod'; $correction_id = $input['mod']; $correction_object = Mod::find($correction_id); } $title = 'Contact Us - ' . $this->site_name; $meta_description = 'Contact us if something is incorrect, if you have a question, or for anything else.'; return View::make('pages.contact', ['title' => $title, 'meta_description' => $meta_description, 'correction_type' => $correction_type, 'correction_id' => $correction_id, 'correction_object' => $correction_object]); }
public function getMod($id) { $modpacks = []; $raw_mod = Mod::find($id); if (!$raw_mod) { return Response::json(['error' => 'No mod with that ID found.']); } $raw_modpacks = $raw_mod->modpacks; foreach ($raw_modpacks as $modpack) { $modpacks[] = ['id' => $modpack->id, 'name' => $modpack->name, 'short_description' => $modpack->deck, 'website' => $modpack->website, 'download_link' => $modpack->download_link, 'donate_link' => $modpack->website, 'wiki_link' => $modpack->wiki_link, 'descriptions' => $modpack->descriptions, 'slug' => $modpack->slug, 'created_at' => $modpack->created_at, 'updated_at' => $modpack->updated_at]; } $result = ['id' => $raw_mod->id, 'name' => $raw_mod->name, 'short_description' => $raw_mod->deck, 'website' => $raw_mod->website, 'download_link' => $raw_mod->download_link, 'donate_link' => $raw_mod->website, 'wiki_link' => $raw_mod->wiki_link, 'descriptions' => $raw_mod->descriptions, 'modpacks' => $modpacks, 'slug' => $raw_mod->slug, 'created_at' => $raw_mod->created_at, 'updated_at' => $raw_mod->updated_at]; return Response::json($result); }
public function action_addversion() { $mod_id = Input::get('mod-id'); $version = Input::get('add-version'); if (empty($mod_id) || empty($version)) { return Response::json(array('status' => 'error', 'reason' => 'Missing Post Data')); } $mod = Mod::find($mod_id); if (empty($mod)) { return Response::json(array('status' => 'error', 'reason' => 'Could not pull mod from database')); } $ver = new ModVersion(); $ver->mod_id = $mod->id; $ver->version = $version; if ($md5 = $this->mod_md5($mod, $version)) { $ver->md5 = $md5; $ver->save(); return Response::json(array('status' => 'success', 'version' => $ver->version, 'md5' => $ver->md5)); } else { return Response::json(array('status' => 'error', 'reason' => 'Could not get MD5. URL Incorrect?')); } }
public function testModVersion() { $mod = Mod::find(1); $modversion = $mod->versions->first(); $response = $this->call('GET', 'api/mod/' . $mod->name . '/' . $modversion->version); $this->assertResponseOk(); $this->assertTrue(is_a($response, 'Illuminate\\Http\\JsonResponse')); $json = $response->getData(true); $this->assertTrue(array_key_exists('md5', $json)); $this->assertTrue(array_key_exists('url', $json)); }
public function testModDeleteGet() { $mod = Mod::find(1); $this->call('GET', '/mod/delete/' . $mod->id); $this->assertResponseOk(); }
public function postEdit($id) { $selected_versions = []; $selected_authors = []; $selected_maintainers = []; $minecraft_versions = MinecraftVersion::all(); $title = 'Edit A Mod - ' . $this->site_name; $can_edit_maintainers = false; $mod = Mod::find($id); if (Auth::check()) { $maintainer = $mod->maintainers()->where('user_id', Auth::id())->first(); if (!$maintainer) { if ($this->checkRoute()) { $can_edit_maintainers = true; } else { return Redirect::route('index'); } } } else { return Redirect::route('index'); } $authors = $mod->authors; $versions = $mod->versions; $maintainers = $mod->maintainers; $input = Input::only('name', 'selected_versions', 'selected_authors', 'selected_maintainers', 'deck', 'website', 'download_link', 'donate_link', 'wiki_link', 'description', 'slug', 'mod_list_hide'); $messages = ['unique' => 'This mod already exists in the database. If it requires an update let us know!', 'url' => 'The :attribute field is not a valid URL.']; $validator = Validator::make($input, ['name' => 'required|unique:mods,name,' . $mod->id, 'selected_authors' => 'required', 'selected_versions' => 'required', 'deck' => 'required', 'website' => 'url', 'download_url' => 'url', 'wiki_url' => 'url', 'donate_link' => 'url'], $messages); if ($validator->fails()) { return Redirect::action('ModController@getEdit', [$mod->id])->withErrors($validator)->withInput(); } $mod->name = $input['name']; $mod->deck = $input['deck']; $mod->website = $input['website']; $mod->download_link = $input['download_link']; $mod->donate_link = $input['donate_link']; $mod->wiki_link = $input['wiki_link']; $mod->description = $input['description']; if ($can_edit_maintainers) { if ($input['slug'] == '' || $input['slug'] == $mod->slug) { $slug = Str::slug($input['name']); } else { $slug = $input['slug']; } $mod->slug = $slug; if ($input['mod_list_hide'] == 1) { $mod->mod_list_hide = 1; } else { $mod->mod_list_hide = 0; } } $mod->last_ip = Request::getClientIp(); $success = $mod->save(); if ($success) { foreach ($authors as $a) { $mod->authors()->detach($a->id); } $mod->authors()->attach($input['selected_authors']); foreach ($versions as $v) { $mod->versions()->detach($v->id); } $mod->versions()->attach($input['selected_versions']); if ($can_edit_maintainers) { foreach ($maintainers as $m) { $mod->maintainers()->detach($m->id); } if ($input['selected_maintainers']) { $mod->maintainers()->attach($input['selected_maintainers']); } } $updated_mod = Mod::find($mod->id); foreach ($updated_mod->versions as $v) { $selected_versions[] = $v->name; } foreach ($updated_mod->authors as $a) { $selected_authors[] = $a->id; } foreach ($updated_mod->maintainers as $m) { $selected_maintainers[] = $m->id; } Cache::tags('mods')->flush(); Queue::push('BuildCache'); return View::make('mods.edit', ['title' => $title, 'mod' => $mod, 'chosen' => true, 'success' => true, 'selected_versions' => $selected_versions, 'selected_authors' => $selected_authors, 'selected_maintainers' => $selected_maintainers, 'versions' => $minecraft_versions, 'can_edit_maintainers' => $can_edit_maintainers]); } return Redirect::action('ModController@getEdit', [$mod->id])->withErrors(['message' => 'Unable to edit mod.'])->withInput(); }
public function anyAddVersion() { if (Request::ajax()) { $mod_id = Input::get('mod-id'); $md5 = Input::get('add-md5'); $version = Input::get('add-version'); if (empty($mod_id) || empty($version)) { return Response::json(array('status' => 'error', 'reason' => 'Missing Post Data')); } $mod = Mod::find($mod_id); if (empty($mod)) { return Response::json(array('status' => 'error', 'reason' => 'Could not pull mod from database')); } if (empty($md5)) { $file_md5 = $this->mod_md5($mod, $version); if ($file_md5['success']) { $md5 = $file_md5['md5']; } } else { $file_md5 = $this->mod_md5($mod, $version); $pfile_md5 = !$file_md5['success'] ? "Null" : $file_md5['md5']; } $ver = new Modversion(); $ver->mod_id = $mod->id; $ver->version = $version; if ($file_md5['success'] && !empty($md5)) { if ($md5 == $file_md5['md5']) { $ver->filesize = $file_md5['filesize']; $ver->md5 = $md5; $ver->save(); return Response::json(array('status' => 'success', 'version' => $ver->version, 'md5' => $ver->md5, 'filesize' => $ver->humanFilesize("MB"))); } else { $ver->filesize = $file_md5['filesize']; $ver->md5 = $md5; $ver->save(); return Response::json(array('status' => 'warning', 'version' => $ver->version, 'md5' => $ver->md5, 'filesize' => $ver->humanFilesize("MB"), 'reason' => 'MD5 provided does not match file MD5: ' . $pfile_md5)); } } else { return Response::json(array('status' => 'error', 'reason' => 'Remote MD5 failed. ' . $file_md5['message'])); } } return Response::view('errors.missing', array(), 404); }
public function anyAddVersion() { if (Request::ajax()) { $mod_id = Input::get('mod-id'); $md5 = Input::get('add-md5'); $version = Input::get('add-version'); if (empty($mod_id) || empty($version)) { return Response::json(array('status' => 'error', 'reason' => 'Missing Post Data')); } $mod = Mod::find($mod_id); if (empty($mod)) { return Response::json(array('status' => 'error', 'reason' => 'Could not pull mod from database')); } if (empty($md5)) { $file_md5 = $this->mod_md5($mod, $version); $md5 = $file_md5; } else { $file_md5 = $this->mod_md5($mod, $version); $pfile_md5 = empty($file_md5) ? "Null" : $file_md5; } $ver = new Modversion(); $ver->mod_id = $mod->id; $ver->md5 = $md5; $ver->version = $version; if ($md5 == $file_md5 && !empty($md5)) { $ver->md5 = $md5; $ver->save(); return Response::json(array('status' => 'success', 'version' => $ver->version, 'md5' => $ver->md5)); } else { if ($md5 != $file_md5 && !empty($md5)) { $ver->md5 = $md5; $ver->save(); return Response::json(array('status' => 'warning', 'version' => $ver->version, 'md5' => $ver->md5, 'reason' => 'MD5 provided does not match file MD5: ' . $pfile_md5)); } else { return Response::json(array('status' => 'error', 'reason' => 'Remote MD5 failed. See app/storage/logs for more details')); } } } return Response::view('errors.missing', array(), 404); }