Skip to content

Commit 1cde981

Browse files
authored
feat: Add setting to disable embed endpoints and UI. (#4316)
1 parent 2a99024 commit 1cde981

7 files changed

Lines changed: 64 additions & 4 deletions

File tree

app/Http/Controllers/Gallery/EmbedController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public function __construct(
5454
*/
5555
public function getAlbum(EmbededRequest $request): EmbedAlbumResource
5656
{
57+
if (!$request->configs()->getValueAsBool('is_embed_enabled')) {
58+
throw new NotFoundHttpException();
59+
}
60+
5761
/** @var Album $album */
5862
$album = $request->album() ?? throw new LycheeLogicException('Album should be set in EmbededRequest');
5963

@@ -84,6 +88,10 @@ public function getAlbum(EmbededRequest $request): EmbedAlbumResource
8488
*/
8589
public function getPublicStream(EmbededRequest $request): EmbedStreamResource
8690
{
91+
if (!$request->configs()->getValueAsBool('is_embed_enabled')) {
92+
throw new NotFoundHttpException();
93+
}
94+
8795
$photos = $this->findPublicPhotos($request->limit ?? 100, $request->offset, $request->sort ?? 'desc', $request->authors);
8896

8997
// Get site title from configuration

app/Http/Resources/GalleryConfigs/InitConfig.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ class InitConfig extends Data
122122
public bool $is_rating_show_avg_in_album_view_enabled;
123123
public VisibilityType $rating_album_view_mode;
124124

125+
// Embed
126+
public bool $is_embed_enabled = true;
127+
125128
// Homepage
126129
public string $default_homepage;
127130
public bool $is_timeline_page_enabled = false;
@@ -225,6 +228,9 @@ public function __construct()
225228
$this->is_rating_show_avg_in_album_view_enabled = request()->configs()->getValueAsBool('rating_show_avg_in_album_view');
226229
$this->rating_album_view_mode = request()->configs()->getValueAsEnum('rating_album_view_mode', VisibilityType::class);
227230

231+
// Embed
232+
$this->is_embed_enabled = request()->configs()->getValueAsBool('is_embed_enabled');
233+
228234
// Homepage
229235
$this->default_homepage = request()->configs()->getValueAsString('home_page_default');
230236
$this->is_timeline_page_enabled = request()->configs()->getValueAsBool('timeline_page_enabled');
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2026 LycheeOrg.
7+
*/
8+
9+
use App\Models\Extensions\BaseConfigMigration;
10+
11+
return new class() extends BaseConfigMigration {
12+
public const CAT = 'config';
13+
14+
public function getConfigs(): array
15+
{
16+
return [
17+
[
18+
'key' => 'is_embed_enabled',
19+
'value' => '1',
20+
'cat' => self::CAT,
21+
'type_range' => self::BOOL,
22+
'description' => 'Enable the embed API endpoints and UI features for external website integration.',
23+
'details' => 'When disabled, all embed API endpoints return 404 and embed-related UI features are hidden.',
24+
'is_secret' => false,
25+
'is_expert' => false,
26+
'level' => 0,
27+
'order' => 100,
28+
],
29+
];
30+
}
31+
};

resources/js/components/gallery/albumModule/AlbumHero.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ const albumStore = useAlbumStore();
179179
const albumsStore = useAlbumsStore();
180180
const photosStore = usePhotosStore();
181181
182-
const { is_se_enabled, is_se_preview_enabled, are_nsfw_visible, is_slideshow_enabled, album_header_size } = storeToRefs(lycheeStore);
182+
const { is_se_enabled, is_se_preview_enabled, are_nsfw_visible, is_slideshow_enabled, album_header_size, is_embed_enabled } =
183+
storeToRefs(lycheeStore);
183184
184185
function toggleAlbumView(mode: "grid" | "list") {
185186
lycheeStore.album_view_mode = mode;
@@ -224,6 +225,10 @@ const emits = defineEmits<{
224225
// Check if album is embeddable (public, no password, no link requirement)
225226
// and if user is logged in
226227
const isEmbeddable = computed(() => {
228+
// Respect the global embed enabled setting
229+
if (!is_embed_enabled.value) {
230+
return false;
231+
}
227232
// Only show embed button to logged-in users
228233
if (!userStore.isLoggedIn) {
229234
return false;

resources/js/composables/contextMenus/leftMenu.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,15 @@ export function useLeftMenu(
3535
const { user } = storeToRefs(authStore);
3636

3737
const { initData, left_menu_open } = storeToRefs(LeftMenuStateStore);
38-
const { clockwork_url, is_se_enabled, is_se_preview_enabled, is_se_info_hidden, is_favourite_enabled, is_timeline_page_enabled } =
39-
storeToRefs(lycheeStore);
38+
const {
39+
clockwork_url,
40+
is_se_enabled,
41+
is_se_preview_enabled,
42+
is_se_info_hidden,
43+
is_favourite_enabled,
44+
is_timeline_page_enabled,
45+
is_embed_enabled,
46+
} = storeToRefs(lycheeStore);
4047
const openLycheeAbout = ref(false);
4148
const logsEnabled = ref(true);
4249

@@ -114,7 +121,7 @@ export function useLeftMenu(
114121
{
115122
label: "left-menu.embed_stream",
116123
icon: "pi pi-code",
117-
access: user.value?.id !== null,
124+
access: (is_embed_enabled.value ?? true) && user.value?.id !== null,
118125
command: () => {
119126
const togglableStore = useTogglablesStateStore();
120127
togglableStore.embed_code_mode = "stream";

resources/js/lychee.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ declare namespace App.Http.Resources.GalleryConfigs {
509509
rating_album_view_mode: App.Enum.VisibilityType;
510510
default_homepage: string;
511511
is_timeline_page_enabled: boolean;
512+
is_embed_enabled: boolean;
512513
is_contact_form_enabled: boolean;
513514
photos_pagination_mode: App.Enum.PaginationMode;
514515
albums_pagination_mode: App.Enum.PaginationMode;

resources/js/stores/LycheeState.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export const useLycheeStateStore = defineStore("lychee-store", {
7676
dropbox_api_key: "disabled",
7777
default_homepage: "gallery",
7878
is_timeline_page_enabled: false,
79+
is_embed_enabled: true,
7980

8081
// Login options
8182
is_basic_auth_enabled: true,
@@ -220,6 +221,7 @@ export const useLycheeStateStore = defineStore("lychee-store", {
220221

221222
this.default_homepage = data.default_homepage;
222223
this.is_timeline_page_enabled = data.is_timeline_page_enabled;
224+
this.is_embed_enabled = data.is_embed_enabled;
223225

224226
this.photos_pagination_mode = data.photos_pagination_mode;
225227
this.albums_pagination_mode = data.albums_pagination_mode;

0 commit comments

Comments
 (0)