Permalink
Browse files

First version of Downloadpage. Also added a migration to fill the dat…

…abase with the correct tables. Cleanup.
  • Loading branch information...
1 parent 9898ad3 commit 1fa34a45d67dbc45847eb6fdd17beba97f2d2e80 @runelaenen runelaenen committed Jan 20, 2016
View
@@ -0,0 +1,26 @@
+<?php
+
+namespace App;
+
+class Helpers
+{
+ /**
+ * Format bytes to kb, mb, gb, tb
+ *
+ * @param integer $size
+ * @param integer $precision
+ * @return integer
+ */
+ public static function formatBytes($size, $precision = 2)
+ {
+ if ($size > 0) {
+ $size = (int) $size;
+ $base = log($size) / log(1024);
+ $suffixes = array(' bytes', ' KB', ' MB', ' GB', ' TB');
+
+ return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
+ } else {
+ return $size;
+ }
+ }
+}
@@ -0,0 +1,91 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+
+use DB;
+use App\Http\Requests;
+use App\Http\Controllers\Controller;
+
+class DownloadController extends Controller
+{
+ /**
+ * Displays the main downloads page, or returns json.
+ *
+ * @param \Illuminate\Http\Request $request
+ * @return \Illuminate\Http\Response
+ */
+ public function index(Request $request)
+ {
+ //
+ $downloads = DB::table('downloads')
+ ->join('downloadsBuilds', function ($join) {
+ $join->on('downloadsBuilds.parentDownloadId', '=', 'downloads.downloadId')
+ ->where('downloadsBuilds.flavourId', '=', 1);
+ })
+ ->select('downloads.*', "downloadsBuilds.status")
+ ->orderBy('downloadId', 'desc')
+ ->take(25)
+ ->get();
+
+ $latest['stable'] = DB::table('downloads')
+ ->where('gitBranch', 'master')
+ ->orderBy('downloadId', 'desc')
+ ->first()
+ ->version;
+
+ $latest['develop'] = DB::table('downloads')
+ ->where('gitBranch', 'develop')
+ ->orderBy('downloadId', 'desc')
+ ->first()
+ ->version;
+
+ if ($request->wantsJson()) {
+ return $downloads;
+ }
+ return view('download.index', ['downloads' => $downloads, 'latest' => $latest]);
+ }
+
+ /**
+ * Displays the download page, or returns json of a specific downloadId.
+ *
+ * @param int $downloadId
+ * @param \Illuminate\Http\Request $request
+ * @return \Illuminate\Http\Response
+ */
+ public function show(int $downloadId, Request $request)
+ {
+ $download = DB::table('downloads')
+ ->join('downloadsBuilds', function ($join) {
+ $join->on('downloadsBuilds.parentDownloadId', '=', 'downloads.downloadId')
+ ->where('downloadsBuilds.flavourId', '=', 1);
+ })
+ ->select('downloads.*', "downloadsBuilds.status")
+ ->where('downloadId', $downloadId)
+ ->orderBy('downloadId', 'desc')
+ ->first();
+
+
+ /* $downloadsBuilds = DB::table('downloadsBuilds')
+ ->where('downloadsBuilds.parentDownloadId', $downloadId)
+ ->join('downloadFlavours', 'downloadFlavours.flavourId', '=', 'downloadsBuilds.flavourId')
+ ->select('downloadBuilds.*', 'downloadFlavours.title');
+
+ //TODO: Convert to querybuilder... Couldn't get it to work so I wrote a manual query
+ */
+ $downloadsBuilds = DB::select('SELECT filePath, fileName, fileSize, fileHash, title as flavourName
+ FROM downloadsBuilds b
+ JOIN downloadFlavours f ON (f.flavourId = b.flavourId)
+ WHERE parentDownloadId = :id', ['id' => $downloadId]);
+
+ if ($request->wantsJson()) {
+ //TODO: return nice json stuff
+ return null;
+ }
+ return view('download.download', ['download' => $download,
+ 'downloadsBuilds' => $downloadsBuilds,
+ 'commits' => json_decode($download->commits, TRUE),
+ 'serverURL' => 'http://cdn.limetric.com/games/openrct2/']);
+ }
+}
View
@@ -18,3 +18,5 @@
Route::get('/features', function () {
return view('features');
});
+
+Route::resource('download', 'DownloadController');
View
@@ -166,6 +166,7 @@
'Blade' => Illuminate\Support\Facades\Blade::class,
'Bus' => Illuminate\Support\Facades\Bus::class,
'Cache' => Illuminate\Support\Facades\Cache::class,
+ 'Carbon' => Carbon\Carbon::class,
'Config' => Illuminate\Support\Facades\Config::class,
'Cookie' => Illuminate\Support\Facades\Cookie::class,
'Crypt' => Illuminate\Support\Facades\Crypt::class,
@@ -175,6 +176,7 @@
'File' => Illuminate\Support\Facades\File::class,
'Gate' => Illuminate\Support\Facades\Gate::class,
'Hash' => Illuminate\Support\Facades\Hash::class,
+ 'Helpers' => App\Helpers::class,
'Input' => Illuminate\Support\Facades\Input::class,
'Lang' => Illuminate\Support\Facades\Lang::class,
'Log' => Illuminate\Support\Facades\Log::class,
View
@@ -26,7 +26,7 @@
|
*/
- 'default' => env('DB_CONNECTION', 'sqlite'),
+ 'default' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
@@ -54,10 +54,10 @@
'mysql' => [
'driver' => 'mysql',
- 'host' => env('DB_HOST', 'localhost'),
- 'database' => env('DB_DATABASE', 'forge'),
- 'username' => env('DB_USERNAME', 'forge'),
- 'password' => env('DB_PASSWORD', ''),
+ 'host' => env('DB_HOST', 'laenen.nu'),
+ 'database' => env('DB_DATABASE', 'admin_oporg'),
+ 'username' => env('DB_USERNAME', 'admin_oporg'),
+ 'password' => env('DB_PASSWORD', 'oporg2'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
@@ -1,34 +0,0 @@
-<?php
-
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Database\Migrations\Migration;
-
-class CreateUsersTable extends Migration
-{
- /**
- * Run the migrations.
- *
- * @return void
- */
- public function up()
- {
- Schema::create('users', function (Blueprint $table) {
- $table->increments('id');
- $table->string('name');
- $table->string('email')->unique();
- $table->string('password', 60);
- $table->rememberToken();
- $table->timestamps();
- });
- }
-
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- Schema::drop('users');
- }
-}
@@ -3,7 +3,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
-class CreatePasswordResetsTable extends Migration
+class CreateDownloadsTables extends Migration
{
/**
* Run the migrations.
@@ -12,11 +12,8 @@ class CreatePasswordResetsTable extends Migration
*/
public function up()
{
- Schema::create('password_resets', function (Blueprint $table) {
- $table->string('email')->index();
- $table->string('token')->index();
- $table->timestamp('created_at');
- });
+ //
+ DB::unprepared(file_get_contents('dump.sql'));
}
/**
@@ -26,6 +23,6 @@ public function up()
*/
public function down()
{
- Schema::drop('password_resets');
+ //
}
}
View
@@ -0,0 +1,88 @@
+SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
+SET time_zone = "+00:00";
+
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8mb4 */;
+
+--
+-- Structure `downloadFlavours`
+--
+
+CREATE TABLE `downloadFlavours` (
+ `flavourId` int(11) UNSIGNED NOT NULL,
+ `platform` enum('linux','macosx','windows') CHARACTER SET utf8 NOT NULL,
+ `architecture` enum('x86','x86-64') CHARACTER SET utf8 NOT NULL,
+ `identifier` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
+ `title` varchar(100) CHARACTER SET utf8 NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+--
+-- Content `downloadFlavours`
+--
+
+INSERT INTO `downloadFlavours` (`flavourId`, `platform`, `architecture`, `identifier`, `title`) VALUES
+(1, 'windows', 'x86', 'portable', 'Portable ZIP'),
+(2, 'windows', 'x86', 'installer', 'Installer'),
+(3, 'linux', 'x86', '', ''),
+(4, 'macosx', 'x86', '', ''),
+(99, 'linux', 'x86', 'janisozaur-test', 'Janisozaur Test');
+
+-- --------------------------------------------------------
+
+--
+-- Structure `downloads`
+--
+
+CREATE TABLE `downloads` (
+ `downloadId` int(11) UNSIGNED NOT NULL,
+ `version` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
+ `gitHash` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
+ `gitBranch` enum('master','develop') COLLATE utf8mb4_unicode_ci NOT NULL,
+ `addedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `commits` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+-- --------------------------------------------------------
+
+--
+-- Structure `downloadsBuilds`
+--
+
+CREATE TABLE `downloadsBuilds` (
+ `buildId` int(11) UNSIGNED NOT NULL,
+ `parentDownloadId` int(11) NOT NULL,
+ `flavourId` int(11) NOT NULL,
+ `status` enum('unknown','success','failed') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'unknown',
+ `filePath` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
+ `fileName` varchar(250) COLLATE utf8mb4_unicode_ci NOT NULL,
+ `fileSize` int(11) UNSIGNED NOT NULL,
+ `fileHash` varchar(250) COLLATE utf8mb4_unicode_ci NOT NULL,
+ `addedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `buildLog` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
+ `publisherKey` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+ALTER TABLE `downloadFlavours`
+ ADD PRIMARY KEY (`flavourId`);
+
+ALTER TABLE `downloads`
+ ADD PRIMARY KEY (`downloadId`),
+ ADD UNIQUE KEY `gitHash` (`gitHash`,`gitBranch`);
+
+ALTER TABLE `downloadsBuilds`
+ ADD PRIMARY KEY (`buildId`);
+
+ALTER TABLE `downloadFlavours`
+ MODIFY `flavourId` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
+
+ALTER TABLE `downloads`
+ MODIFY `downloadId` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=14;
+
+ALTER TABLE `downloadsBuilds`
+ MODIFY `buildId` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=33;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Oops, something went wrong.

0 comments on commit 1fa34a4

Please sign in to comment.