Skip to content

Commit

Permalink
updated with requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cshyam1892 committed Jan 22, 2023
1 parent f930ac0 commit 160f052
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 4 deletions.
21 changes: 21 additions & 0 deletions app/Http/Controllers/Administration/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Http\Requests\Settings\GetSetAllSettingsRequest;
use App\Http\Requests\Settings\SetAlbumDecorationRequest;
use App\Http\Requests\Settings\SetCSSSettingRequest;
use App\Http\Requests\Settings\SetJSSettingRequest;
use App\Http\Requests\Settings\SetDefaultLicenseSettingRequest;
use App\Http\Requests\Settings\SetDropboxKeySettingRequest;
use App\Http\Requests\Settings\SetImageOverlaySettingRequest;
Expand Down Expand Up @@ -333,6 +334,26 @@ public function setCSS(SetCSSSettingRequest $request): void
}
}

/**
* Takes the js input text and put it into `dist/custom.js`.
* This allows admins to actually execute custom js code on their
* Lychee-Laravel installation.
*
* @param SetJSSettingRequest $request
*
* @return void
*
* @throws InsufficientFilesystemPermissions
*/
public function setJS(SetJSSettingRequest $request): void
{
/** @var string $js */
$js = $request->getSettingValue();
if (Storage::disk('dist')->put('custom.js', $js) === false) {
throw new InsufficientFilesystemPermissions('Could not save JS');
}
}

/**
* Returns ALL settings. This is not filtered!
* Fortunately, this is behind an admin middleware.
Expand Down
25 changes: 25 additions & 0 deletions app/Http/Requests/Settings/SetJSSettingRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Requests\Settings;

class SetJSSettingRequest extends AbstractSettingRequest
{
public const ATTRIBUTE = 'js';

/**
* {@inheritDoc}
*/
public function rules(): array
{
return [self::ATTRIBUTE => 'present|nullable|string'];
}

/**
* {@inheritDoc}
*/
protected function processValidatedValues(array $values, array $files): void
{
$this->name = self::ATTRIBUTE;
$this->value = $values[self::ATTRIBUTE] ?? '';
}
}
1 change: 1 addition & 0 deletions public/dist/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('sosua');
70 changes: 68 additions & 2 deletions public/dist/frontend.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
Route::post('/Settings::setLocationShow', [Administration\SettingsController::class, 'setLocationShow']);
Route::post('/Settings::setLocationShowPublic', [Administration\SettingsController::class, 'setLocationShowPublic']);
Route::post('/Settings::setCSS', [Administration\SettingsController::class, 'setCSS']);
Route::post('/Settings::setJS', [Administration\SettingsController::class, 'setJS']);
Route::post('/Settings::getAll', [Administration\SettingsController::class, 'getAll']);
Route::post('/Settings::saveAll', [Administration\SettingsController::class, 'saveAll']);
Route::post('/Settings::setAlbumDecoration', [Administration\SettingsController::class, 'setAlbumDecoration']);
Expand Down
5 changes: 4 additions & 1 deletion scripts/install_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
echo "\n{$YELLOW}creating file for CSS personalization$NO_COLOR" . PHP_EOL;
touch('public/dist/user.css');

echo "\n{$YELLOW}creating file for JS personalization$NO_COLOR" . PHP_EOL;
touch('public/dist/custom.js');

echo "\n{$YELLOW}creating default SQLite database$NO_COLOR" . PHP_EOL;
touch('database/database.sqlite');

Expand All @@ -23,4 +26,4 @@
}

echo "\n{$ORANGE}To disable the call of composer and migration on pull add$NO_COLOR" . PHP_EOL;
echo "{$ORANGE}a file named '.NO_AUTO_COMPOSER_MIGRATE' in this directory.$NO_COLOR" . PHP_EOL;
echo "{$ORANGE}a file named '.NO_AUTO_COMPOSER_MIGRATE' in this directory.$NO_COLOR" . PHP_EOL;

0 comments on commit 160f052

Please sign in to comment.