const axios = require('axios'); function formatDate(isoString) { const date = new Date(isoString); const day = String(date.getDate()).padStart(2, '0'); const month = String(date.getMonth() + 1).padStart(2, '0'); const year = date.getFullYear(); const hours = String(date.getHours()).padStart(2, '0'); const minutes = String(date.getMinutes()).padStart(2, '0'); return `${day}-${month}-${year} ${hours}:${minutes}`; } async function unsplash(q) { try { if (!q) throw new Error('Query is required'); const { data } = await axios.get(`https://unsplash.com/napi/search/photos?page=${Math.floor(Math.random() * 100) + 1}&per_page=20&query=${q}`); return data.results.map(res => ({ title: res.alt_description || 'No Title', likes: res.likes, type: res.asset_type, is_premium: res.premium, is_plus: res.plus, author: { name: res.user.name, username: res.user.username, avatar: res.user.profile_image.large, url: `https://unsplash.com/@${res.user.username}` }, thumbnail: res.urls, created_at: formatDate(res.created_at), updated_at: formatDate(res.updated_at), downloadUrl: res.links.download, url: res.links.html })); } catch (error) { throw new Error(error.message); } } // Usage: const resp = await unsplash('field'); console.log(resp);