From 66f13bc782f428cfde0bce4c953e7c0b5abcb3e9 Mon Sep 17 00:00:00 2001 From: Refringe Date: Thu, 6 Jun 2024 13:18:48 -0400 Subject: [PATCH] Moves Static Assets to R2 --- app/Console/Commands/ImportHub.php | 11 +- app/Console/Commands/UploadAssets.php | 41 +++ composer.json | 1 + composer.lock | 273 +++++++++++++++++- config/filesystems.php | 16 +- resources/js/app.js | 2 + {public => resources}/video/welcome.mp4 | 0 resources/views/components/mod-list.blade.php | 2 +- resources/views/home.blade.php | 3 +- resources/views/mod/show.blade.php | 2 +- vite.config.js | 9 +- 11 files changed, 335 insertions(+), 25 deletions(-) create mode 100644 app/Console/Commands/UploadAssets.php rename {public => resources}/video/welcome.mp4 (100%) diff --git a/app/Console/Commands/ImportHub.php b/app/Console/Commands/ImportHub.php index 7c8cb45..f07767b 100644 --- a/app/Console/Commands/ImportHub.php +++ b/app/Console/Commands/ImportHub.php @@ -350,11 +350,11 @@ class ImportHub extends Command $hashShort = substr($thumbnailHash, 0, 2); $hubUrl = "https://hub.sp-tarkov.com/files/images/file/$hashShort/$fileID.$thumbnailExtension"; - $localPath = "mods/$thumbnailHash.$thumbnailExtension"; + $relativePath = "mods/$thumbnailHash.$thumbnailExtension"; // Check to make sure the image doesn't already exist. - if (Storage::disk('public')->exists($localPath)) { - return "/storage/$localPath"; + if (Storage::exists($relativePath)) { + return $relativePath; } $command->output->write("Downloading mod thumbnail: $hubUrl... "); @@ -363,12 +363,11 @@ class ImportHub extends Command if ($image === false) { $command->error('Error: '.curl_error($curl)); } else { - Storage::disk('public')->put($localPath, $image); + Storage::put($relativePath, $image); $command->info('Done.'); } - // Return the path to the saved thumbnail. - return "/storage/$localPath"; + return $relativePath; } protected function importModVersions(): void diff --git a/app/Console/Commands/UploadAssets.php b/app/Console/Commands/UploadAssets.php new file mode 100644 index 0000000..02a33c4 --- /dev/null +++ b/app/Console/Commands/UploadAssets.php @@ -0,0 +1,41 @@ +info('Publishing assets...'); + + $buildFiles = File::allFiles(public_path('/build')); + foreach ($buildFiles as $asset) { + $buildDir = 'build/'.$asset->getRelativePathname(); + $this->info('Uploading asset to: '.$buildDir); + Storage::disk('r2')->put($buildDir, $asset->getContents()); + } + + $this->info('Assets published successfully'); + } +} diff --git a/composer.json b/composer.json index cdfd0ce..2f9dd51 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ "laravel/sanctum": "^4.0", "laravel/scout": "^10.9", "laravel/tinker": "^2.9", + "league/flysystem-aws-s3-v3": "3.0", "league/html-to-markdown": "^5.1", "livewire/livewire": "^3.0", "meilisearch/meilisearch-php": "^1.8", diff --git a/composer.lock b/composer.lock index 2f761dd..3aebb50 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,157 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cf943e5dca69a9321599e06cd8e5a114", + "content-hash": "8c770bdae88add57a8001a1354d48f72", "packages": [ + { + "name": "aws/aws-crt-php", + "version": "v1.2.5", + "source": { + "type": "git", + "url": "https://github.com/awslabs/aws-crt-php.git", + "reference": "0ea1f04ec5aa9f049f97e012d1ed63b76834a31b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/awslabs/aws-crt-php/zipball/0ea1f04ec5aa9f049f97e012d1ed63b76834a31b", + "reference": "0ea1f04ec5aa9f049f97e012d1ed63b76834a31b", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35||^5.6.3||^9.5", + "yoast/phpunit-polyfills": "^1.0" + }, + "suggest": { + "ext-awscrt": "Make sure you install awscrt native extension to use any of the functionality." + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "AWS SDK Common Runtime Team", + "email": "aws-sdk-common-runtime@amazon.com" + } + ], + "description": "AWS Common Runtime for PHP", + "homepage": "https://github.com/awslabs/aws-crt-php", + "keywords": [ + "amazon", + "aws", + "crt", + "sdk" + ], + "support": { + "issues": "https://github.com/awslabs/aws-crt-php/issues", + "source": "https://github.com/awslabs/aws-crt-php/tree/v1.2.5" + }, + "time": "2024-04-19T21:30:56+00:00" + }, + { + "name": "aws/aws-sdk-php", + "version": "3.311.0", + "source": { + "type": "git", + "url": "https://github.com/aws/aws-sdk-php.git", + "reference": "3e1cc8fe522eae7deca8b7753c573c2c69444705" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/3e1cc8fe522eae7deca8b7753c573c2c69444705", + "reference": "3e1cc8fe522eae7deca8b7753c573c2c69444705", + "shasum": "" + }, + "require": { + "aws/aws-crt-php": "^1.2.3", + "ext-json": "*", + "ext-pcre": "*", + "ext-simplexml": "*", + "guzzlehttp/guzzle": "^6.5.8 || ^7.4.5", + "guzzlehttp/promises": "^1.4.0 || ^2.0", + "guzzlehttp/psr7": "^1.9.1 || ^2.4.5", + "mtdowling/jmespath.php": "^2.6", + "php": ">=7.2.5", + "psr/http-message": "^1.0 || ^2.0" + }, + "require-dev": { + "andrewsville/php-token-reflection": "^1.4", + "aws/aws-php-sns-message-validator": "~1.0", + "behat/behat": "~3.0", + "composer/composer": "^1.10.22", + "dms/phpunit-arraysubset-asserts": "^0.4.0", + "doctrine/cache": "~1.4", + "ext-dom": "*", + "ext-openssl": "*", + "ext-pcntl": "*", + "ext-sockets": "*", + "nette/neon": "^2.3", + "paragonie/random_compat": ">= 2", + "phpunit/phpunit": "^5.6.3 || ^8.5 || ^9.5", + "psr/cache": "^1.0", + "psr/simple-cache": "^1.0", + "sebastian/comparator": "^1.2.3 || ^4.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "suggest": { + "aws/aws-php-sns-message-validator": "To validate incoming SNS notifications", + "doctrine/cache": "To use the DoctrineCacheAdapter", + "ext-curl": "To send requests using cURL", + "ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages", + "ext-sockets": "To use client-side monitoring" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "files": [ + "src/functions.php" + ], + "psr-4": { + "Aws\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Amazon Web Services", + "homepage": "http://aws.amazon.com" + } + ], + "description": "AWS SDK for PHP - Use Amazon Web Services in your PHP project", + "homepage": "http://aws.amazon.com/sdkforphp", + "keywords": [ + "amazon", + "aws", + "cloud", + "dynamodb", + "ec2", + "glacier", + "s3", + "sdk" + ], + "support": { + "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", + "issues": "https://github.com/aws/aws-sdk-php/issues", + "source": "https://github.com/aws/aws-sdk-php/tree/3.311.0" + }, + "time": "2024-06-05T18:07:37+00:00" + }, { "name": "bacon/bacon-qr-code", "version": "v3.0.0", @@ -2893,6 +3042,62 @@ }, "time": "2024-05-22T10:09:12+00:00" }, + { + "name": "league/flysystem-aws-s3-v3", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/flysystem-aws-s3-v3.git", + "reference": "f8ba6a92a5c1fdcbdd89dede009a1e6e1b93ba8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/flysystem-aws-s3-v3/zipball/f8ba6a92a5c1fdcbdd89dede009a1e6e1b93ba8c", + "reference": "f8ba6a92a5c1fdcbdd89dede009a1e6e1b93ba8c", + "shasum": "" + }, + "require": { + "aws/aws-sdk-php": "^3.132.4", + "league/flysystem": "^2.0.0 || ^3.0.0", + "league/mime-type-detection": "^1.0.0", + "php": "^8.0.2" + }, + "conflict": { + "guzzlehttp/guzzle": "<7.0", + "guzzlehttp/ringphp": "<1.1.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "League\\Flysystem\\AwsS3V3\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frank de Jonge", + "email": "info@frankdejonge.nl" + } + ], + "description": "AWS S3 filesystem adapter for Flysystem.", + "keywords": [ + "Flysystem", + "aws", + "file", + "files", + "filesystem", + "s3", + "storage" + ], + "support": { + "issues": "https://github.com/thephpleague/flysystem-aws-s3-v3/issues", + "source": "https://github.com/thephpleague/flysystem-aws-s3-v3/tree/3.0.0" + }, + "time": "2022-01-13T21:11:49+00:00" + }, { "name": "league/flysystem-local", "version": "3.28.0", @@ -3396,6 +3601,72 @@ ], "time": "2024-04-12T21:02:21+00:00" }, + { + "name": "mtdowling/jmespath.php", + "version": "2.7.0", + "source": { + "type": "git", + "url": "https://github.com/jmespath/jmespath.php.git", + "reference": "bbb69a935c2cbb0c03d7f481a238027430f6440b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jmespath/jmespath.php/zipball/bbb69a935c2cbb0c03d7f481a238027430f6440b", + "reference": "bbb69a935c2cbb0c03d7f481a238027430f6440b", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "symfony/polyfill-mbstring": "^1.17" + }, + "require-dev": { + "composer/xdebug-handler": "^3.0.3", + "phpunit/phpunit": "^8.5.33" + }, + "bin": [ + "bin/jp.php" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "files": [ + "src/JmesPath.php" + ], + "psr-4": { + "JmesPath\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Declaratively specify how to extract elements from a JSON document", + "keywords": [ + "json", + "jsonpath" + ], + "support": { + "issues": "https://github.com/jmespath/jmespath.php/issues", + "source": "https://github.com/jmespath/jmespath.php/tree/2.7.0" + }, + "time": "2023-08-25T10:54:48+00:00" + }, { "name": "nesbot/carbon", "version": "3.4.0", diff --git a/config/filesystems.php b/config/filesystems.php index 44fe9c8..f51b156 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -44,15 +44,15 @@ return [ 'throw' => false, ], - 's3' => [ + 'r2' => [ 'driver' => 's3', - 'key' => env('AWS_ACCESS_KEY_ID'), - 'secret' => env('AWS_SECRET_ACCESS_KEY'), - 'region' => env('AWS_DEFAULT_REGION'), - 'bucket' => env('AWS_BUCKET'), - 'url' => env('AWS_URL'), - 'endpoint' => env('AWS_ENDPOINT'), - 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), + 'key' => env('R2_ACCESS_KEY_ID'), + 'secret' => env('R2_SECRET_ACCESS_KEY'), + 'region' => 'us-east-1', // ignores region + 'bucket' => env('R2_BUCKET'), + 'url' => env('R2_URL'), + 'endpoint' => env('R2_ENDPOINT'), + 'use_path_style_endpoint' => env('R2_USE_PATH_STYLE_ENDPOINT', false), 'throw' => false, ], diff --git a/resources/js/app.js b/resources/js/app.js index dad301d..1f65529 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -1,5 +1,7 @@ import "./bootstrap"; +import.meta.glob(["../video/**"]); + document.addEventListener("DOMContentLoaded", function () { const themeToggleIcon = { dark: document.getElementById("theme-toggle-dark-icon"), diff --git a/public/video/welcome.mp4 b/resources/video/welcome.mp4 similarity index 100% rename from public/video/welcome.mp4 rename to resources/video/welcome.mp4 diff --git a/resources/views/components/mod-list.blade.php b/resources/views/components/mod-list.blade.php index 6add3f6..20fea7e 100644 --- a/resources/views/components/mod-list.blade.php +++ b/resources/views/components/mod-list.blade.php @@ -10,7 +10,7 @@ {{ $mod->name }} @else - {{ $mod->name }} + {{ $mod->name }} @endif
diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 6482f81..7edbc44 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -4,7 +4,7 @@
- diff --git a/resources/views/mod/show.blade.php b/resources/views/mod/show.blade.php index 547d8a7..33c964c 100644 --- a/resources/views/mod/show.blade.php +++ b/resources/views/mod/show.blade.php @@ -15,7 +15,7 @@ {{ $mod->name }} @else - {{ $mod->name }} + {{ $mod->name }} @endif
diff --git a/vite.config.js b/vite.config.js index 89f26f5..498ee23 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,13 +1,10 @@ -import { defineConfig } from 'vite'; -import laravel from 'laravel-vite-plugin'; +import { defineConfig } from "vite"; +import laravel from "laravel-vite-plugin"; export default defineConfig({ plugins: [ laravel({ - input: [ - 'resources/css/app.css', - 'resources/js/app.js', - ], + input: ["resources/css/app.css", "resources/js/app.js"], refresh: true, }), ],