mirror of
https://github.com/mudabbir-ahmad/Media-Aggregation-and-Sorting-System.git
synced 2026-10-08 03:40:20 +00:00
Init + some files and folders
This commit is contained in:
1 parent
c9c374c7fa
commit
59ac1fc926
10 files changed
+71
No files matched your search
@@ -0,0 +1,71 @@
|
|||||||
|
const GooglePhotosAPI = (getAccessToken) => {
|
||||||
|
const callFetch = async (endpoint, method = 'GET', dataObj = null) => {
|
||||||
|
const token = await getAccessToken();
|
||||||
|
if (!token) return { isSuccess: false, message: 'Missing access token' };
|
||||||
|
|
||||||
|
let requestObj = {
|
||||||
|
method,
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (dataObj) {
|
||||||
|
requestObj = {
|
||||||
|
...requestObj,
|
||||||
|
headers: {
|
||||||
|
...requestObj.headers,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(dataObj),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(endpoint, requestObj);
|
||||||
|
const result = response.status !== 204 ? await response.json() : null;
|
||||||
|
return response.ok
|
||||||
|
? { isSuccess: true, result }
|
||||||
|
: { isSuccess: false, message: result?.error?.message || 'Request failed' };
|
||||||
|
} catch (error) {
|
||||||
|
return { isSuccess: false, message: error.message };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const API_ROOT = 'https://photoslibrary.googleapis.com/v1';
|
||||||
|
|
||||||
|
return {
|
||||||
|
// List media items
|
||||||
|
listMediaItems: (pageSize = 25, pageToken) => {
|
||||||
|
const params = new URLSearchParams({ pageSize });
|
||||||
|
if (pageToken) params.append('pageToken', pageToken);
|
||||||
|
return callFetch(`${API_ROOT}/mediaItems?${params.toString()}`, 'GET');
|
||||||
|
},
|
||||||
|
|
||||||
|
// Get a single media item by ID
|
||||||
|
getMediaItem: (mediaItemId) =>
|
||||||
|
callFetch(`${API_ROOT}/mediaItems/${mediaItemId}`, 'GET'),
|
||||||
|
|
||||||
|
// Search media items with filters (e.g., albumId)
|
||||||
|
searchMediaItems: (filters) =>
|
||||||
|
callFetch(`${API_ROOT}/mediaItems:search`, 'POST', filters),
|
||||||
|
|
||||||
|
// Create an album
|
||||||
|
createAlbum: (title) =>
|
||||||
|
callFetch(`${API_ROOT}/albums`, 'POST', { album: { title } }),
|
||||||
|
|
||||||
|
// Add media items to an album
|
||||||
|
addItemsToAlbum: (albumId, mediaItemIds) =>
|
||||||
|
callFetch(`${API_ROOT}/albums/${albumId}:batchAddMediaItems`, 'POST', {
|
||||||
|
mediaItemIds,
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Remove media items from an album
|
||||||
|
removeItemsFromAlbum: (albumId, mediaItemIds) =>
|
||||||
|
callFetch(`${API_ROOT}/albums/${albumId}:batchRemoveMediaItems`, 'POST', {
|
||||||
|
mediaItemIds,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default GooglePhotosAPI;
|
||||||
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Reference in new issue
Block a user