//native
type Shutterstock = {
token: string;
};
/**
* Search for images
* This endpoint searches for images.
*/
export async function main(
auth: Shutterstock,
library: string | undefined,
added_date: string | undefined,
added_date_start: string | undefined,
aspect_ratio_min: string | undefined,
aspect_ratio_max: string | undefined,
aspect_ratio: string | undefined,
added_date_end: string | undefined,
category: string | undefined,
color: string | undefined,
contributor: string | undefined,
contributor_country: string | undefined,
fields: string | undefined,
height: string | undefined,
height_from: string | undefined,
height_to: string | undefined,
image_type: string | undefined,
keyword_safe_search: string | undefined,
language:
| "ar"
| "bg"
| "bn"
| "cs"
| "da"
| "de"
| "el"
| "en"
| "es"
| "fi"
| "fr"
| "gu"
| "he"
| "hi"
| "hr"
| "hu"
| "id"
| "it"
| "ja"
| "kn"
| "ko"
| "ml"
| "mr"
| "nb"
| "nl"
| "or"
| "pl"
| "pt"
| "ro"
| "ru"
| "sk"
| "sl"
| "sv"
| "ta"
| "te"
| "th"
| "tr"
| "uk"
| "ur"
| "vi"
| "zh"
| "zh-Hant"
| undefined,
license: string | undefined,
model: string | undefined,
orientation: "horizontal" | "vertical" | undefined,
page: string | undefined,
per_page: string | undefined,
people_model_released: string | undefined,
people_age:
| "infants"
| "children"
| "teenagers"
| "20s"
| "30s"
| "40s"
| "50s"
| "60s"
| "older"
| undefined,
people_ethnicity: string | undefined,
people_gender: "male" | "female" | "both" | undefined,
people_number: string | undefined,
query: string | undefined,
region: string | undefined,
safe: string | undefined,
sort: "newest" | "popular" | "relevance" | "random" | undefined,
spellcheck_query: string | undefined,
view: "minimal" | "full" | undefined,
width: string | undefined,
width_from: string | undefined,
width_to: string | undefined,
) {
const url = new URL(`https://api.shutterstock.com/v2/images/search`);
for (const [k, v] of [
["library", library],
["added_date", added_date],
["added_date_start", added_date_start],
["aspect_ratio_min", aspect_ratio_min],
["aspect_ratio_max", aspect_ratio_max],
["aspect_ratio", aspect_ratio],
["added_date_end", added_date_end],
["category", category],
["color", color],
["contributor", contributor],
["contributor_country", contributor_country],
["fields", fields],
["height", height],
["height_from", height_from],
["height_to", height_to],
["image_type", image_type],
["keyword_safe_search", keyword_safe_search],
["language", language],
["license", license],
["model", model],
["orientation", orientation],
["page", page],
["per_page", per_page],
["people_model_released", people_model_released],
["people_age", people_age],
["people_ethnicity", people_ethnicity],
["people_gender", people_gender],
["people_number", people_number],
["query", query],
["region", region],
["safe", safe],
["sort", sort],
["spellcheck_query", spellcheck_query],
["view", view],
["width", width],
["width_from", width_from],
["width_to", width_to],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago