UNPKG

@xct007/frieren-scraper

Version:
57 lines (56 loc) 1.84 kB
import { Axios } from "../Utils.js"; import { UnsplashBaseUrl } from "../Constant.js"; async function search(query, page = 1) { try { const { data } = await Axios.get(UnsplashBaseUrl + "/search/photos", { headers: { ["Content-Type"]: "application/json", ["authorization"]: "Client-ID 7oM5DivqfP1jh19NoEU7UZiWrcJIzYBC2f8B9fVRMug", }, params: { page, per_page: 12, query, orientation: "portrait", order_by: "latest", content_filter: "low", }, }).catch((e) => e?.response); if (data && typeof data === "object" && data.results) { const _temp = []; for (const key of data.results) { _temp.push({ id: key.id, created_at: key.created_at, updated_at: key.updated_at, urls: { ...key.urls }, links: { download: key.links.download, }, user: { username: key.user.username, bio: key.user.bio, social: { ...key.user.social }, }, }); } if (Array.isArray(_temp) && _temp.length) { return _temp; } else { throw new Error(data?.errors || "failed retrieve data"); } console.log(data.results[0]); } else { throw new Error(data?.errors || "failed retrieve data"); } } catch (e) { return { error: true, message: String(e), }; } } export { search };