Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions resources/js/services/metrics-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import axios, { type AxiosResponse } from "axios";
import Constants from "./constants";
import { ALL } from "@/config/constants";

function validateAlbumId(album_id: string | undefined): boolean {
if (album_id === undefined || album_id === ALL) {
return false;
}
// We check if the length of album_id is 24 characters, that excldes all the smarts albums
return album_id.length === 24;
}

const MetricsService = {
get(): Promise<AxiosResponse<App.Http.Resources.Models.LiveMetricsResource[]>> {
return axios.get(`${Constants.getApiUrl()}Metrics`, { data: {} });
Expand All @@ -13,17 +21,15 @@ const MetricsService = {
// Do not send a request if no photo_id is provided, otherwise it breaks in front-end.
return Promise.resolve(null);
}
// This is the case if we are in global search mode.
if (album_id === undefined || album_id === ALL) {
if (validateAlbumId(album_id)) {
return Promise.resolve(null);
}

return axios.post(`${Constants.getApiUrl()}Metrics::photo`, { photo_ids: [photo_id], from_id: album_id });
},

favourite(photo_id: string, album_id: string | undefined): Promise<AxiosResponse<null> | null> {
// This is the case if we are in global search mode.
if (album_id === undefined || album_id === ALL) {
if (validateAlbumId(album_id)) {
return Promise.resolve(null);
}

Expand Down