Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mythos committed Jul 29, 2023
2 parents bc9db94 + 52f1aef commit b157518
Show file tree
Hide file tree
Showing 95 changed files with 4,710 additions and 10,962 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ IMAGES_TYPE=jpg
IMAGES_NSFW_PIXELATE=20
IMAGES_NSFW_BLUR=10

JOBS_MANGAPASSION_UPDATER_INCLUDE_COMPLETED=false
JOBS_MANGAPASSION_UPDATER_INCLUDE_CANCELED=false

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
Expand Down
11 changes: 0 additions & 11 deletions .github/dependabot.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
- uses: shivammathur/setup-php@5b29e8a45433c406b3902dff138a820a408c45b7
with:
php-version: "8.1"
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## 2.3.1

- Added images for publishers
- Added page count to volumes
- Added placeholder image
- Added barcode scanner when editing volumes
- Changed total in overview to only count delivered and read volumes
- Removed ISBN requirement for Overview
- Changed search bar to be always visible on mobile devices
- Fields are now readonly when managed via Manga Passion API
- Improved series/volume requirements for statistics
- Improved handling of Manga Passion API results regarding single volume series

## 2.3.0 (2022-07-12)

- Added cover images for volumes
Expand Down
33 changes: 33 additions & 0 deletions app/Helpers/ImageHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Helpers;

use App\Models\Publisher;
use App\Models\Series;
use App\Models\Volume;
use Illuminate\Support\Facades\Storage;
Expand All @@ -16,6 +17,14 @@ class ImageHelpers

private const COVER_SFW_FILENAME = 'cover_sfw';

private const LOGO_FILENAME = 'logo';

private const LOGO_SFW_FILENAME = 'logo_sfw';

private const IMAGE_FILENAME = 'image';

private const IMAGE_SFW_FILENAME = 'image_sfw';

public static function getImage($url): ?Image
{
if (empty($url)) {
Expand Down Expand Up @@ -66,6 +75,30 @@ public static function updateSeriesImage(Series $series, $wasCreated = false): v
]);
}

public static function updatePublisherImage(Publisher $publisher, $wasCreated = false): void
{
if (!$wasCreated && !$publisher->isDirty('image_url') && !$publisher->wasChanged('image_url')) {
return;
}

if (!empty($publisher->image_url)) {
static::createAndSaveCoverImage($publisher->image_url, $publisher->image_path);

return;
}

$path = $publisher->image_path;
$thumbnailPath = static::THUMBNAIL_FOLDER . $publisher->image_path;
$coverFilename = static::LOGO_FILENAME . '.' . config('images.type');
$coverSfwFilename = static::LOGO_SFW_FILENAME . '.' . config('images.type');
Storage::disk('public')->delete([
implode(DIRECTORY_SEPARATOR, [$path, $coverFilename]),
implode(DIRECTORY_SEPARATOR, [$path, $coverSfwFilename]),
implode(DIRECTORY_SEPARATOR, [$thumbnailPath, $coverFilename]),
implode(DIRECTORY_SEPARATOR, [$thumbnailPath, $coverSfwFilename]),
]);
}

public static function updateVolumeImage(Volume $volume, $wasCreated = false): void
{
if (!$wasCreated && !$volume->isDirty('image_url') && !$volume->wasChanged('image_url')) {
Expand Down
24 changes: 21 additions & 3 deletions app/Helpers/MangaPassionApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ public static function loadSeriesById(int $mangaPassionId)
$series['status'] = $result['status'] ?? SeriesStatus::ANNOUNCED;
$series['image_url'] = $result['cover'] ?? '';
$series['total'] = $result['numVolumes'] ?? 0;

if (!empty($result['allInOne'])) {
$isbn = !empty($result['allInOne']['isbn13']) ? (string) Isbn::of($result['allInOne']['isbn13'])->to13() : null;
$publish_date = !empty($result['allInOne']['date']) ? new DateTime($result['allInOne']['date']) : null;
$price = !empty($result['allInOne']['price']) ? floatval($result['allInOne']['price']) / 100.0 : 0.00;
$pages = !empty($result['allInOne']['pages']) ? $result['allInOne']['pages'] : null;
$series['allInOne'] = true;
$series['isbn'] = $isbn;
$series['publish_date'] = $publish_date?->format('Y-m-d');
$series['price'] = $price;
$series['pages'] = $pages;
}

if (!empty($result['sources'])) {
$source = $result['sources'][0];
$series['total'] = $source['volumes'] ?? null;
Expand All @@ -57,6 +70,10 @@ public static function loadSeriesById(int $mangaPassionId)
$series['demographics'] = $tags->where('type', '=', '0')->pluck('name')->first();
$series['genres'] = $tags->where('type', '=', '1')->pluck('name');
}
if (!empty($source['tags'])) {
$magazines = collect($source['magazines']);
$series['magazines'] = $magazines->pluck('name');
}
}

$defaultPrice = MangaPassionApi::getDefaultPrice($series['mangapassion_id']);
Expand Down Expand Up @@ -89,13 +106,14 @@ public static function loadVolumes($mangaPassionId, $total)
}
$isbn = !empty($responseItem['isbn13']) ? (string) Isbn::of($responseItem['isbn13'])->to13() : null;
$price = !empty($responseItem['price']) ? floatval($responseItem['price']) / 100.0 : 0.00;

$pages = $responseItem['pages'] ?? null;
$result[] = [
'number' => $number,
'isbn' => $isbn,
'publish_date' => $publish_date,
'publish_date' => $publish_date?->format('Y-m-d'),
'price' => $price,
'image_url' => $responseItem['cover'],
'image_url' => $responseItem['cover'] ?? null,
'pages' => $pages,
];
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Livewire/Articles/CreateArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CreateArticle extends Component

protected $rules = [
'article.name' => 'required',
'article.release_date' => 'date',
'article.release_date' => 'nullable|date',
'article.price' => 'nullable|regex:"^[0-9]{1,9}([,.][0-9]{1,2})?$"',
'article.status' => 'required|integer|min:0',
'article.category_id' => 'required|exists:categories,id',
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Livewire/Articles/EditArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class EditArticle extends Component

protected $rules = [
'article.name' => 'required',
'article.release_date' => 'date',
'article.release_date' => 'nullable|date',
'article.price' => 'nullable|regex:"^[0-9]{1,9}([,.][0-9]{1,2})?$"',
'article.status' => 'required|integer|min:0',
'article.category_id' => 'required|exists:categories,id',
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Livewire/Categories/EditCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function render()

public function updated($property, $value): void
{
if($property == 'category.page_size') {
if ($property == 'category.page_size') {
$this->category->page_size = !empty($value) ? $value : null;
}
$this->validateOnly($property);
Expand Down
9 changes: 6 additions & 3 deletions app/Http/Livewire/Overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,21 @@ private function getVolumeStatistics()
})
->orWhereHas('genres', function ($query): void {
$query->where('name', 'like', '%' . $this->search . '%');
})
->orWhereHas('magazines', function ($query): void {
$query->where('name', 'like', '%' . $this->search . '%');
});
});
});
}
$volumes = $volumes->join('series', 'volumes.series_id', '=', 'series.id')->WhereNotNull('isbn')->select([
$volumes = $volumes->join('series', 'volumes.series_id', '=', 'series.id')->select([
DB::raw('COALESCE(sum(case when volumes.status = ' . VolumeStatus::NEW . ' AND series.status <> ' . SeriesStatus::CANCELED . ' then 1 else 0 end), 0) as new'),
DB::raw('COALESCE(sum(case when volumes.status = ' . VolumeStatus::ORDERED . ' AND series.status <> ' . SeriesStatus::CANCELED . ' then 1 else 0 end), 0) as ordered'),
DB::raw('COALESCE(sum(case when volumes.status = ' . VolumeStatus::SHIPPED . ' then 1 else 0 end), 0) as shipped'),
DB::raw('COALESCE(sum(case when volumes.status = ' . VolumeStatus::DELIVERED . ' then 1 else 0 end), 0) as delivered'),
DB::raw('COALESCE(sum(case when volumes.status = ' . VolumeStatus::READ . ' then 1 else 0 end), 0) as `read`'),
DB::raw('COALESCE(sum(case when volumes.status = ' . VolumeStatus::DELIVERED . ' OR volumes.status = ' . VolumeStatus::READ . ' then price else 0 end), 0) as price'),
DB::raw('COALESCE(sum(case when series.status <> ' . SeriesStatus::CANCELED . ' or volumes.status = ' . VolumeStatus::DELIVERED . ' or volumes.status = ' . VolumeStatus::READ . ' then 1 else 0 end), 0) as total'),
DB::raw('COALESCE(sum(case when volumes.status = ' . VolumeStatus::DELIVERED . ' or volumes.status = ' . VolumeStatus::READ . ' then 1 else 0 end), 0) as total'),
])->first();

return json_decode(json_encode($volumes->toArray()), true);
Expand All @@ -80,7 +83,7 @@ private function getArticleStatistics()
DB::raw('COALESCE(sum(case when status = 3 then 1 else 0 end), 0) as delivered'),
DB::raw('0 as `read`'),
DB::raw('COALESCE(sum(case when status = 3 then price else 0 end), 0) as price'),
DB::raw('count(*) as total'),
DB::raw('COALESCE(sum(case when status = 3 then 1 else 0 end), 0) as total'),
])->first();

return json_decode(json_encode($articleStatisticsQuery), true);
Expand Down
23 changes: 18 additions & 5 deletions app/Http/Livewire/Publishers/CreatePublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace App\Http\Livewire\Publishers;

use App\Helpers\ImageHelpers;
use App\Models\Publisher;
use Exception;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Livewire\Component;

class CreatePublisher extends Component
Expand All @@ -11,6 +15,7 @@ class CreatePublisher extends Component

protected $rules = [
'publisher.name' => 'required',
'publisher.image_url' => 'nullable|url',
];

public function updated($property, $value): void
Expand All @@ -31,10 +36,18 @@ public function render()
public function save()
{
$this->validate();

$this->publisher->save();
toastr()->addSuccess(__(':name has been created', ['name' => $this->publisher->name]));

return redirect()->route('publishers.index');
if (!empty($this->series->default_price)) {
$this->series->default_price = floatval(Str::replace(',', '.', $this->series->default_price));
}
try {
$this->publisher->save();
ImageHelpers::updatePublisherImage($this->publisher, true);
toastr()->addSuccess(__(':name has been created', ['name' => $this->publisher->name]));

return redirect()->route('publishers.index');
} catch (Exception $exception) {
Log::error($exception);
toastr()->addError(__(':name could not be created', ['name' => $this->publisher->name]));
}
}
}
20 changes: 16 additions & 4 deletions app/Http/Livewire/Publishers/EditPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace App\Http\Livewire\Publishers;

use App\Helpers\ImageHelpers;
use App\Models\Publisher;
use App\Models\Series;
use Exception;
use Illuminate\Support\Facades\Log;
use Jantinnerezo\LivewireAlert\LivewireAlert;
use Livewire\Component;

Expand All @@ -15,6 +18,7 @@ class EditPublisher extends Component

protected $rules = [
'publisher.name' => 'required',
'publisher.image_url' => 'nullable|url',
];

protected $listeners = [
Expand All @@ -36,12 +40,20 @@ public function render()
return view('livewire.publishers.edit-publisher')->extends('layouts.app')->section('content');
}

public function save(): void
public function save()
{
$this->validate();
try {
$this->validate();

$this->publisher->save();
toastr()->addSuccess(__(':name has been updated', ['name' => $this->publisher->name]));
$this->publisher->save();
ImageHelpers::updatePublisherImage($this->publisher);
toastr()->addSuccess(__(':name has been updated', ['name' => $this->publisher->name]));

return redirect()->route('publishers.index');
} catch (Exception $exception) {
Log::error($exception);
toastr()->addError(__(':name could not be created', ['name' => $this->publisher->name]));
}
}

public function delete(): void
Expand Down
29 changes: 26 additions & 3 deletions app/Http/Livewire/RegenerateImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

use App\Helpers\ImageHelpers;
use App\Models\Article;
use App\Models\Publisher;
use App\Models\Series;
use Exception;
use Illuminate\Support\Facades\Log;
use Livewire\Component;

class RegenerateImages extends Component
Expand All @@ -18,14 +21,34 @@ public function regenerate(): void
{
$articles = Article::whereNotNull('image_url')->orderBy('id')->get();
foreach ($articles as $article) {
ImageHelpers::createAndSaveArticleImage($article->image_url, $article->image_path);
try {
ImageHelpers::createAndSaveArticleImage($article->image_url, $article->image_path);
} catch (Exception $exception) {
Log::error('Error while regenerating image for article ' . $article->name, ['exception' => $exception]);
}
}
$series = Series::with('volumes')->whereNotNull('image_url')->orderBy('id')->get();
foreach ($series as $item) {
ImageHelpers::createAndSaveCoverImage($item->image_url, $item->image_path);
try {
ImageHelpers::createAndSaveCoverImage($item->image_url, $item->image_path);
} catch (Exception $exception) {
Log::error('Error while regenerating image for series ' . $item->name, ['exception' => $exception]);
}
$volumes = $item->volumes->whereNotNull('image_url')->sortBy('id');
foreach ($volumes as $volume) {
ImageHelpers::createAndSaveCoverImage($volume->image_url, $volume->image_path);
try {
ImageHelpers::createAndSaveCoverImage($volume->image_url, $volume->image_path);
} catch (Exception $exception) {
Log::error('Error while regenerating image for volume ' . $volume->isbn, ['exception' => $exception]);
}
}
}
$publishers = Publisher::whereNotNull('image_url')->orderBy('id')->get();
foreach ($publishers as $item) {
try {
ImageHelpers::updatePublisherImage($item, true);
} catch (Exception $exception) {
Log::error('Error while regenerating image for publisher ' . $item->name, ['exception' => $exception]);
}
}
toastr()->addSuccess(__('Images have been updated'));
Expand Down
Loading

0 comments on commit b157518

Please sign in to comment.