Update admin gallery to fetch images directly from Cloudinary
Integrates Cloudinary API to fetch image details for the admin gallery page, replacing previous data sources. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 23852c00-4779-460a-9e0c-d09fee4b6c92 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: eb361b34-3147-44e1-a7c3-11100d3e83b8 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/23852c00-4779-460a-9e0c-d09fee4b6c92/ncMMRQ9 Replit-Helium-Checkpoint-Created: true
This commit is contained in:
@@ -116,6 +116,63 @@ export async function listCloudinaryGallery(): Promise<string[]> {
|
||||
}
|
||||
}
|
||||
|
||||
export interface CloudinaryResourceInfo {
|
||||
publicId: string;
|
||||
fileName: string;
|
||||
artist: string;
|
||||
width: number;
|
||||
height: number;
|
||||
format: string;
|
||||
bytes: number;
|
||||
createdAt: string;
|
||||
thumb: string;
|
||||
large: string;
|
||||
mobile: string;
|
||||
full: string;
|
||||
}
|
||||
|
||||
export async function listCloudinaryGalleryDetailed(): Promise<CloudinaryResourceInfo[]> {
|
||||
try {
|
||||
let allResources: any[] = [];
|
||||
let nextCursor: string | undefined;
|
||||
|
||||
do {
|
||||
const result = await cloudinary.api.resources({
|
||||
type: "upload",
|
||||
prefix: GALLERY_FOLDER + "/",
|
||||
max_results: 500,
|
||||
resource_type: "image",
|
||||
...(nextCursor ? { next_cursor: nextCursor } : {}),
|
||||
});
|
||||
allResources = allResources.concat(result.resources);
|
||||
nextCursor = result.next_cursor;
|
||||
} while (nextCursor);
|
||||
|
||||
return allResources.map((r: any) => {
|
||||
const urls = generateImageUrls(r.public_id);
|
||||
const rawName = r.public_id.replace(`${GALLERY_FOLDER}/`, "").replace(/_/g, " ");
|
||||
let originalFileName = rawName;
|
||||
const ext = r.format || "jpg";
|
||||
originalFileName = rawName + "." + ext;
|
||||
|
||||
return {
|
||||
publicId: r.public_id,
|
||||
fileName: originalFileName,
|
||||
artist: extractArtistFromPublicId(r.public_id),
|
||||
width: r.width,
|
||||
height: r.height,
|
||||
format: r.format,
|
||||
bytes: r.bytes,
|
||||
createdAt: r.created_at,
|
||||
...urls,
|
||||
};
|
||||
});
|
||||
} catch (err: any) {
|
||||
console.error("Cloudinary detailed list failed:", err.message);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function extractArtistFromPublicId(publicId: string): string {
|
||||
const name = publicId.replace(`${GALLERY_FOLDER}/`, "").replace(/_/g, " ");
|
||||
if (/^DSC\d/i.test(name) || /^IMG[\s_]\d/i.test(name)) return "";
|
||||
|
||||
Reference in New Issue
Block a user