-
-
Notifications
You must be signed in to change notification settings - Fork 366
Expand file tree
/
Copy pathInitConfig.php
More file actions
192 lines (157 loc) · 7.4 KB
/
InitConfig.php
File metadata and controls
192 lines (157 loc) · 7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/
namespace App\Http\Resources\GalleryConfigs;
use App\Enum\AlbumDecorationOrientation;
use App\Enum\AlbumDecorationType;
use App\Enum\ImageOverlayType;
use App\Enum\PhotoThumbInfoType;
use App\Enum\SmallLargeType;
use App\Enum\ThumbAlbumSubtitleType;
use App\Enum\ThumbOverlayVisibilityType;
use App\Models\Configs;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\URL;
use LycheeVerify\Verify;
use Spatie\LaravelData\Data;
use Spatie\TypeScriptTransformer\Attributes\LiteralTypeScriptType;
use Spatie\TypeScriptTransformer\Attributes\TypeScript;
#[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_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;
public bool $is_exif_disabled;
public bool $is_favourite_enabled;
public SmallLargeType $photo_previous_next_size;
// Thumbs configuration
public ThumbOverlayVisibilityType $display_thumb_album_overlay;
public ThumbOverlayVisibilityType $display_thumb_photo_overlay;
public ThumbAlbumSubtitleType $album_subtitle_type;
public AlbumDecorationType $album_decoration;
public AlbumDecorationOrientation $album_decoration_orientation;
#[LiteralTypeScriptType('1|2|3')]
public int $number_albums_per_row_mobile;
public PhotoThumbInfoType $photo_thumb_info;
// Download configuration
public bool $is_thumb_download_enabled;
public bool $is_thum2x_download_enabled;
public bool $is_small_download_enabled;
public bool $is_small2x_download_enabled;
public bool $is_medium_download_enabled;
public bool $is_medium2x_download_enabled;
// 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;
// Lychee SE is available.
public bool $is_se_enabled;
// Lychee SE is not available, but preview is enabled.
public bool $is_se_preview_enabled;
// We hide the info about Lychee SE if the user is already a supporter
// or if they asked to hide it (because we are nice :) ).
public bool $is_se_info_hidden;
// Live Metrics settings
public bool $is_live_metrics_enabled;
// User registration enabled
public bool $is_registration_enabled;
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'); // 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');
// 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->is_exif_disabled = Configs::getValueAsBool('exif_disabled_for_all');
$this->is_favourite_enabled = Configs::getValueAsBool('client_side_favourite_enabled');
$this->photo_previous_next_size = Configs::getValueAsEnum('photo_previous_next_size', SmallLargeType::class);
// 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->number_albums_per_row_mobile = Configs::getValueAsInt('number_albums_per_row_mobile');
$this->photo_thumb_info = Configs::getValueAsEnum('photo_thumb_info', PhotoThumbInfoType::class);
// Download configuration
$this->is_thumb_download_enabled = Configs::getValueAsBool('disable_thumb_download') === false;
$this->is_thum2x_download_enabled = Configs::getValueAsBool('disable_thumb2x_download') === false;
$this->is_small_download_enabled = Configs::getValueAsBool('disable_small_download') === false;
$this->is_small2x_download_enabled = Configs::getValueAsBool('disable_small2x_download') === false;
$this->is_medium_download_enabled = Configs::getValueAsBool('disable_medium_download') === false;
$this->is_medium2x_download_enabled = Configs::getValueAsBool('disable_medium2x_download') === false;
// Clockwork
$this->has_clockwork_in_menu();
// Slideshow settings
$this->slideshow_timeout = Configs::getValueAsInt('slideshow_timeout');
// Timeline settings
$this->is_timeline_left_border_visible = Configs::getValueAsBool('timeline_left_border_enabled');
// 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';
// User registration enabled
$this->is_registration_enabled = Configs::getValueAsBool('user_registration_enabled');
$this->set_supporter_properties();
}
/**
* 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
$clock_work_enabled = config('clockwork.enable') === true || (config('app.debug') === true && config('clockwork.enable') === null);
$clock_work_web = config('clockwork.web');
$this->clockwork_url = match (true) {
$clock_work_enabled && ($clock_work_web === true) => URL::asset('clockwork/app'),
is_string($clock_work_web) => $clock_work_web . '/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');
$this->is_live_metrics_enabled = $this->is_se_enabled && Configs::getValueAsBool('live_metrics_enabled');
}
}