Skip to content

Commit

Permalink
squash
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Oct 25, 2024
1 parent 4903b69 commit 46a8864
Show file tree
Hide file tree
Showing 22 changed files with 721 additions and 122 deletions.
13 changes: 13 additions & 0 deletions app/Enum/TimelineAlbumGranularity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Enum;

/**
* Defines the possible granularities for album timelines.
*/
enum TimelineAlbumGranularity: string
{
case YEAR = 'year';
case MONTH = 'month';
case DAY = 'day';
}
14 changes: 14 additions & 0 deletions app/Enum/TimelinePhotoGranularity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Enum;

/**
* Defines the possible granularities for photo timelines.
*/
enum TimelinePhotoGranularity: string
{
case YEAR = 'year';
case MONTH = 'month';
case DAY = 'day';
case HOUR = 'hour';
}
7 changes: 7 additions & 0 deletions app/Http/Resources/Collections/RootAlbumResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
namespace App\Http\Resources\Collections;

use App\DTO\TopAlbumDTO;
use App\Enum\ColumnSortingType;
use App\Enum\TimelineAlbumGranularity;
use App\Http\Resources\GalleryConfigs\RootConfig;
use App\Http\Resources\Models\ThumbAlbumResource;
use App\Http\Resources\Models\Utils\TimelineData;
use App\Http\Resources\Rights\RootAlbumRightsResource;
use App\Models\Configs;
use Illuminate\Support\Collection;
use Spatie\LaravelData\Data;
use Spatie\TypeScriptTransformer\Attributes\TypeScript;
Expand Down Expand Up @@ -54,6 +58,9 @@ public function __construct(
$this->smart_albums = $smart_albums;
$this->tag_albums = $tag_albums;
$this->albums = $albums;
$sorting = Configs::getValueAsEnum('sorting_albums_col', ColumnSortingType::class);
$album_granularity = Configs::getValueAsEnum('timeline_album_granularity', TimelineAlbumGranularity::class);
$this->albums = TimelineData::setTimeLineDataForAlbums($this->albums, $sorting, $album_granularity);
$this->shared_albums = $shared_albums;
$this->config = $config;
$this->rights = $rights;
Expand Down
6 changes: 6 additions & 0 deletions app/Http/Resources/GalleryConfigs/AlbumConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use App\Enum\AspectRatioCSSType;
use App\Enum\AspectRatioType;
use App\Enum\PhotoLayoutType;
use App\Enum\TimelineAlbumGranularity;
use App\Enum\TimelinePhotoGranularity;
use App\Models\Album;
use App\Models\Configs;
use App\Models\Extensions\BaseAlbum;
Expand All @@ -28,6 +30,8 @@ class AlbumConfig extends Data
public bool $is_nsfw_warning_visible;
public AspectRatioCSSType $album_thumb_css_aspect_ratio;
public PhotoLayoutType $photo_layout;
public TimelineAlbumGranularity $timeline_album_granularity;
public TimelinePhotoGranularity $timeline_photo_granularity;

public function __construct(AbstractAlbum $album)
{
Expand All @@ -42,6 +46,8 @@ public function __construct(AbstractAlbum $album)
$album instanceof BaseAlbum &&
$album->is_nsfw &&
(Auth::check() ? Configs::getValueAsBool('nsfw_warning_admin') : Configs::getValueAsBool('nsfw_warning'));
$this->timeline_album_granularity = Configs::getValueAsEnum('timeline_album_granularity', TimelineAlbumGranularity::class);
$this->timeline_photo_granularity = Configs::getValueAsEnum('timeline_photo_granularity', TimelinePhotoGranularity::class);

$this->setIsMapAccessible();
$this->setIsSearchAccessible($this->is_base_album);
Expand Down
109 changes: 80 additions & 29 deletions app/Http/Resources/GalleryConfigs/InitConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,42 @@
#[TypeScript()]
class InitConfig extends Data
{
// ! This will make the error on http requests or front-end being displayed very visibly.
public bool $is_debug_enabled;

// NSFW settings
public bool $are_nsfw_visible;
public bool $is_nsfw_warning_visible;
public bool $is_nsfw_background_blurred;
public string $nsfw_banner_override;
public bool $is_nsfw_banner_backdrop_blurred;

// Keybinding help popup
public bool $show_keybinding_help_popup;

// Image overlay settings
public ImageOverlayType $image_overlay_type;
public bool $can_rotate;
public bool $can_autoplay;

// Thumbs configuration
public ThumbOverlayVisibilityType $display_thumb_album_overlay;
public ThumbOverlayVisibilityType $display_thumb_photo_overlay;
public ?string $clockwork_url;
public ThumbAlbumSubtitleType $album_subtitle_type;
public bool $can_rotate;
public bool $can_autoplay;
public AlbumDecorationType $album_decoration;
public AlbumDecorationOrientation $album_decoration_orientation;

// Clockwork
public ?string $clockwork_url;

// Slideshow setting
public int $slideshow_timeout;

// Timeline settings
public bool $is_timeline_left_border_visible;

// Site title & dropbox key if logged in as admin.
public string $title;
public string $dropbox_api_key;
public int $slideshow_timeout;

// Lychee SE is available.
public bool $is_se_enabled;
Expand All @@ -47,48 +64,82 @@ class InitConfig extends Data

public function __construct()
{
// Debug mode
$this->is_debug_enabled = config('app.debug');

// NSFW settings
$this->are_nsfw_visible = Configs::getValueAsBool('nsfw_visible');
$this->is_nsfw_background_blurred = Configs::getValueAsBool('nsfw_blur');
$this->nsfw_banner_override = Configs::getValueAsString('nsfw_banner_override');
$this->is_nsfw_banner_backdrop_blurred = Configs::getValueAsBool('nsfw_banner_blur_backdrop');
$this->image_overlay_type = Configs::getValueAsEnum('image_overlay_type', ImageOverlayType::class);
$this->display_thumb_album_overlay = Configs::getValueAsEnum('display_thumb_album_overlay', ThumbOverlayVisibilityType::class);
$this->display_thumb_photo_overlay = Configs::getValueAsEnum('display_thumb_photo_overlay', ThumbOverlayVisibilityType::class);
$this->is_nsfw_background_blurred = Configs::getValueAsBool('nsfw_blur'); // blur the thumbnails
$this->nsfw_banner_override = Configs::getValueAsString('nsfw_banner_override'); // override the banner text.
$this->is_nsfw_banner_backdrop_blurred = Configs::getValueAsBool('nsfw_banner_blur_backdrop'); // blur the backdrop of the warning banner.

// keybinding help popup
$this->show_keybinding_help_popup = Configs::getValueAsBool('show_keybinding_help_popup');
$this->clockwork_url = $this->has_clockwork_in_menu();

$this->album_subtitle_type = Configs::getValueAsEnum('album_subtitle_type', ThumbAlbumSubtitleType::class);
// Image overlay settings
$this->image_overlay_type = Configs::getValueAsEnum('image_overlay_type', ImageOverlayType::class);
$this->can_rotate = Configs::getValueAsBool('editor_enabled');
$this->can_autoplay = Configs::getValueAsBool('autoplay_enabled');
$this->slideshow_timeout = Configs::getValueAsInt('slideshow_timeout');

// Thumbs configuration
$this->display_thumb_album_overlay = Configs::getValueAsEnum('display_thumb_album_overlay', ThumbOverlayVisibilityType::class);
$this->display_thumb_photo_overlay = Configs::getValueAsEnum('display_thumb_photo_overlay', ThumbOverlayVisibilityType::class);
$this->album_subtitle_type = Configs::getValueAsEnum('album_subtitle_type', ThumbAlbumSubtitleType::class);
$this->album_decoration = Configs::getValueAsEnum('album_decoration', AlbumDecorationType::class);
$this->album_decoration_orientation = Configs::getValueAsEnum('album_decoration_orientation', AlbumDecorationOrientation::class);

$this->title = Configs::getValueAsString('site_title');
// Clockwork
$this->has_clockwork_in_menu();

$verify = resolve(Verify::class);
$is_supporter = $verify->is_supporter();
$this->is_se_enabled = $verify->validate() && $is_supporter;
$this->is_se_preview_enabled = !$is_supporter && Configs::getValueAsBool('enable_se_preview');
$this->is_se_info_hidden = $is_supporter || Configs::getValueAsBool('disable_se_call_for_actions');
// Slideshow settings
$this->slideshow_timeout = Configs::getValueAsInt('slideshow_timeout');

// Timeline settings
$this->is_timeline_left_border_visible = Configs::getValueAsBool('timeline_left_border_enable');

// Site title & dropbox key if logged in as admin.
$this->title = Configs::getValueAsString('site_title');
$this->dropbox_api_key = Auth::user()?->may_administrate === true ? Configs::getValueAsString('dropbox_key') : 'disabled';

$this->set_supporter_properties();
}

private function has_clockwork_in_menu(): string|null
/**
* For clockwork we need to check that it is enabled or that we are in debug mode.
* Furthermore we need to check if the web interface is enabled.
*
* @return void
*/
private function has_clockwork_in_menu(): void
{
// Defining clockwork URL
$clockWorkEnabled = config('clockwork.enable') === true || (config('app.debug') === true && config('clockwork.enable') === null);
$clockWorkWeb = config('clockwork.web');
if ($clockWorkEnabled && $clockWorkWeb === true) {
return URL::asset('clockwork/app');
}
if (is_string($clockWorkWeb)) {
return $clockWorkWeb . '/app';
}

return null;

$this->clockwork_url = match (true) {
$clockWorkEnabled && ($clockWorkWeb === true) => URL::asset('clockwork/app'),
is_string($clockWorkWeb) => $clockWorkWeb . '/app',
default => null,
};
}

/**
* We set the properties related to Lychee SE.
*
* @return void
*/
private function set_supporter_properties()
{
$verify = resolve(Verify::class);
$is_supporter = $verify->is_supporter();

// We enable Lychee SE if the user is a supporter.
$this->is_se_enabled = $verify->validate() && $is_supporter;

// We disable preview if we are already a supporter.
$this->is_se_preview_enabled = !$is_supporter && Configs::getValueAsBool('enable_se_preview');

// We hide the info if we are already a supporter (or the user requests it).
$this->is_se_info_hidden = $is_supporter || Configs::getValueAsBool('disable_se_call_for_actions');
}
}
21 changes: 19 additions & 2 deletions app/Http/Resources/GalleryConfigs/RootConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Contracts\Models\AbstractAlbum;
use App\Enum\AspectRatioCSSType;
use App\Enum\AspectRatioType;
use App\Enum\TimelineAlbumGranularity;
use App\Factories\AlbumFactory;
use App\Models\Configs;
use App\Models\Photo;
Expand All @@ -20,6 +21,8 @@ class RootConfig extends Data
{
public bool $is_map_accessible = false;
public bool $is_mod_frame_enabled = false;
public bool $is_timeline_enabled = false;
public bool $is_album_timeline_enabled = false;
public bool $is_search_accessible = false;
public bool $show_keybinding_help_button = false;
#[LiteralTypeScriptType('App.Enum.AspectRatioType')]
Expand All @@ -30,15 +33,29 @@ class RootConfig extends Data
public bool $back_button_enabled;
public string $back_button_text;
public string $back_button_url;
public TimelineAlbumGranularity $timeline_album_granularity;

public function __construct()
{
$is_logged_in = Auth::check();
$count_locations = Photo::whereNotNull('latitude')->whereNotNull('longitude')->count() > 0;
$map_display = Configs::getValueAsBool('map_display');
$public_display = Auth::check() || Configs::getValueAsBool('map_display_public');
$public_display = $is_logged_in || Configs::getValueAsBool('map_display_public');

$this->is_map_accessible = $count_locations && $map_display && $public_display;
$this->is_mod_frame_enabled = $this->checkModFrameEnabled();
$this->is_search_accessible = Auth::check() || Configs::getValueAsBool('search_public');

$timeline_enabled = Configs::getValueAsBool('timeline_enable');
$timeline_public = Configs::getValueAsBool('timeline_public');
$this->is_timeline_enabled = $timeline_enabled && ($is_logged_in || $timeline_public);

$timeline_albums_enabled = Configs::getValueAsBool('timeline_albums_enable');
$timeline_albums_public = Configs::getValueAsBool('timeline_albums_public');
$this->is_album_timeline_enabled = $timeline_albums_enabled && ($is_logged_in || $timeline_albums_public);
$this->timeline_album_granularity = Configs::getValueAsEnum('timeline_album_granularity', TimelineAlbumGranularity::class);

$this->is_search_accessible = $is_logged_in || Configs::getValueAsBool('search_public');

$this->album_thumb_css_aspect_ratio = Configs::getValueAsEnum('default_album_thumb_aspect_ratio', AspectRatioType::class)->css();
$this->show_keybinding_help_button = Configs::getValueAsBool('show_keybinding_help_button');
$this->login_button_position = Configs::getValueAsString('login_button_position');
Expand Down
10 changes: 10 additions & 0 deletions app/Http/Resources/Models/AlbumResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

namespace App\Http\Resources\Models;

use App\Enum\ColumnSortingType;
use App\Enum\TimelineAlbumGranularity;
use App\Http\Resources\Editable\EditableBaseAlbumResource;
use App\Http\Resources\Models\Utils\AlbumProtectionPolicy;
use App\Http\Resources\Models\Utils\PreFormattedAlbumData;
use App\Http\Resources\Models\Utils\TimelineData;
use App\Http\Resources\Rights\AlbumRightsResource;
use App\Http\Resources\Traits\HasHeaderUrl;
use App\Http\Resources\Traits\HasPrepPhotoCollection;
use App\Models\Album;
use App\Models\Configs;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Spatie\LaravelData\Data;
Expand Down Expand Up @@ -74,6 +78,12 @@ public function __construct(Album $album)
$this->photos = $album->relationLoaded('photos') ? PhotoResource::collect($album->photos) : null;
$this->prepPhotosCollection();

if ($this->albums->count() > 0) {
$sorting = $album->album_sorting?->column ?? Configs::getValueAsEnum('sorting_albums_col', ColumnSortingType::class);
$album_granularity = Configs::getValueAsEnum('timeline_album_granularity', TimelineAlbumGranularity::class);
$this->albums = TimelineData::setTimeLineDataForAlbums($this->albums, $sorting, $album_granularity);
}

// thumb
$this->cover_id = $album->cover_id;
$this->thumb = ThumbResource::make($album->thumb?->id, $album->thumb?->type, $album->thumb?->thumbUrl, $album->thumb?->thumb2xUrl);
Expand Down
36 changes: 33 additions & 3 deletions app/Http/Resources/Models/ThumbAlbumResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
use App\Contracts\Models\AbstractAlbum;
use App\Enum\DateOrderingType;
use App\Http\Resources\Models\Utils\AlbumProtectionPolicy;
use App\Http\Resources\Models\Utils\TimelineData;
use App\Http\Resources\Rights\AlbumRightsResource;
use App\Models\Album;
use App\Models\Configs;
use App\Models\Extensions\BaseAlbum;
use App\Models\TagAlbum;
use App\SmartAlbums\BaseSmartAlbum;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Spatie\LaravelData\Data;
use Spatie\TypeScriptTransformer\Attributes\TypeScript;
Expand Down Expand Up @@ -39,7 +41,12 @@ class ThumbAlbumResource extends Data
public ?string $formatted_min_max = null;
public ?string $owner = null;

private Carbon $created_at_carbon;
private ?Carbon $min_taken_at_carbon = null;
private ?Carbon $max_taken_at_carbon = null;

public AlbumRightsResource $rights;
public ?TimelineData $timeline = null;

public function __construct(AbstractAlbum $data)
{
Expand All @@ -53,12 +60,15 @@ public function __construct(AbstractAlbum $data)
$policy = AlbumProtectionPolicy::ofSmartAlbum($data);
} else {
/** @var BaseAlbum $data */
$this->max_taken_at = $data->max_taken_at?->format($date_format);
$this->min_taken_at = $data->min_taken_at?->format($date_format);
$this->min_taken_at_carbon = $data->min_taken_at;
$this->max_taken_at_carbon = $data->max_taken_at;
$this->max_taken_at = $this->max_taken_at_carbon?->format($date_format);
$this->min_taken_at = $this->min_taken_at_carbon?->format($date_format);

$this->formatMinMaxDate();

$this->created_at = $data->created_at->format($date_format);
$this->created_at_carbon = $data->created_at;
$this->created_at = $this->created_at_carbon->format($date_format);
$policy = AlbumProtectionPolicy::ofBaseAlbum($data);
$this->description = Str::limit($data->description, 100);
$this->owner = $data->owner->username;
Expand Down Expand Up @@ -103,4 +113,24 @@ private function formatMinMaxDate(): void
$this->formatted_min_max = $this->min_taken_at . ' - ' . $this->max_taken_at;
}
}

/**
* Accessors to the Carbon instances.
*
* @return Carbon
*/
public function created_at_carbon(): Carbon
{
return $this->created_at_carbon;
}

public function min_taken_at_carbon(): ?Carbon
{
return $this->min_taken_at_carbon;
}

public function max_taken_at_carbon(): ?Carbon
{
return $this->max_taken_at_carbon;
}
}
Loading

0 comments on commit 46a8864

Please sign in to comment.