Skip to content

Commit

Permalink
Changes based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
AW0005 committed Dec 15, 2023
1 parent fdfbb01 commit dd1353b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 8 deletions.
79 changes: 79 additions & 0 deletions app/Console/Commands/AddImageHashes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace App\Console\Commands;

use App\Models\Character\CharacterCategory;
use App\Models\Currency\Currency;
use App\Models\Feature\Feature;
use App\Models\Feature\FeatureCategory;
use App\Models\Item\Item;
use App\Models\Item\ItemCategory;
use App\Models\Prompt\Prompt;
use App\Models\Prompt\PromptCategory;
use App\Models\Rarity;
use App\Models\Shop\Shop;
use App\Models\Species\Species;
use App\Models\Species\Subtype;
use App\Services\FeatureService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;

class AddImageHashes extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'add-image-hashes';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Adds hashes to any existing images that don\'t already have them.';

/**
* Create a new command instance.
*/
public function __construct() {
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle() {
$images = CharacterCategory::where('has_image', 1)->whereNull('hash')->get();
$images = $images->concat(Currency::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(Feature::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(FeatureCategory::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(Item::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(ItemCategory::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(Prompt::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(PromptCategory::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(Rarity::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(Shop::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(Species::where('has_image', 1)->whereNull('hash')->get());
$images = $images->concat(Subtype::where('has_image', 1)->whereNull('hash')->get());

foreach ($images as $image) {
$oldName = $image->id . '-image.png';
$image->hash = randomString(10);
// Any service works, I can't use the abstract one
if (
File::exists(public_path($image->imageDirectory) . '/' . $oldName) &&
(new FeatureService)->handleImage(
null,
public_path($image->imageDirectory),
$image->hash . $image->id . '-image.png',
$oldName
)
) $image->save();
else
$this->info('Failed to add hash to ' . get_class($image) . ', id ' . $image->id);
}
}
}
8 changes: 0 additions & 8 deletions public/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,4 @@
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Deny access to no referrer
RewriteCond %{HTTP_REFERER} ^$
RewriteRule \.(jpg|jpeg|png|gif)$ [NC,F,L]

# Deny access to referrer that is not the host
RewriteCond %{HTTP_HOST}@@%{HTTP_REFERER} !^([^@]*)@@https?://\1/.* [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ [NC,F,L]
</IfModule>

0 comments on commit dd1353b

Please sign in to comment.