frontend: route all photo queries through sidecar timeline proxy
- listPhotos → /api/sidecar/timeline (was /photos) - countPhotos → /api/sidecar/timeline (was /photos) - hasPhotosMatching → /api/sidecar/timeline (was /photos) - Sidecar handler forwards X-Count header for countPhotos() - Sidecar adjusts X-Count to reflect post-filtered count
This commit is contained in:
@@ -39,6 +39,10 @@ func handlePhotos(pp *ppClient) gin.HandlerFunc {
|
|||||||
|
|
||||||
// If the user has no BasePath (admin/empty), return as-is.
|
// If the user has no BasePath (admin/empty), return as-is.
|
||||||
if basePath == "" {
|
if basePath == "" {
|
||||||
|
// Forward PhotoPrism's X-Count header for countPhotos().
|
||||||
|
if count := resp.Header.Get("X-Count"); count != "" {
|
||||||
|
c.Header("X-Count", count)
|
||||||
|
}
|
||||||
c.JSON(http.StatusOK, photos)
|
c.JSON(http.StatusOK, photos)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -62,6 +66,8 @@ func handlePhotos(pp *ppClient) gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Forward X-Count header adjusted to the filtered count.
|
||||||
|
c.Header("X-Count", itoa(len(filtered)))
|
||||||
c.JSON(http.StatusOK, filtered)
|
c.JSON(http.StatusOK, filtered)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,7 +144,7 @@ export interface ListPhotosParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function listPhotos(params: ListPhotosParams = {}): Promise<PpPhoto[]> {
|
export async function listPhotos(params: ListPhotosParams = {}): Promise<PpPhoto[]> {
|
||||||
const { data } = await http.get<PpPhoto[]>('/photos', {
|
const { data } = await http.get<PpPhoto[]>('/api/sidecar/timeline', {
|
||||||
params: {
|
params: {
|
||||||
count: 60,
|
count: 60,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
@@ -260,7 +260,7 @@ export async function listPhotosAround(p: AroundParams): Promise<PpPhoto[]> {
|
|||||||
*/
|
*/
|
||||||
export async function countPhotos(q: string, opts: { merged?: boolean } = {}): Promise<number> {
|
export async function countPhotos(q: string, opts: { merged?: boolean } = {}): Promise<number> {
|
||||||
const merged = opts.merged ?? false;
|
const merged = opts.merged ?? false;
|
||||||
const resp = await http.get<PpPhoto[]>('/photos', {
|
const resp = await http.get<PpPhoto[]>('/api/sidecar/timeline', {
|
||||||
params: { count: 10000, offset: 0, merged, q }
|
params: { count: 10000, offset: 0, merged, q }
|
||||||
});
|
});
|
||||||
// PhotoPrism's `X-Count` header counts SQL file rows (one row per
|
// PhotoPrism's `X-Count` header counts SQL file rows (one row per
|
||||||
@@ -636,7 +636,7 @@ export async function aggregateKeywords(): Promise<AggregatedKeyword[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function hasPhotosMatching(q: string): Promise<boolean> {
|
async function hasPhotosMatching(q: string): Promise<boolean> {
|
||||||
const resp = await http.get<PpPhoto[]>('/photos', {
|
const resp = await http.get<PpPhoto[]>('/api/sidecar/timeline', {
|
||||||
params: { count: 1, offset: 0, q }
|
params: { count: 1, offset: 0, q }
|
||||||
});
|
});
|
||||||
return Array.isArray(resp.data) && resp.data.length > 0;
|
return Array.isArray(resp.data) && resp.data.length > 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user