Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API to change upload date & fix API token auth #1591

Merged
merged 12 commits into from
Nov 23, 2022
Merged
16 changes: 16 additions & 0 deletions app/Http/Controllers/PhotoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use App\Http\Requests\Photo\SetPhotosStarredRequest;
use App\Http\Requests\Photo\SetPhotosTagsRequest;
use App\Http\Requests\Photo\SetPhotosTitleRequest;
use App\Http\Requests\Photo\SetPhotoUploadDate;
use App\Image\TemporaryLocalFile;
use App\Image\UploadedFile;
use App\ModelFunctions\SymLinkFunctions;
Expand Down Expand Up @@ -274,6 +275,21 @@ public function setLicense(SetPhotoLicenseRequest $request): void
$request->photo()->save();
}

/**
* Sets the license of the photo.
*
* @param SetPhotoUploadDate $request
*
* @return void
*
* @throws LycheeException
*/
public function setUploadDate(SetPhotoUploadDate $request): void
{
$request->photo()->created_at = $request->requestDate();
$request->photo()->save();
}

/**
* Delete one or more photos.
*
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class VerifyCsrfToken extends Middleware
*/
public function handle($request, Closure $next): mixed
{
$token = $request->get(SessionOrTokenGuard::TOKEN_COLUMN_NAME);
$token = $request->headers->get(SessionOrTokenGuard::HTTP_TOKEN_HEADER);
if (is_string($token) && $token !== '') {
return $next($request);
}
Expand Down
15 changes: 15 additions & 0 deletions app/Http/Requests/Contracts/HasDate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Http\Requests\Contracts;

use Illuminate\Support\Carbon;

interface HasDate
{
public const DATE_ATTRIBUTE = 'date';

/**
* @return Carbon|null
*/
public function requestDate(): ?Carbon;
ildyria marked this conversation as resolved.
Show resolved Hide resolved
}
40 changes: 40 additions & 0 deletions app/Http/Requests/Photo/SetPhotoUploadDate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Http\Requests\Photo;

use App\Http\Requests\BaseApiRequest;
use App\Http\Requests\Contracts\HasDate;
use App\Http\Requests\Contracts\HasPhoto;
use App\Http\Requests\Traits\Authorize\AuthorizeCanEditPhotoTrait;
use App\Http\Requests\Traits\HasDateTrait;
use App\Http\Requests\Traits\HasPhotoTrait;
use App\Models\Photo;
use App\Rules\RandomIDRule;
use Illuminate\Support\Carbon;

class SetPhotoUploadDate extends BaseApiRequest implements HasPhoto, HasDate
{
use HasPhotoTrait;
use HasDateTrait;
use AuthorizeCanEditPhotoTrait;

/**
* {@inheritDoc}
*/
public function rules(): array
{
return [
HasPhoto::PHOTO_ID_ATTRIBUTE => ['required', new RandomIDRule(false)],
HasDate::DATE_ATTRIBUTE => 'required|date',
];
}

/**
* {@inheritDoc}
*/
protected function processValidatedValues(array $values, array $files): void
{
$this->photo = Photo::query()->findOrFail($values[HasPhoto::PHOTO_ID_ATTRIBUTE]);
$this->date = Carbon::parse($values[HasDate::DATE_ATTRIBUTE]);
}
}
18 changes: 18 additions & 0 deletions app/Http/Requests/Traits/HasDateTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Requests\Traits;

use Illuminate\Support\Carbon;

trait HasDateTrait
{
protected ?Carbon $date = null;

/**
* @return Carbon|null
*/
public function requestDate(): ?Carbon
{
return $this->date;
}
}
2 changes: 2 additions & 0 deletions app/Locale/ChineseSimplified.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => '此照片的共享属性将被修改为:',
'PHOTO_NO_EDIT_SHARING_TEXT' => '因为此照片位于一个公开相册中,其继承了相册的可见性设置。其当前的可见性仅在下方作为提示的作用而显示。',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => '此照片的可见性可以使用全局的 Lychee 设置进行更细致的调整。其当前的可见性仅在下方作为提示的作用而显示。',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => '载入中',
'ERROR' => '错误',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/ChineseTraditional.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => '此照片的共享屬性將更改為以下內容:',
'PHOTO_NO_EDIT_SHARING_TEXT' => '由於此照片位於公開相簿中,因此它會繼承該相冊的公開範圍設置。 下面顯示了它的當前可見性,僅供參考。',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => '可以使用全局Lychee設置微調這張照片的可見性。 下面顯示了它的當前可見性,僅供參考。',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => '載入中',
'ERROR' => '錯誤',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/Czech.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => 'Vlastnosti sdílení fotografie budou změněny takto:',
'PHOTO_NO_EDIT_SHARING_TEXT' => 'Protože je tato fotografie umístěna ve veřejném albu, zdědí i nastavení tohoto veřejného alba. Aktuální stav viditelnosti je uveden pouze pro informaci.',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => 'Viditelnost této fotografie lze doladit pomocí globálních nastavení. Aktuální stav viditelnosti je uveden pouze pro informaci.',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => 'Probíhá příprava',
'ERROR' => 'Chyba',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/Dutch.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => 'The sharing properties of this photo will be changed to the following:',
'PHOTO_NO_EDIT_SHARING_TEXT' => 'Because this photo is located in a public album, it inherits that album’s visibility settings. Its current visibility is shown below for informational purposes only.',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => 'The visibility of this photo can be fine-tuned using global Lychee settings. Its current visibility is shown below for informational purposes only.',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => 'Laden',
'ERROR' => 'Error',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/English.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => 'The sharing properties of this photo will be changed to the following:',
'PHOTO_NO_EDIT_SHARING_TEXT' => 'Because this photo is located in a public album, it inherits that album’s visibility settings. Its current visibility is shown below for informational purposes only.',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => 'The visibility of this photo can be fine-tuned using global Lychee settings. Its current visibility is shown below for informational purposes only.',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => 'Loading',
'ERROR' => 'Error',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/French.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => 'Les propriété de partages de cette photo seront changé pour les suivantes :',
'PHOTO_NO_EDIT_SHARING_TEXT' => 'Parce que cette photo est dans un album public, elle hérite des propriété de partage de l’album. Sa visibilité est montrée ci dessous pour votre information.',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => 'La visibilité de cette photo est ajustable avec les paramètres generaux de Lychee. Sa visibilité est montrée ci dessous pour votre information.',
'PHOTO_NEW_CREATED_AT' => 'Entrez la date d’upload de cette photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Changer la date',

'LOADING' => 'Chargement en cours',
'ERROR' => 'Erreur',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/German.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => 'Die Einstellungen zum Teilen des Foto werden wie folgt angepasst:',
'PHOTO_NO_EDIT_SHARING_TEXT' => 'Dieses Foto ist in einem öffentlichen Album und erbt deshalb die Sichtbarkeitseinstellungen des Albums. Die aktuellen Sichtbarkeitseinstellungen werden unten nur zur Info dargestellt.',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => 'Die Sichtbarkeit dieses Fotos kann über die globalen Lychee Einstellungen modifiziert werden. Die aktuellen Sichtbarkeitseinstellungen werden unten nur zur Info dargestellt.',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => 'Laden',
'ERROR' => 'Fehler',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/Greek.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => 'Οι ιδιότητες κοινής χρήσης αυτής της φωτογραφίας θα αλλάξουν στις ακόλουθες:',
'PHOTO_NO_EDIT_SHARING_TEXT' => 'Επειδή αυτή η φωτογραφία βρίσκεται σε ένα δημόσιο λεύκωμα, κληρονομεί τις ρυθμίσεις ορατότητας του λευκώματος στο οποίο ανήκει. Η τρέχουσα ορατότητά της φαίνεται παρακάτω για ενημερωτικούς λόγους μόνο.',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => 'Η ορατότητα αυτής της φωτογραφίας μπορεί να ρυθμιστεί με μεγαλύτερη λεπτομέρεια χρησιμοποιώντας τις γενικές ρυθμίσεις του Lychee. Η τρέχουσα ορατότητά της φαίνεται παρακάτω για ενημερωτικούς λόγους μόνο.',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => 'Φορτώνει',
'ERROR' => 'Σφάλμα',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/Italian.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => 'The sharing properties of this photo will be changed to the following:',
'PHOTO_NO_EDIT_SHARING_TEXT' => 'Because this photo is located in a public album, it inherits that album’s visibility settings. Its current visibility is shown below for informational purposes only.',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => 'The visibility of this photo can be fine-tuned using global Lychee settings. Its current visibility is shown below for informational purposes only.',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => 'Caricamento',
'ERROR' => 'Errore',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/NorwegianBokmal.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => 'Innstillingene for deling av bildet vil bli endret til:',
'PHOTO_NO_EDIT_SHARING_TEXT' => 'Dette bildet er i et offentlig album som arver synligheten til albumet. Nåværende synlighet er vist bare for informasjon.',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => 'Synligeten til bildet kan bli finjustert gjennom innstillingene til Lychee. Nåværende synlighet er vist bare for informasjon.',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => 'Laster',
'ERROR' => 'Feil',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/Polish.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => 'Ustawienia udostępniania tego zdjęcia zostaną zmienione na następujące:',
'PHOTO_NO_EDIT_SHARING_TEXT' => 'Ponieważ zdjęcie znajduje się w albumie publicznym, dzieli jego ustawienia widoczności. Aktualna wartość widoczna jest poniżej (tylko informacyjnie).',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => 'Widoczność zdjęcia można dostosować używając globalnych ustawień Lychee. Aktualna wartość widoczna jest poniżej (tylko informacyjnie).',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => 'Wczytywanie',
'ERROR' => 'Błąd',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/Portuguese.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => 'As propriedades de partilha desta fotografia vão ser alteradas para o seguinte:',
'PHOTO_NO_EDIT_SHARING_TEXT' => 'Porque esta fotografia está localizada num álbum público, herda as configurações de visibilidade desse álbum. A sua visibilidade atual é mostrada abaixo apenas como informação.',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => 'A visibilidade desta fotografia pode ser afinada através das configurações globais do Lychee. A sua visibilidade atual é mostrada abaixo apenas como informação.',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => 'A carregar',
'ERROR' => 'Erro',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/Russian.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => 'The sharing properties of this photo will be changed to the following:',
'PHOTO_NO_EDIT_SHARING_TEXT' => 'Because this photo is located in a public album, it inherits that album’s visibility settings. Its current visibility is shown below for informational purposes only.',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => 'The visibility of this photo can be fine-tuned using global Lychee settings. Its current visibility is shown below for informational purposes only.',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => 'Загрузка',
'ERROR' => 'Ошибка',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/Slovak.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => 'Vlastnosti zdieľania tejto fotografie sa zmenia na nasledujúce:',
'PHOTO_NO_EDIT_SHARING_TEXT' => 'Pretože je táto fotografia umiestnená vo verejnom albume, zdedí nastavenie viditeľnosti daného albumu. Jeho aktuálna viditeľnosť je uvedená len na informačné účely.',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => 'Viditeľnosť tejto fotografie je možné doladiť pomocou globálnych nastavení. Jeho aktuálna viditeľnosť je uvedená len na informačné účely.',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => 'Nahráva sa',
'ERROR' => 'Chyba',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/Spanish.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => 'Las propiedades para compartir de esta foto se cambiarán a lo siguiente:',
'PHOTO_NO_EDIT_SHARING_TEXT' => 'Debido a que esta foto se encuentra en un álbum público, hereda la configuración de visibilidad de ese álbum. Su visibilidad actual se muestra a continuación solo con fines informativos.',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => 'La visibilidad de esta foto se puede ajustar utilizando la configuración global de Lychee. Su visibilidad actual se muestra a continuación solo con fines informativos.',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => 'Cargando',
'ERROR' => 'Error',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/Swedish.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => 'The sharing properties of this photo will be changed to the following:',
'PHOTO_NO_EDIT_SHARING_TEXT' => 'Because this photo is located in a public album, it inherits that album’s visibility settings. Its current visibility is shown below for informational purposes only.',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => 'The visibility of this photo can be fine-tuned using global Lychee settings. Its current visibility is shown below for informational purposes only.',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => 'Laddar',
'ERROR' => 'Fel',
Expand Down
2 changes: 2 additions & 0 deletions app/Locale/Vietnamese.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public function get_locale(): array
'PHOTO_EDIT_SHARING_TEXT' => 'Những đặc điểm chia sẻ của tấm hình này sẽ được thay đổi thành như sau:',
'PHOTO_NO_EDIT_SHARING_TEXT' => 'Vì tấm hình này đang có trong một album công cộng, nó có chế độ hiển thị công cộng giống như cài đặt hiển thị của album. Chế độ hiển thị hiện tại của hình được hiển thị bên dưới để người dùng biết thêm thông tin.',
'PHOTO_EDIT_GLOBAL_SHARING_TEXT' => 'Chế độ hiển thị của tấm hình này có thể được chỉnh chỉ tiết hơn với cài đặt tổng của Lychee. Chế độ hiển thị hiện thời của tấm hình được hiển thị để người dùng biết thêm thông tin.',
'PHOTO_NEW_CREATED_AT' => 'Enter the upload date for this photo. mm/dd/yyyy, hh:mm [am/pm]',
'PHOTO_SET_CREATED_AT' => 'Set upload date',

'LOADING' => 'Đang tải',
'ERROR' => 'Bị lỗi',
Expand Down
Loading