More refactor for albums

Signed-off-by: Varun Patil <varunpatil@ucla.edu>
pull/563/head
Varun Patil 2023-03-24 18:09:18 -07:00
parent 68a1366f4e
commit 8db1ce0350
5 changed files with 27 additions and 7 deletions

View File

@ -54,7 +54,7 @@ return [
['name' => 'Folders#sub', 'url' => '/api/folders/sub', 'verb' => 'GET'],
['name' => 'Clusters#list', 'url' => '/api/clusters/{backend}', 'verb' => 'GET'],
['name' => 'Clusters#preview', 'url' => '/api/clusters/{backend}/preview/{name}', 'verb' => 'GET'],
['name' => 'Clusters#preview', 'url' => '/api/clusters/{backend}/preview', 'verb' => 'GET'],
['name' => 'Clusters#download', 'url' => '/api/clusters/{backend}/download', 'verb' => 'POST'],
['name' => 'Tags#set', 'url' => '/api/tags/set/{id}', 'verb' => 'PATCH'],

View File

@ -112,7 +112,7 @@ class AlbumsBackend extends Backend
public static function getClusterId(array $cluster)
{
return $cluster['album_id'];
return $cluster['cluster_id'];
}
public function getPhotos(string $name, ?int $limit = null): array
@ -129,6 +129,11 @@ class AlbumsBackend extends Backend
return $this->albumsQuery->getAlbumPhotos($id, $limit) ?? [];
}
public function sortPhotosForPreview(array &$photos)
{
// Do nothing, the photos are already sorted by added date desc
}
private function getUID(): string
{
return Util::isLoggedIn() ? Util::getUID() : '---';

View File

@ -58,6 +58,7 @@ class AlbumsQuery
// Post process
foreach ($albums as &$row) {
$row['cluster_id'] = $row['user'].'/'.$row['name'];
$row['album_id'] = (int) $row['album_id'];
$row['created'] = (int) $row['created'];
$row['last_added_photo'] = (int) $row['last_added_photo'];
@ -210,11 +211,25 @@ class AlbumsQuery
public function getAlbumPhotos(int $albumId, ?int $limit)
{
$query = $this->connection->getQueryBuilder();
$query->select('file_id')->from('photos_albums_files', 'paf')->where(
$query->expr()->eq('album_id', $query->createNamedParameter($albumId, IQueryBuilder::PARAM_INT))
);
// SELECT all files
$query->select('file_id')->from('photos_albums_files', 'paf');
// WHERE they are in this album
$query->where($query->expr()->eq('album_id', $query->createNamedParameter($albumId, IQueryBuilder::PARAM_INT)));
// AND in the filecache
$query->innerJoin('paf', 'filecache', 'fc', $query->expr()->eq('fc.fileid', 'paf.file_id'));
// Do not check if these files are indexed in memories
// This is since this function is called for downloads
// so funky things might happen if non-indexed files were
// added throught the Photos app
// ORDER by the id of the paf i.e. the order in which they were added
$query->orderBy('paf.album_file_id', 'DESC');
// LIMIT the results
if (null !== $limit) {
$query->setMaxResults($limit);
}

View File

@ -120,7 +120,7 @@ export default defineComponent({
}
if (this.face) {
const name = this.face.name || this.face.cluster_id.toString();
const name = String(this.face.name || this.face.cluster_id);
const user = this.face.user_id;
return { name: this.data.cluster_type, params: { name, user } };
}

View File

@ -102,7 +102,7 @@ export class API {
}
static CLUSTER_PREVIEW(backend: ClusterTypes, name: string | number) {
return gen(`${BASE}/clusters/${backend}/preview/{name}`, { name });
return API.Q(gen(`${BASE}/clusters/${backend}/preview`), { name });
}
static ARCHIVE(fileid: number) {