Skip to content

Commit

Permalink
squash
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Nov 13, 2024
1 parent f6a72dd commit 3a1f861
Show file tree
Hide file tree
Showing 86 changed files with 2,080 additions and 265 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ jobs:
if-no-files-found: error # 'warn' or 'ignore' are also available, defaults to `warn`

- name: Attest
uses: actions/attest-build-provenance@ef244123eb79f2f7a7e75d99086184180e6d0018 # v1.4.4
uses: actions/attest-build-provenance@1c608d11d69870c2092266b3f9a6f3abbf17002c # v1.4.3
with:
# Path to the artifact serving as the subject of the attestation. Must
# specify exactly one of "subject-path" or "subject-digest". May contain a
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1
uses: github/codeql-action/init@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -60,7 +60,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1
uses: github/codeql-action/autobuild@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -73,6 +73,6 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@4f3212b61783c3c68e8309a0f18a699764811cda # v3.27.1
uses: github/codeql-action/analyze@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
with:
category: "/language:${{matrix.language}}"
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@4f3212b61783c3c68e8309a0f18a699764811cda # v2.16.4
uses: github/codeql-action/upload-sarif@83a02f7883b12e0e4e1a146174f5e2292a01e601 # v2.16.4
with:
sarif_file: results.sarif
6 changes: 4 additions & 2 deletions app/Actions/Albums/PositionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(PhotoQueryPolicy $photoQueryPolicy)
public function do(): PositionDataResource
{
$photoQuery = $this->photoQueryPolicy->applySearchabilityFilter(
Photo::query()
query: Photo::query()
->with([
'album' => function ($b) {
// The album is required for photos to properly
Expand All @@ -51,7 +51,9 @@ public function do(): PositionDataResource
'size_variants.sym_links',
])
->whereNotNull('latitude')
->whereNotNull('longitude')
->whereNotNull('longitude'),
origin: null,
include_nsfw: !Configs::getValueAsBool('hide_nsfw_in_map')
);

return new PositionDataResource(null, null, $photoQuery->get(), null);
Expand Down
44 changes: 44 additions & 0 deletions app/Actions/Photo/Timeline.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Actions\Photo;

use App\Eloquent\FixedQueryBuilder;
use App\Enum\ColumnSortingPhotoType;
use App\Enum\OrderSortingType;
use App\Models\Configs;
use App\Models\Photo;
use App\Policies\PhotoQueryPolicy;
use Illuminate\Database\Eloquent\Builder;

class Timeline
{
protected PhotoQueryPolicy $photoQueryPolicy;

public function __construct(PhotoQueryPolicy $photoQueryPolicy)
{
$this->photoQueryPolicy = $photoQueryPolicy;
}

/**
* Create the query manually.
*
* @return FixedQueryBuilder<Photo>
*/
public function do(): Builder
{
$order = Configs::getValueAsEnum('timeline_photos_order', ColumnSortingPhotoType::class);

// Safe default (should not be needed).
// @codeCoverageIgnoreStart
if (!in_array($order, [ColumnSortingPhotoType::CREATED_AT, ColumnSortingPhotoType::TAKEN_AT], true)) {
$order = ColumnSortingPhotoType::TAKEN_AT;
}
// @codeCoverageIgnoreEnd

return $this->photoQueryPolicy->applySearchabilityFilter(
query: Photo::query()->with(['album', 'size_variants', 'size_variants.sym_links']),
origin: null,
include_nsfw: !Configs::getValueAsBool('hide_nsfw_in_timeline')
)->orderBy($order->value, OrderSortingType::DESC->value);
}
}
4 changes: 3 additions & 1 deletion app/Actions/RSS/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public function do(): Collection
/** @var Collection<int,Photo> $photos */
$photos = $this->photoQueryPolicy
->applySearchabilityFilter(
Photo::query()->with(['album', 'owner', 'size_variants', 'size_variants.sym_links'])
query: Photo::query()->with(['album', 'owner', 'size_variants', 'size_variants.sym_links']),
origin: null,
include_nsfw: !Configs::getValueAsBool('hide_nsfw_in_rss')
)
->where('photos.created_at', '>=', $nowMinus)
->limit($rss_max)
Expand Down
6 changes: 4 additions & 2 deletions app/Actions/Search/PhotoSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\DTO\PhotoSortingCriterion;
use App\Eloquent\FixedQueryBuilder;
use App\Models\Album;
use App\Models\Configs;
use App\Models\Extensions\SortingDecorator;
use App\Models\Photo;
use App\Policies\PhotoQueryPolicy;
Expand Down Expand Up @@ -50,8 +51,9 @@ public function query(array $terms): Collection
public function sqlQuery(array $terms, ?Album $album = null): Builder
{
$query = $this->photoQueryPolicy->applySearchabilityFilter(
Photo::query()->with(['album', 'size_variants', 'size_variants.sym_links']),
$album
query: Photo::query()->with(['album', 'size_variants', 'size_variants.sym_links']),
origin: $album,
include_nsfw: !Configs::getValueAsBool('hide_nsfw_in_search')
);

foreach ($terms as $term) {
Expand Down
13 changes: 13 additions & 0 deletions app/Contracts/Http/Requests/HasTimelineAlbum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Contracts\Http\Requests;

use App\Enum\TimelineAlbumGranularity;

interface HasTimelineAlbum
{
/**
* @return TimelineAlbumGranularity|null
*/
public function album_timeline(): ?TimelineAlbumGranularity;
}
13 changes: 13 additions & 0 deletions app/Contracts/Http/Requests/HasTimelinePhoto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Contracts\Http\Requests;

use App\Enum\TimelinePhotoGranularity;

interface HasTimelinePhoto
{
/**
* @return TimelinePhotoGranularity|null
*/
public function photo_timeline(): ?TimelinePhotoGranularity;
}
2 changes: 2 additions & 0 deletions app/Contracts/Http/Requests/RequestAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class RequestAttribute
public const ALBUM_SORTING_COLUMN_ATTRIBUTE = 'album_sorting_column';
public const ALBUM_SORTING_ORDER_ATTRIBUTE = 'album_sorting_order';
public const ALBUM_PHOTO_LAYOUT = 'photo_layout';
public const ALBUM_TIMELINE_ALBUM = 'album_timeline';
public const ALBUM_TIMELINE_PHOTO = 'photo_timeline';

public const PERMISSION_ID = 'perm_id';
public const IS_COMPACT_ATTRIBUTE = 'is_compact';
Expand Down
15 changes: 15 additions & 0 deletions app/Enum/TimelineAlbumGranularity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Enum;

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

namespace App\Enum;

/**
* Defines the possible granularities for photo timelines.
*/
enum TimelinePhotoGranularity: string
{
case DEFAULT = 'default';
case DISABLED = 'disabled';
case YEAR = 'year';
case MONTH = 'month';
case DAY = 'day';
case HOUR = 'hour';
}
4 changes: 4 additions & 0 deletions app/Http/Controllers/Gallery/AlbumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public function updateAlbum(UpdateAlbumRequest $request, SetHeader $setHeader):
$album->album_sorting = $request->albumSortingCriterion();
$album->photo_layout = $request->photoLayout();

$album->album_timeline = $request->album_timeline();
$album->photo_timeline = $request->photo_timeline();

$album = $setHeader->do(
album: $album,
is_compact: $request->is_compact(),
Expand All @@ -133,6 +136,7 @@ public function updateTagAlbum(UpdateTagAlbumRequest $request): EditableBaseAlbu
$album->copyright = $request->copyright();
$album->photo_sorting = $request->photoSortingCriterion();
$album->photo_layout = $request->photoLayout();
$album->photo_timeline = $request->photo_timeline();
$album->save();

return EditableBaseAlbumResource::fromModel($album);
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/Gallery/FrameController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ private function loadPhoto(AbstractAlbum|null $album, int $retries = 5): ?Photo

// default query
if ($album === null) {
$query = $this->photoQueryPolicy->applySearchabilityFilter(Photo::query()->with(['album', 'size_variants', 'size_variants.sym_links']));
$query = $this->photoQueryPolicy->applySearchabilityFilter(
query: Photo::query()->with(['album', 'size_variants', 'size_variants.sym_links']),
origin: null,
include_nsfw: !Configs::getValueAsBool('hide_nsfw_in_frame')
);
} else {
$query = $album->photos()->with(['album', 'size_variants', 'size_variants.sym_links']);
}
Expand Down
40 changes: 40 additions & 0 deletions app/Http/Controllers/Gallery/TimelineController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Http\Controllers\Gallery;

use App\Actions\Photo\Timeline;
use App\Http\Requests\Photo\GetTimelineRequest;
use App\Http\Resources\Timeline\InitResource;
use App\Http\Resources\Timeline\TimelineResource;
use App\Models\Configs;
use App\Models\Photo;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Routing\Controller;
use Spatie\LaravelData\Data;

/**
* Controller responsible for the Timeline data.
*/
class TimelineController extends Controller
{
public function __invoke(GetTimelineRequest $request, Timeline $timeline): Data
{
/** @var LengthAwarePaginator<Photo> $photoResults */
/** @disregard P1013 Undefined method withQueryString() (stupid intelephense) */
$photoResults = $timeline->do()->paginate(Configs::getValueAsInt('timeline_photos_pagination_limit'));

return TimelineResource::fromData($photoResults);
}

/**
* Return init Search.
*
* @param GetTimelineRequest $request
*
* @return InitResource
*/
public function init(GetTimelineRequest $request): Data
{
return new InitResource();
}
}
16 changes: 15 additions & 1 deletion app/Http/Requests/Album/UpdateAlbumRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use App\Contracts\Http\Requests\HasPhoto;
use App\Contracts\Http\Requests\HasPhotoLayout;
use App\Contracts\Http\Requests\HasPhotoSortingCriterion;
use App\Contracts\Http\Requests\HasTimelineAlbum;
use App\Contracts\Http\Requests\HasTimelinePhoto;
use App\Contracts\Http\Requests\HasTitle;
use App\Contracts\Http\Requests\RequestAttribute;
use App\Contracts\Models\AbstractAlbum;
Expand All @@ -22,6 +24,8 @@
use App\Enum\LicenseType;
use App\Enum\OrderSortingType;
use App\Enum\PhotoLayoutType;
use App\Enum\TimelineAlbumGranularity;
use App\Enum\TimelinePhotoGranularity;
use App\Http\Requests\BaseApiRequest;
use App\Http\Requests\Traits\HasAlbumSortingCriterionTrait;
use App\Http\Requests\Traits\HasAlbumTrait;
Expand All @@ -33,19 +37,22 @@
use App\Http\Requests\Traits\HasPhotoLayoutTrait;
use App\Http\Requests\Traits\HasPhotoSortingCriterionTrait;
use App\Http\Requests\Traits\HasPhotoTrait;
use App\Http\Requests\Traits\HasTimelineAlbumTrait;
use App\Http\Requests\Traits\HasTimelinePhotoTrait;
use App\Http\Requests\Traits\HasTitleTrait;
use App\Models\Album;
use App\Models\Photo;
use App\Policies\AlbumPolicy;
use App\Rules\CopyrightRule;
use App\Rules\DescriptionRule;
use App\Rules\EnumRequireSupportRule;
use App\Rules\RandomIDRule;
use App\Rules\TitleRule;
use Illuminate\Support\Facades\Gate;
use Illuminate\Validation\Rules\Enum;
use Illuminate\Validation\ValidationException;

class UpdateAlbumRequest extends BaseApiRequest implements HasAlbum, HasTitle, HasDescription, HasLicense, HasPhotoSortingCriterion, HasAlbumSortingCriterion, HasCopyright, HasPhoto, HasCompactBoolean, HasPhotoLayout
class UpdateAlbumRequest extends BaseApiRequest implements HasAlbum, HasTitle, HasDescription, HasLicense, HasPhotoSortingCriterion, HasAlbumSortingCriterion, HasCopyright, HasPhoto, HasCompactBoolean, HasPhotoLayout, HasTimelineAlbum, HasTimelinePhoto
{
use HasAlbumTrait;
use HasLicenseTrait;
Expand All @@ -58,6 +65,8 @@ class UpdateAlbumRequest extends BaseApiRequest implements HasAlbum, HasTitle, H
use HasAlbumSortingCriterionTrait;
use HasCopyrightTrait;
use HasPhotoLayoutTrait;
use HasTimelineAlbumTrait;
use HasTimelinePhotoTrait;

public function authorize(): bool
{
Expand Down Expand Up @@ -92,6 +101,8 @@ public function rules(): array
RequestAttribute::COPYRIGHT_ATTRIBUTE => ['present', 'nullable', new CopyrightRule()],
RequestAttribute::IS_COMPACT_ATTRIBUTE => ['required', 'boolean'],
RequestAttribute::HEADER_ID_ATTRIBUTE => ['present', new RandomIDRule(true)],
RequestAttribute::ALBUM_TIMELINE_ALBUM => ['present', 'nullable', new Enum(TimelineAlbumGranularity::class), new EnumRequireSupportRule(TimelinePhotoGranularity::class, [TimelinePhotoGranularity::DEFAULT, TimelinePhotoGranularity::DISABLED], $this->verify)],
RequestAttribute::ALBUM_TIMELINE_PHOTO => ['present', 'nullable', new Enum(TimelinePhotoGranularity::class), new EnumRequireSupportRule(TimelinePhotoGranularity::class, [TimelinePhotoGranularity::DEFAULT, TimelinePhotoGranularity::DISABLED], $this->verify)],
];
}

Expand Down Expand Up @@ -129,6 +140,9 @@ protected function processValidatedValues(array $values, array $files): void

$this->aspectRatio = AspectRatioType::tryFrom($values[RequestAttribute::ALBUM_ASPECT_RATIO_ATTRIBUTE]);
$this->photoLayout = PhotoLayoutType::tryFrom($values[RequestAttribute::ALBUM_PHOTO_LAYOUT]);
$this->album_timeline = TimelineAlbumGranularity::tryFrom($values[RequestAttribute::ALBUM_TIMELINE_ALBUM]);
$this->photo_timeline = TimelinePhotoGranularity::tryFrom($values[RequestAttribute::ALBUM_TIMELINE_PHOTO]);

$this->copyright = $values[RequestAttribute::COPYRIGHT_ATTRIBUTE];

$this->is_compact = static::toBoolean($values[RequestAttribute::IS_COMPACT_ATTRIBUTE]);
Expand Down
Loading

0 comments on commit 3a1f861

Please sign in to comment.