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

Consistent JSON API incl. Proper Handling of Errors (2nd half of big refactoring) #1217

Merged
merged 540 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
540 commits
Select commit Hold shift + click to select a range
49bc87b
More clean-up work.
nagmat84 Dec 20, 2021
728394b
Fixed some left overs which still assumed numeric IDs
nagmat84 Dec 21, 2021
b24fcb1
Merge branch 'refactor_photo_model' into consistent_json_api
nagmat84 Dec 21, 2021
9829cb7
Added some comments.
nagmat84 Dec 21, 2021
c824c0f
Clean up or remaining controllers
nagmat84 Dec 21, 2021
0fb9b3d
Replaced unspecific exceptions by custom ones.
nagmat84 Dec 21, 2021
369df5b
Fixed a fatal parsing error.
nagmat84 Dec 22, 2021
252ba66
Turned Thumb into a DTO.
nagmat84 Dec 22, 2021
e0cec9e
Middlewares cleaned up (in particular: delete unnecessarities)
nagmat84 Dec 22, 2021
7992c1a
Removed unused ReadCheck.
nagmat84 Dec 23, 2021
213c5b5
Fixed checks for sharing.
nagmat84 Dec 23, 2021
17da7b8
Fixed authorization of photo rotation and dropped unnessary UploadCheck
nagmat84 Dec 23, 2021
a5ed073
Cleaned up authorization for user controller.
nagmat84 Dec 23, 2021
e3f742f
Removed "login" middleware from WebAuth and dropped unnessery login m…
nagmat84 Dec 23, 2021
fdb9132
Consolidated capitalization.
nagmat84 Dec 23, 2021
7f26ebc
Suppress false IDE warnings
nagmat84 Dec 24, 2021
bae39f7
Consolidated middleware to check installation status
nagmat84 Dec 24, 2021
430a252
Made routes and route files more systematic
nagmat84 Dec 24, 2021
25a8985
Sorted routes into their correct groups.
nagmat84 Dec 24, 2021
f6d4e71
Repaired diagnostic.
nagmat84 Dec 25, 2021
9505455
Fixed JSON in test.
nagmat84 Dec 25, 2021
efefd8c
Fixed a bug in middleware InstallationStatus and ensured that it neve…
nagmat84 Dec 25, 2021
cd55cbe
Fixed check IsInstalled: Must not rely on `installed.log`.
nagmat84 Dec 25, 2021
60be7bb
Added 'admin' middlewware to routes in 'api-admin'.
nagmat84 Dec 25, 2021
0c53b93
Fixed UseController and UserTest.
nagmat84 Dec 25, 2021
bbb1c39
Fixed routes for albums and photos.
nagmat84 Dec 25, 2021
00472aa
Fixed content problem for archive
nagmat84 Dec 26, 2021
6c4199c
Fixed URLs in tests
nagmat84 Dec 26, 2021
afd1741
Added requirement to accept any content to achive API calls.
nagmat84 Dec 26, 2021
41562fe
Made exception handler content aware.
nagmat84 Dec 27, 2021
1b57461
Moved redirection and direct HTML responses out of middleware
nagmat84 Dec 27, 2021
9de6c7d
Fixed two silly bugs
nagmat84 Dec 27, 2021
119263b
First fixes of front-end.
nagmat84 Dec 27, 2021
70edf7e
Fix the restoring of explicit covers of albums
kamil4 Dec 30, 2021
cc828ae
Fixed a bug wrt. to skip duplicates.
nagmat84 Dec 30, 2021
de78bd7
Fixed photo uploading.
nagmat84 Dec 30, 2021
14db3f7
Added updated front-end.
nagmat84 Dec 31, 2021
dd5c36e
Fixed bug which denied non-admin users with the upload right to creat…
nagmat84 Dec 31, 2021
389275f
Fixed bug such that admin sees thumbnails of albums of other users
nagmat84 Dec 31, 2021
cb6f458
Fixed grouping by owner for shared albums.
nagmat84 Dec 31, 2021
3cf7e3c
Apply suggestions from code review
nagmat84 Dec 31, 2021
2cb4595
Merge branch 'refactor_photo_model' into consistent_json_api
nagmat84 Dec 31, 2021
8fc73d5
Fixed a bug in the view controller.
nagmat84 Dec 31, 2021
c441013
Added redirection support for legacy IDs.
nagmat84 Dec 31, 2021
1152870
Fixed redirection test and cleanup of redirection code.
nagmat84 Jan 1, 2022
22078e1
Added support for translation of legacy IDs by front-end
nagmat84 Jan 1, 2022
fb2fee1
Synced with @kamil4's recent changes to the front-end
nagmat84 Jan 1, 2022
a48ed6c
Made search results being sorted
nagmat84 Jan 1, 2022
d657699
Merge branch 'refactor_photo_model' into consistent_json_api
nagmat84 Jan 1, 2022
51c8114
Use our own template to report exceptions.
nagmat84 Jan 1, 2022
cc03a7b
Work on import from server.
nagmat84 Jan 2, 2022
92516d0
Synced @kamil4's changes of the front-end.
nagmat84 Jan 2, 2022
371a1bd
Fixed issue with sorting of public albums wrt. to anonymous users.
nagmat84 Jan 2, 2022
a14fecf
Fixed bug which prevented uploading to root/unsorted.
nagmat84 Jan 2, 2022
f5cbf4e
Fixed bug which leaked unsorted photos.
nagmat84 Jan 2, 2022
f60a708
Upgrade to timestamps with microsecond resolution.
nagmat84 Jan 2, 2022
2bcec44
Workaround for a silly Laravel bug in the migration.
nagmat84 Jan 3, 2022
0068b50
Added id/time-conversion and made migration fancy
nagmat84 Jan 3, 2022
8c8129d
Set creation time of photos after upload not after processing.
nagmat84 Jan 3, 2022
ace7fa9
Fixed tests due to more accurate timestamps
nagmat84 Jan 3, 2022
38a086c
Allow null albumID for setAlbum and duplicate
kamil4 Jan 3, 2022
48e1886
fix timestamps for page_content
ildyria Jan 3, 2022
ff0bdbf
Fixed copy-to for root album.
nagmat84 Jan 3, 2022
4c6dc31
Fixed foreign constraint when a cover photo is deleted.
nagmat84 Jan 3, 2022
44384bf
Allow unprivilege users to unset album covers (i.e. use the `null` ph…
nagmat84 Jan 3, 2022
b55a9d1
Made migration a little bit more robust wrt. to a former Lychee bug
nagmat84 Jan 3, 2022
3784b71
Fixed test case for photo duplication.
nagmat84 Jan 3, 2022
5290adb
Allow uploading to the Recent smart album
kamil4 Jan 3, 2022
3b5dc1c
Clean up the mess left by the front end
kamil4 Jan 3, 2022
4e9b569
Support null albumID
kamil4 Jan 4, 2022
c50b2d6
Fixed missing sorting in case album uses default sorting.
nagmat84 Jan 4, 2022
082b688
Revert "Clean up the mess left by the front end"
nagmat84 Jan 4, 2022
de773d7
Synced front-end
nagmat84 Jan 4, 2022
904d4d2
Support to translate all legacy model IDs in a single request.
nagmat84 Jan 4, 2022
01960b2
Sync with front-end
nagmat84 Jan 4, 2022
cdf3a81
Only use SORT_NATURAL on string columns
kamil4 Jan 4, 2022
af9cb7c
Don't serialize owner_id
kamil4 Jan 5, 2022
3a269fd
Support serializing default sorting and hiding it
kamil4 Jan 5, 2022
c0502ed
Fix findWhereIDsIn for smart albums
kamil4 Jan 5, 2022
a6111e1
Restore checking downloadable flag of parent album
kamil4 Jan 5, 2022
3418285
Don't serialize owner_id of photos either
kamil4 Jan 5, 2022
eb083bd
Fix the serialization of sorting info
kamil4 Jan 5, 2022
be1035d
Turn empty album description into null
kamil4 Jan 5, 2022
e211b10
Use the same sorting as Top
kamil4 Jan 5, 2022
33eeff5
Fix #1187
kamil4 Jan 5, 2022
60b1706
Synced front-end
nagmat84 Jan 6, 2022
43d4070
Removed unnessary Laravel mutators for sortigng
nagmat84 Jan 6, 2022
572de1e
Fixed some type cast warnings
nagmat84 Jan 6, 2022
17f1de7
Fixed wrong configuration option in `getEffictiveSorting[Column|Order]`
nagmat84 Jan 6, 2022
d4172e3
Fix a crash with skip_duplicates enabled
kamil4 Jan 6, 2022
3335fcc
Made album deletion mor robust.
nagmat84 Jan 6, 2022
175430d
Fixed album deletion bug.
nagmat84 Jan 6, 2022
934930a
Fixed a bug wrt. to skip duplicates.
nagmat84 Dec 30, 2021
69a8086
Fix skip_duplicates for import from server
kamil4 Jan 6, 2022
48ca754
Merge branch 'refactor_photo_model' into consistent_json_api
nagmat84 Jan 6, 2022
e3c34f7
Merge branch 'refactor_photo_model' into consistent_json_api
nagmat84 Jan 6, 2022
1c33efc
Fix ownership for album moves and merges
kamil4 Jan 6, 2022
9b92a7a
Fixed a bug when creating the tree of albums.
nagmat84 Jan 7, 2022
4459a25
Fixed move-to and merge operations.
nagmat84 Jan 7, 2022
e05ec14
Merge branch 'refactor_photo_model' into consistent_json_api
nagmat84 Jan 7, 2022
b781bdd
Synced front-end.
nagmat84 Jan 7, 2022
72079fa
Fixed silly syntax error
nagmat84 Jan 7, 2022
7f6bc9b
Synced front-end
nagmat84 Jan 7, 2022
f165013
Fixed Diagnostics and Logs.
nagmat84 Jan 8, 2022
007f9b5
Fixed GET-request for archives.
nagmat84 Jan 8, 2022
6570137
Tests consistently use `postJson`
nagmat84 Jan 8, 2022
b2b5e5e
Sorted routes alphabetically.
nagmat84 Jan 8, 2022
94c7881
Cleaned up some of the mess around installation/upgrade/migration.
nagmat84 Jan 8, 2022
fab177c
Always return proper and complete HTML for views.
nagmat84 Jan 8, 2022
633b4c6
Receive arrays as arrays (avoid stringification of arrays)
nagmat84 Jan 8, 2022
9304459
Fixed a comment.
nagmat84 Jan 9, 2022
65d6bb4
Fixed API wrt. to front-end and synced front-end
nagmat84 Jan 29, 2022
d754018
Proper PHP 8 constants in Configs
nagmat84 Jan 30, 2022
f37c1c8
Merge branch 'master' into consistent_json_api
nagmat84 Feb 5, 2022
13cb477
Adopted unit tests to pass proper arrays and content type.
nagmat84 Feb 6, 2022
5d33548
Fixed exception handler for installation.
nagmat84 Feb 6, 2022
ae20fd0
Fixed access rights to diagnostics
nagmat84 Feb 6, 2022
025a4bd
Fixed silly oversight in middleware.
nagmat84 Feb 6, 2022
9c75836
Removed unnecessary and problematic route.
nagmat84 Feb 6, 2022
195fb44
Fixed init configuration returned by session controller.
nagmat84 Feb 6, 2022
6fb9d3c
Fixed achive for albums and photos
nagmat84 Feb 6, 2022
60f8cf7
Synced front-end
nagmat84 Feb 6, 2022
10884f9
Another silly bug.
nagmat84 Feb 6, 2022
5d7c461
Added forgotten dot `.` in array validation rules.
nagmat84 Feb 6, 2022
b34d87f
Tags are transmitted as proper arrays.
nagmat84 Feb 6, 2022
c578485
Sync front-end
nagmat84 Feb 11, 2022
79567b7
Merge branch 'master' into consistent_json_api
nagmat84 Feb 11, 2022
39548e6
Added authorization method for already loaded album model
nagmat84 Feb 11, 2022
1eca584
Request to add album loads parent model early
nagmat84 Feb 11, 2022
0181d9c
Added authorization method for already loaded album model
nagmat84 Feb 11, 2022
aacda8d
Request to archive album loads model early
nagmat84 Feb 11, 2022
de640a4
Added authorization method for already loaded album model
nagmat84 Feb 12, 2022
dfa0faf
Request to delete albums loads model early
nagmat84 Feb 12, 2022
d133e63
Request to get position data of albums loads model early
nagmat84 Feb 12, 2022
3e28605
Cleaned up APIBaseRequest
nagmat84 Feb 12, 2022
4eda32b
Merge and Move album request load models eagerly
nagmat84 Feb 12, 2022
67fe242
Added authorization method for already loaded photo model
nagmat84 Feb 12, 2022
529d688
Request to set album cover loads model early
nagmat84 Feb 12, 2022
619234e
Request to set album access, description, license, nsfw state load mo…
nagmat84 Feb 12, 2022
0f65926
All album related requests load models eagerly.
nagmat84 Feb 12, 2022
f5daace
Some fixes for bugs identified by automatic testing.
nagmat84 Feb 12, 2022
e87e7e6
All import related requests load models eagerly.
nagmat84 Feb 15, 2022
81d439d
Add photo request loads models eagerly.
nagmat84 Feb 15, 2022
722e466
Archive photo request loads models eagerly.
nagmat84 Feb 15, 2022
6e40fac
Added authorization method for already loaded photo model
nagmat84 Feb 16, 2022
d79fb7d
Duplicate photo request loads models eagerly.
nagmat84 Feb 16, 2022
5f0d83a
Duplicate, get and move photo request load models eagerly.
nagmat84 Feb 16, 2022
30fde70
Delete photo request loads models eagerly.
nagmat84 Feb 16, 2022
c751147
Rotate photo request loads models eagerly.
nagmat84 Feb 17, 2022
45979d0
All photo requests load models eagerly.
nagmat84 Feb 17, 2022
7d0d8da
View photo request loads model eagerly.
nagmat84 Feb 19, 2022
c5f6eb9
User requests load models eagerly.
nagmat84 Feb 19, 2022
8911d46
Fixed type error
nagmat84 Feb 19, 2022
73f589d
Fixed some bugs
nagmat84 Feb 19, 2022
c065d73
Added 404 tests
nagmat84 Feb 19, 2022
a77a185
Clean up of method names.
nagmat84 Feb 19, 2022
7121401
Clean up of exception messages.
nagmat84 Feb 19, 2022
8238cf1
Fixed HTTP result code for the unauthenticated case.
nagmat84 Feb 19, 2022
864482c
Fixed bug with wrong URL query parameter `p`
nagmat84 Feb 19, 2022
c31c955
Synced front-end
nagmat84 Feb 19, 2022
84d4ad0
Fixed password exception.
nagmat84 Feb 19, 2022
cc45fa9
Synced front-end.
nagmat84 Feb 19, 2022
a729498
Fixed search and synced front-end.
nagmat84 Feb 20, 2022
7e7672d
Split smart and tag albums.
nagmat84 Feb 20, 2022
6d57a10
Synced front-end
nagmat84 Feb 20, 2022
701dfcc
Improved handling of sorting criterions
nagmat84 Feb 20, 2022
0dbb946
Fixed Lychee exception.
nagmat84 Feb 21, 2022
ef86550
Fixed import from URL/dropbox and synced front-end.
nagmat84 Feb 21, 2022
f40bfea
Import/Exec uses proper exceptions now.
nagmat84 Feb 24, 2022
6402906
Added report function
nagmat84 Feb 24, 2022
ff5f6c0
Cleaned up report function.
nagmat84 Feb 25, 2022
1140a98
Use report function of global handler during import.
nagmat84 Feb 25, 2022
fe24f4f
Removed a lot of explicit log commands and added exceptions to image …
nagmat84 Feb 25, 2022
7c035dd
Removed friendly model name.
nagmat84 Feb 26, 2022
06bb716
Status reports for streamed response and synced front-end.
nagmat84 Feb 26, 2022
78fcebe
Removed an annoying log entry.
nagmat84 Feb 26, 2022
83a6e63
Slighlty improved deletion of albums.
nagmat84 Feb 26, 2022
81ca3b6
Added dummy source map file to avoid exception logs in Lychee.
nagmat84 Feb 26, 2022
36ceb4e
Improved exception if base album is not found.
nagmat84 Feb 26, 2022
edae999
Removed one issue reported by SonarCloud
nagmat84 Feb 27, 2022
f3eaf28
Merge branch 'master' into consistent_json_api
nagmat84 Feb 27, 2022
27fca0d
Update app/Actions/Diagnostics/Configuration.php
nagmat84 Mar 13, 2022
f4420c1
Update app/Actions/Update/Apply.php
nagmat84 Mar 13, 2022
cf98fd1
Update resources/views/logs/list.blade.php
nagmat84 Mar 13, 2022
58160ad
Update app/Actions/Import/Exec.php
nagmat84 Mar 13, 2022
884ef27
Update app/Actions/Import/Exec.php
nagmat84 Mar 13, 2022
bb40f19
Synced front-end
nagmat84 Mar 13, 2022
f8c1386
Added middleware for trusted proxies again.
nagmat84 Mar 13, 2022
b91c95d
Renamed "setPublic" to "setProtectionPolicy" and synced frontend.
nagmat84 Mar 13, 2022
dfda5f4
Renamed "setStar" to "toggleStar".
nagmat84 Mar 13, 2022
bd7b248
Removed all unnecessary actions which were bloated wrappers around a …
nagmat84 Mar 13, 2022
a8927d0
Added reverse proxy configuration to .env file
nagmat84 Mar 16, 2022
028ce71
Merge branch 'master' into consistent_json_api
nagmat84 Mar 16, 2022
52891fe
Apply suggestions from code review
nagmat84 Mar 18, 2022
89a9483
Incorporated suggestions by @kamil4 from code review.
nagmat84 Mar 18, 2022
6e13c20
Update app/Http/Controllers/ImportController.php
nagmat84 Mar 19, 2022
c034f31
Rephrased a comment due to review by @kamil4.
nagmat84 Mar 19, 2022
0734243
Renamed method.
nagmat84 Mar 19, 2022
e1cec52
Fixed setNSWF due to review by @kamil4
nagmat84 Mar 19, 2022
15374da
Cleaned up toggleStar for photos.
nagmat84 Mar 19, 2022
9035bb5
Apply suggestions from code review
nagmat84 Mar 23, 2022
0e04784
Update app/Http/Middleware/MigrationStatus.php
nagmat84 Mar 23, 2022
5c7ae89
Apply suggestions from code review
nagmat84 Mar 24, 2022
5901299
Fixed comment as pointed out by @kamil4.
nagmat84 Mar 24, 2022
4935e50
Merge branch 'master' into consistent_json_api
nagmat84 Mar 24, 2022
1bb145d
Apply suggestions from code review
nagmat84 Mar 27, 2022
41f3c02
Apply suggestions from code review
nagmat84 Mar 28, 2022
7aa5bfd
Update app/Rules/AlbumIDListRule.php
nagmat84 Mar 28, 2022
4268452
Fixed an unnecessary type conversion and comment spotted by @kamil4.
nagmat84 Mar 28, 2022
2b24bb7
Sync of frontend.
nagmat84 Mar 31, 2022
e7c4fb8
Added PhotoResyncedException to AddDuplicateStrategy
nagmat84 Apr 9, 2022
a27a5e4
Ensure that Albums::get always returns a proper object for smart albums.
nagmat84 Apr 9, 2022
128c9b1
Added forgotten file
nagmat84 Apr 9, 2022
826f667
Synced frontend
nagmat84 Apr 9, 2022
308d757
Removed empty file.
nagmat84 Apr 9, 2022
081d24c
update composer to use nested-set:^6 instead of version 5
ildyria Apr 10, 2022
73a2194
Merge branch 'master' into consistent_json_api
nagmat84 Apr 10, 2022
3dd4233
Fixed a missing blank.
nagmat84 Apr 10, 2022
1cc7bc7
Disable HTTP content zipping only for specific URLs
nagmat84 Apr 12, 2022
cedfe3b
Merge branch 'master' into consistent_json_api
nagmat84 Apr 14, 2022
7bc1657
Synced front-end
nagmat84 Apr 16, 2022
077bc67
Fixed error handler part 1.
nagmat84 Apr 16, 2022
b3daac3
Put exception handler on steriods.
nagmat84 Apr 16, 2022
da561cb
Some minor fixes due to review comments.
nagmat84 Apr 17, 2022
d5c7d2f
Added a DTO for PositionData
nagmat84 Apr 17, 2022
2c556fe
Created DTO AlbumTree as suggested by @kamil4
nagmat84 Apr 17, 2022
a7d552f
Fixed some IDE complains about wrong annotations for exceptions
nagmat84 Apr 17, 2022
63766a2
Fixed settings and synced frontend
nagmat84 Apr 17, 2022
324188c
Merge branch 'master' into consistent_json_api
nagmat84 Apr 17, 2022
33baac2
Make custom `toJson` clear the error message.
nagmat84 Apr 7, 2022
31f93f7
Merge branch 'master' into consistent_json_api
nagmat84 Apr 23, 2022
84a08da
Fix github functions.
nagmat84 Apr 24, 2022
0398a8f
Fixed JsonRequestFunctions
nagmat84 Apr 24, 2022
6e38059
Added a second, potential error message to the unit tests.
nagmat84 Apr 25, 2022
145a354
Merge branch 'master' into consistent_json_api
nagmat84 Apr 25, 2022
8c6e3fc
Fixed some already fixed errors again (probably a failed merge).
nagmat84 Apr 25, 2022
6c99d6a
Fixed translation of legacy IDs
nagmat84 Apr 25, 2022
85b42c4
Sync of frontend.
nagmat84 Apr 25, 2022
aa74612
Merge branch 'master' into consistent_json_api
nagmat84 Apr 27, 2022
e7397b3
Fixed detection of expired sessions.
nagmat84 Apr 27, 2022
0cf4de9
Synced front-end after @kamil4's latest changes.
nagmat84 Apr 27, 2022
9cea54a
Added a dedicated exception for required password.
nagmat84 Apr 28, 2022
40bfc52
Merge branch 'master' into consistent_json_api
nagmat84 Apr 28, 2022
75973c6
Update app/Exceptions/Handler.php
nagmat84 Apr 29, 2022
cf46b55
Put search results into a special `SearchAlbum`
nagmat84 Apr 30, 2022
9fd78ac
Merge branch 'master' into consistent_json_api
nagmat84 Apr 30, 2022
5ae6da5
Synced frontend
nagmat84 May 1, 2022
4e22447
Synced frontend again.
nagmat84 May 1, 2022
67fd61f
Synced sub-module after merge into master
nagmat84 May 3, 2022
24559fa
Merge branch 'master' into consistent_json_api
nagmat84 May 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,10 @@ PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

# The trusted proxies if Lychee is behind a reverse proxy
# Accepted values:
# - `null`: no proxy
# - `*`: any proxy
# - <ip address>[,<ip address>]: a comma-seperated list of IP addresses
TRUSTED_PROXIES=null
7 changes: 7 additions & 0 deletions .env.homestead
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

# The trusted proxies if Lychee is behind a reverse proxy
# Accepted values:
# - `null`: no proxy
# - `*`: any proxy
# - <ip address>[,<ip address>]: a comma-seperated list of IP addresses
TRUSTED_PROXIES=null
117 changes: 68 additions & 49 deletions app/Actions/Album/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
namespace App\Actions\Album;

use App\Contracts\AbstractAlbum;
use App\Contracts\BaseAlbum;
use App\Exceptions\Internal\FrameworkException;
use App\Facades\AccessControl;
use App\Facades\Helpers;
use App\Models\Album;
use App\Models\Configs;
use App\Models\Logs;
use App\Models\Extensions\BaseAlbum;
use App\Models\Photo;
use App\Models\TagAlbum;
use App\SmartAlbums\BaseSmartAlbum;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Support\Collection;
use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\HttpFoundation\StreamedResponse;
Expand All @@ -29,16 +30,24 @@ class Archive extends Action
'<', '>', ':', '"', '/', '\\', '|', '?', '*',
];

protected ExceptionHandler $exceptionHandler;

public function __construct()
{
parent::__construct();
$this->exceptionHandler = resolve(ExceptionHandler::class);
}

/**
* @param array $albumIDs
* @param Collection<AbstractAlbum> $albums
*
* @return StreamedResponse
*
* @throws FrameworkException
*/
public function do(array $albumIDs): StreamedResponse
public function do(Collection $albums): StreamedResponse
{
$albums = $this->albumFactory->findWhereIDsIn($albumIDs);

$response = new StreamedResponse(function () use ($albums) {
$responseGenerator = function () use ($albums) {
$options = new \ZipStream\Option\Archive();
$options->setEnableZip64(Configs::get_value('zip64', '1') === '1');
$zip = new ZipStream(null, $options);
Expand All @@ -50,22 +59,27 @@ public function do(array $albumIDs): StreamedResponse

// finish the zip stream
$zip->finish();
});

// Set file type and destination
$zipTitle = self::createZipTitle($albums);
$disposition = HeaderUtils::makeDisposition(
HeaderUtils::DISPOSITION_ATTACHMENT,
$zipTitle . '.zip',
mb_check_encoding($zipTitle, 'ASCII') ? '' : 'Album.zip'
);
$response->headers->set('Content-Type', 'application/x-zip');
$response->headers->set('Content-Disposition', $disposition);

// Disable caching
$response->headers->set('Cache-Control', 'no-cache, no-store, must-revalidate');
$response->headers->set('Pragma', 'no-cache');
$response->headers->set('Expires', '0');
};

try {
$response = new StreamedResponse($responseGenerator);
// Set file type and destination
$zipTitle = self::createZipTitle($albums);
$disposition = HeaderUtils::makeDisposition(
HeaderUtils::DISPOSITION_ATTACHMENT,
$zipTitle . '.zip',
mb_check_encoding($zipTitle, 'ASCII') ? '' : 'Album.zip'
);
$response->headers->set('Content-Type', 'application/x-zip');
$response->headers->set('Content-Disposition', $disposition);

// Disable caching
$response->headers->set('Cache-Control', 'no-cache, no-store, must-revalidate');
$response->headers->set('Pragma', 'no-cache');
$response->headers->set('Expires', '0');
} catch (\InvalidArgumentException $e) {
throw new FrameworkException('Symfony\'s response component', $e);
}

return $response;
}
Expand Down Expand Up @@ -154,43 +168,48 @@ private function compressAlbum(AbstractAlbum $album, array &$usedDirNames, ?stri
}

$usedFileNames = [];
// TODO: Ensure that the size variant `original` for each photo is eagerly loaded as it is needed below. This must be solved in close coordination with `ArchiveAlbumRequest`.
$photos = $album->photos;

/** @var Photo $photo */
foreach ($photos as $photo) {
// For photos in smart or tag albums, skip the ones that are not
// downloadable based on their actual parent album. The test for
// album_id == null shouldn't really be needed as all such photos
// in smart albums should be owned by the current user...
if (($album instanceof BaseSmartAlbum || $album instanceof TagAlbum) &&
!AccessControl::is_current_user($photo->owner_id) &&
!($photo->album_id == null ? $album->is_downloadable : $photo->album->is_downloadable)) {
continue;
}

$fullPath = $photo->size_variants->getOriginal()->full_path;
// Check if readable
if (!@is_readable($fullPath)) {
Logs::error(__METHOD__, __LINE__, 'Original photo missing: ' . $fullPath);
continue;
try {
// For photos in smart or tag albums, skip the ones that are not
// downloadable based on their actual parent album. The test for
// album_id == null shouldn't really be needed as all such photos
// in smart albums should be owned by the current user...
if (($album instanceof BaseSmartAlbum || $album instanceof TagAlbum) &&
!AccessControl::is_current_user_or_admin($photo->owner_id) &&
!($photo->album_id == null ? $album->is_downloadable : $photo->album->is_downloadable)) {
continue;
}

$fullPath = $photo->size_variants->getOriginal()->full_path;

// Set title for photo
$extension = Helpers::getExtension($fullPath, false);
$fileBaseName = $this->makeUnique(self::createValidTitle($photo->title), $usedFileNames);
$fileName = $fullNameOfDirectory . '/' . $fileBaseName . $extension;

// Reset the execution timeout for every iteration.
set_time_limit(ini_get('max_execution_time'));
$zip->addFileFromPath($fileName, $fullPath);
} catch (\Throwable $e) {
$this->exceptionHandler->report($e);
}

// Set title for photo
$extension = Helpers::getExtension($fullPath, false);
$fileBaseName = $this->makeUnique(self::createValidTitle($photo->title), $usedFileNames);
$fileName = $fullNameOfDirectory . '/' . $fileBaseName . $extension;

// Reset the execution timeout for every iteration.
set_time_limit(ini_get('max_execution_time'));
$zip->addFileFromPath($fileName, $fullPath);
}

// Recursively compress sub-albums
if ($album instanceof Album) {
$subDirs = [];
// TODO: For higher efficiency, ensure that the photos of each child album together with the original size variant are eagerly loaded.
$subAlbums = $album->children;
foreach ($subAlbums as $subAlbum) {
$this->compressAlbum($subAlbum, $subDirs, $fullNameOfDirectory, $zip);
try {
$this->compressAlbum($subAlbum, $subDirs, $fullNameOfDirectory, $zip);
} catch (\Throwable $e) {
$this->exceptionHandler->report($e);
}
}
}
}
Expand All @@ -207,6 +226,6 @@ private static function isArchivable(AbstractAlbum $album): bool
return
$album->is_downloadable ||
($album instanceof BaseSmartAlbum && AccessControl::is_logged_in()) ||
($album instanceof BaseAlbum && AccessControl::is_current_user($album->owner_id));
($album instanceof BaseAlbum && AccessControl::is_current_user_or_admin($album->owner_id));
}
}
31 changes: 15 additions & 16 deletions app/Actions/Album/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,45 @@

namespace App\Actions\Album;

use App\Exceptions\ModelDBException;
use App\Facades\AccessControl;
use App\Models\Album;

class Create extends Action
{
/**
* @param string $title
* @param string|null $parent_id
* @param string $title
* @param Album|null $parentAlbum
*
* @return Album
*
* @throws ModelDBException
*/
public function create(string $title, ?string $parent_id = null): Album
public function create(string $title, ?Album $parentAlbum): Album
{
$album = new Album();
$album->title = $title;
$this->set_parent($album, $parent_id);
if (!$album->save()) {
throw new \RuntimeException('could not persist album to DB');
}
$this->set_parent($album, $parentAlbum);
$album->save();

return $album;
}

/**
* Setups parent album on album structure.
*
* @param Album $album
* @param string|null $parent_id
* @param Album $album
* @param Album|null $parentAlbum
*/
private function set_parent(Album $album, ?string $parent_id): void
private function set_parent(Album $album, ?Album $parentAlbum): void
{
if ($parent_id !== null) {
/** @var Album $parent */
$parent = Album::query()->findOrFail($parent_id);
// Admin can add subalbums to other users' albums. Make sure that
if ($parentAlbum !== null) {
// Admin can add sub-albums to other users' albums. Make sure that
// the ownership stays with that user.
$album->owner_id = $parent->owner_id;
$album->owner_id = $parentAlbum->owner_id;
// Don't set attribute `parent_id` manually, but use specialized
// methods of the nested set `NodeTrait`.
$album->appendToNode($parent);
$album->appendToNode($parentAlbum);
} else {
$album->owner_id = AccessControl::id();
$album->makeRoot();
Expand Down
13 changes: 7 additions & 6 deletions app/Actions/Album/CreateTagAlbum.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Actions\Album;

use App\Exceptions\ModelDBException;
use App\Facades\AccessControl;
use App\Models\TagAlbum;

Expand All @@ -10,20 +11,20 @@ class CreateTagAlbum extends Action
/**
* Create a new smart album based on tags.
*
* @param string $title
* @param string $show_tags
* @param string $title
* @param string[] $show_tags
*
* @return TagAlbum
*
* @throws ModelDBException
*/
public function create(string $title, string $show_tags): TagAlbum
public function create(string $title, array $show_tags): TagAlbum
{
$album = new TagAlbum();
$album->title = $title;
$album->show_tags = $show_tags;
$album->owner_id = AccessControl::id();
if (!$album->save()) {
throw new \RuntimeException('could not persist album to DB');
}
$album->save();

return $album;
}
Expand Down
17 changes: 15 additions & 2 deletions app/Actions/Album/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace App\Actions\Album;

use App\Actions\Photo\Delete as PhotoDelete;
use App\Contracts\InternalLycheeException;
use App\Exceptions\Internal\QueryBuilderException;
use App\Exceptions\ModelDBException;
use App\Facades\AccessControl;
use App\Image\FileDeleter;
use App\Models\Album;
Expand Down Expand Up @@ -50,6 +53,8 @@ class Delete extends Action
* @param string[] $albumIDs the album IDs
*
* @return FileDeleter contains the collected files which became obsolete
*
* @throws ModelDBException
*/
public function do(array $albumIDs): FileDeleter
{
Expand Down Expand Up @@ -117,14 +122,22 @@ public function do(array $albumIDs): FileDeleter
})->delete();

return $fileDeleter;
} catch (\Exception $e) {
} catch (QueryBuilderException|InternalLycheeException $e) {
try {
// if anything goes wrong, don't leave the tree in an inconsistent state
Album::query()->fixTree();
} catch (\Throwable) {
// Sic! We cannot do anything about the inner exception
}
throw ModelDBException::create('albums', 'deleting', $e);
} catch (\InvalidArgumentException $e) {
try {
// if anything goes wrong, don't leave the tree in an inconsistent state
Album::query()->fixTree();
} catch (\Throwable) {
// Sic! We cannot do anything about the inner exception
}
throw $e;
assert(false, new \AssertionError('\InvalidArgumentException must not be thrown by ->where', $e->getCode(), $e));
}
}
}
Loading