-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
624 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
namespace App\Http\Controllers; | ||
|
||
use App\Http\Resources\ReleaseResource; | ||
use App\Models\Release; | ||
use Illuminate\Http\Request; | ||
use Pion\Laravel\ChunkUpload\Handler\HandlerFactory; | ||
use Pion\Laravel\ChunkUpload\Receiver\FileReceiver; | ||
use Pion\Laravel\ChunkUpload\Exceptions\UploadMissingFileException; | ||
use Illuminate\Support\Facades\Storage; | ||
|
||
class ReleaseController extends Controller | ||
{ | ||
public function uploadFile(Request $request) | ||
{ | ||
// Create the file receiver | ||
$receiver = new FileReceiver("file", $request, HandlerFactory::classFromRequest($request)); | ||
|
||
// Check if the upload is success or has failed | ||
if ($receiver->isUploaded() === false) { | ||
throw new UploadMissingFileException(); | ||
} | ||
|
||
// Receive the file | ||
$save = $receiver->receive(); | ||
|
||
// Check if the upload has finished | ||
if ($save->isFinished()) { | ||
return $this->saveFile($save->getFile(), $request->input('version')); | ||
} | ||
|
||
// We are in chunk mode, lets send the current progress | ||
$handler = $save->handler(); | ||
return response()->json([ | ||
"done" => $handler->getPercentageDone(), | ||
"status" => true | ||
]); | ||
} | ||
|
||
protected function saveFile($file, $version) | ||
{ | ||
// Generate the file name | ||
$fileName = "Foody_v{$version}.apk"; | ||
|
||
$disk = Storage::disk('public'); | ||
$path = $disk->putFileAs('release', $file, $fileName); | ||
|
||
// Delete the chunked file | ||
unlink($file->getPathname()); | ||
|
||
return response()->json([ | ||
'path' => asset('storage/' . $path), | ||
'filename' => $fileName, | ||
'status' => true | ||
]); | ||
} | ||
|
||
public function latest() { | ||
$release = Release::latest()->first(); | ||
|
||
return response()->json([ | ||
'success' => true, | ||
'status' => 'success', | ||
'data' => new ReleaseResource($release) | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class ReleaseResource extends JsonResource | ||
{ | ||
/** | ||
* Transform the resource into an array. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(Request $request): array | ||
{ | ||
return [ | ||
"id" => $this->id, | ||
"version" => $this->version, | ||
"url" => $this->url, | ||
"changelog" => $this->changelog, | ||
"release_date" => $this->created_at->format('Y-m-d') | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Concerns\HasUuids; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Release extends Model | ||
{ | ||
use HasFactory, HasUuids; | ||
|
||
protected $guraed = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
database/migrations/2024_11_05_101751_create_releases_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('releases', function (Blueprint $table) { | ||
$table->uuid('id')->primary(); | ||
$table->string('version')->unique(); | ||
$table->string('url'); | ||
$table->text('changelog'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('releases'); | ||
} | ||
}; |
Oops, something went wrong.