Skip to content

New Components - pexels #16498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions components/pexels/actions/download-photo/download-photo.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { axios } from "@pipedream/platform";
import fs from "fs";
import stream from "stream";
import { promisify } from "util";
import pexels from "../../pexels.app.mjs";

export default {
key: "pexels-download-photo",
name: "Download Photo",
description: "Download a specific photo by providing its photo ID and optionally choosing the desired size. [See the documentation](https://www.pexels.com/api/documentation/)",
version: "0.0.1",
type: "action",
props: {
pexels,
photoId: {
propDefinition: [
pexels,
"photoId",
],
},
filePath: {
type: "string",
label: "File Path",
description: "The destination path in [`/tmp`](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory) for the downloaded the file (e.g., `/tmp/myFile.jpg`). Make sure to include the file extension.",
},
},
methods: {
getFileStream({
$, downloadUrl,
}) {
return axios($, {
url: downloadUrl,
responseType: "stream",
});
},
},
async run({ $ }) {
const response = await this.pexels.getPhoto({
$,
photoId: this.photoId,
});

const fileStream = await this.getFileStream({
$,
downloadUrl: response.src.original,
});

const pipeline = promisify(stream.pipeline);
const resp = await pipeline(
fileStream,
fs.createWriteStream(this.filePath.includes("/tmp")
? this.filePath
: `/tmp/${this.filePath}`),
);

$.export("$summary", `Successfully downloaded photo with ID ${this.photoId} to ${this.filePath}`);
return {
resp,
};
},
};
26 changes: 26 additions & 0 deletions components/pexels/actions/get-photo-details/get-photo-details.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pexels from "../../pexels.app.mjs";

export default {
key: "pexels-get-photo-details",
name: "Get Photo Details",
description: "Retrieve detailed information about a specific photo by providing its photo ID. [See the documentation](https://www.pexels.com/api/documentation/#photos-show)",
version: "0.0.1",
type: "action",
props: {
pexels,
photoId: {
propDefinition: [
pexels,
"photoId",
],
},
},
async run({ $ }) {
const response = await this.pexels.getPhoto({
$,
photoId: this.photoId,
});
$.export("$summary", `Successfully retrieved details for photo ID: ${this.photoId}`);
return response;
},
};
65 changes: 65 additions & 0 deletions components/pexels/actions/search-photos/search-photos.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import pexels from "../../pexels.app.mjs";

export default {
key: "pexels-search-photos",
name: "Search Photos",
description: "Search for photos on Pexels using a keyword or phrase. [See the documentation](https://www.pexels.com/api/documentation/#photos-search)",
version: "0.0.1",
type: "action",
props: {
pexels,
searchQuery: {
propDefinition: [
pexels,
"searchQuery",
],
},
orientation: {
propDefinition: [
pexels,
"orientation",
],
},
size: {
propDefinition: [
pexels,
"size",
],
},
color: {
propDefinition: [
pexels,
"color",
],
},
page: {
type: "integer",
label: "Page",
description: "The page number you are requesting",
optional: true,
},
perPage: {
type: "integer",
label: "Per Page",
description: "The number of results you are requesting per page",
max: 80,
optional: true,
},
},
async run({ $ }) {
const response = await this.pexels.searchPhotos({
$,
params: {
query: this.searchQuery,
orientation: this.orientation,
size: this.size,
color: this.color,
page: this.page || 1,
per_page: this.perPage || 15,
},
});

$.export("$summary", `Successfully retrieved ${response.photos.length} photos for the query "${this.searchQuery}".`);
return response;
},
};
80 changes: 80 additions & 0 deletions components/pexels/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
export const ORIENTATION_OPTIONS = [
{
label: "Landscape",
value: "landscape",
},
{
label: "Portrait",
value: "portrait",
},
{
label: "Square",
value: "square",
},
];

export const SIZE_OPTIONS = [
{
label: "Large (24MP)",
value: "large",
},
{
label: "Medium (12MP)",
value: "medium",
},
{
label: "Small (4MP)",
value: "small",
},
];

export const COLOR_OPTIONS = [
{
label: "Red",
value: "red",
},
{
label: "Orange",
value: "orange",
},
{
label: "Yellow",
value: "yellow",
},
{
label: "Green",
value: "green",
},
{
label: "Turquoise",
value: "turquoise",
},
{
label: "Blue",
value: "blue",
},
{
label: "Violet",
value: "violet",
},
{
label: "Pink",
value: "pink",
},
{
label: "Brown",
value: "brown",
},
{
label: "Black",
value: "black",
},
{
label: "Gray",
value: "gray",
},
{
label: "White",
value: "white",
},
];
5 changes: 3 additions & 2 deletions components/pexels/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/pexels",
"version": "0.6.0",
"version": "0.1.0",
"description": "Pipedream pexels Components",
"main": "pexels.app.mjs",
"keywords": [
Expand All @@ -13,6 +13,7 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.0"
"@pipedream/platform": "^3.0.3",
"stream": "^0.0.3"
}
}
105 changes: 101 additions & 4 deletions components/pexels/pexels.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,108 @@
import { axios } from "@pipedream/platform";
import {
COLOR_OPTIONS,
ORIENTATION_OPTIONS,
SIZE_OPTIONS,
} from "./common/constants.mjs";

export default {
type: "app",
app: "pexels",
propDefinitions: {},
propDefinitions: {
searchQuery: {
type: "string",
label: "Search Query",
description: "The search query. **Ocean**, **Tigers**, **Pears**, etc.",
},
orientation: {
type: "string",
label: "Orientation",
description: "Desired photo orientation.",
optional: true,
options: ORIENTATION_OPTIONS,
},
size: {
type: "string",
label: "Size",
description: "Minimum photo size.",
optional: true,
options: SIZE_OPTIONS,
},
color: {
type: "string",
label: "Color",
description: "Desired photo color. You can set any color listed or any hexidecimal color code (eg. #ffffff)",
optional: true,
options: COLOR_OPTIONS,
},
photoId: {
type: "string",
label: "Photo ID",
description: "The ID of the photo to retrieve or download.",
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.pexels.com/v1";
},
_headers() {
return {
"Authorization": `${this.$auth.api_key}`,
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
headers: this._headers(),
...opts,
});
},
searchPhotos(opts = {}) {
return this._makeRequest({
path: "/search",
...opts,
});
},
getPhoto({
photoId, ...opts
} = {}) {
return this._makeRequest({
path: `/photos/${photoId}`,
...opts,
});
},
getCuratedPhotos(opts = {}) {
return this._makeRequest({
path: "/curated",
...opts,
});
},
async *paginate({
fn, params = {}, maxResults = null, ...opts
}) {
let hasMore = false;
let count = 0;
let page = 0;

do {
params.page = ++page;
const { photos } = await fn({
params,
...opts,
});
for (const d of photos) {
yield d;

if (maxResults && ++count === maxResults) {
return count;
}
}

hasMore = photos.length;

} while (hasMore);
},
},
};
Loading
Loading