Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "social_fetch-get-credit-balance",
name: "Get Credit Balance",
description: "Returns the current API credit balance for your Social Fetch account. [See the documentation](https://www.socialfetch.dev/docs/api/v1/balance)",
version: "0.0.1",
version: "0.0.2",
type: "action",
annotations: {
destructiveHint: false,
Expand Down
2 changes: 1 addition & 1 deletion components/social_fetch/actions/get-post/get-post.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "social_fetch-get-post",
name: "Get Post",
description: "Fetches public post, video, or tweet data from a URL. [See the documentation](https://www.socialfetch.dev/docs/api)",
version: "0.0.1",
version: "0.0.2",
type: "action",
annotations: {
destructiveHint: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "social_fetch-get-profile",
name: "Get Profile",
description: "Fetches public profile data. Choose platform, then handle or profile URL. [See the documentation](https://www.socialfetch.dev/docs/api)",
version: "0.0.1",
version: "0.0.2",
type: "action",
annotations: {
destructiveHint: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import app from "../../social_fetch.app.mjs";

export default {
key: "social_fetch-get-reddit-post-transcript",
name: "Get Reddit Post Transcript",
description: "Get the captions transcript for a Reddit video post. Use this when you need the spoken text of a Reddit-hosted video; for the post's comment thread use **List Reddit Post Comments** instead. Provide the post URL or a direct hosted video URL, and optionally a two-letter ISO 639-1 language code (e.g. `en`) to prefer a caption track when several exist. [See the documentation](https://app.socialfetch.dev/playground?path=/v1/reddit/posts/transcript&method=GET)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
app,
url: {
propDefinition: [
app,
"redditPostUrl",
],
},
language: {
propDefinition: [
app,
"language",
],
},
},
async run({ $ }) {
const response = await this.app.getPostTranscript({
$,
url: this.url,
language: this.language,
});
$.export("$summary", "Successfully fetched post transcript");
return response;
},
};
38 changes: 38 additions & 0 deletions components/social_fetch/actions/get-subreddit/get-subreddit.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import app from "../../social_fetch.app.mjs";

export default {
key: "social_fetch-get-subreddit",
name: "Get Subreddit",
description: "Get metadata for a single Reddit community — title, description, subscriber counts, and icon/banner images when available. Use this to look up details about one subreddit; to fetch its posts use **List Subreddit Posts** instead. Provide the community as a bare name (`pics`), an `r/`-prefixed name (`r/pics`), or a full subreddit URL (`https://www.reddit.com/r/pics`); casing must match Reddit exactly. [See the documentation](https://app.socialfetch.dev/playground?path=/v1/reddit/subreddits&method=GET)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
app,
subreddit: {
propDefinition: [
app,
"subreddit",
],
},
url: {
propDefinition: [
app,
"subredditUrl",
],
},
},
async run({ $ }) {
const response = await this.app.getSubreddit({
$,
subreddit: this.subreddit,
url: this.url,
});
$.export("$summary", "Successfully fetched subreddit details");
return response;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "social_fetch-get-transcript",
name: "Get Transcript",
description: "Fetches a transcript for a video or post URL. [See the documentation](https://www.socialfetch.dev/docs/api)",
version: "0.0.1",
version: "0.0.2",
type: "action",
annotations: {
destructiveHint: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "social_fetch-list-profile-posts",
name: "List Profile Posts",
description: "Lists recent posts, videos, reels, or tweets for a profile. [See the documentation](https://www.socialfetch.dev/docs/api)",
version: "0.0.1",
version: "0.0.2",
type: "action",
annotations: {
destructiveHint: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import app from "../../social_fetch.app.mjs";
import { truncateArrays } from "../../common/utils.mjs";

export default {
key: "social_fetch-list-reddit-post-comments",
name: "List Reddit Post Comments",
description: "List the comments and nested replies on a specific Reddit post. Use this after locating a post via **List Subreddit Posts** when you need its discussion thread. Provide the full post URL (e.g. `https://www.reddit.com/r/pics/comments/abc123/title/`). Enable **Trim** for a lighter response shape, and page through long threads with the cursor. [See the documentation](https://app.socialfetch.dev/playground?path=/v1/reddit/posts/comments&method=GET)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
app,
url: {
propDefinition: [
app,
"redditPostUrl",
],
},
trim: {
propDefinition: [
app,
"trim",
],
},
cursor: {
propDefinition: [
app,
"cursor",
],
},
},
async run({ $ }) {
const MAX_COMMENTS = 10;
const response = await this.app.listPostComments({
$,
url: this.url,
trim: this.trim,
cursor: this.cursor,
});
truncateArrays(response?.data, MAX_COMMENTS);
$.export("$summary", "Successfully listed post comments");
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import app from "../../social_fetch.app.mjs";
import { truncateArrays } from "../../common/utils.mjs";

export default {
key: "social_fetch-list-subreddit-posts",
name: "List Subreddit Posts",
description: "List posts from a single subreddit, with optional sorting (`best`, `hot`, `new`, `top`, `rising`) and a timeframe for time-based sorts (`all`, `day`, `week`, `month`, `year`). Use this to browse or page through a community's feed; for details about the community itself use **Get Subreddit**, and to read a specific post's replies use **List Reddit Post Comments**. Accepts the subreddit as a bare name (`pics`), an `r/`-prefixed name (`r/pics`), or a subreddit URL. Page through results with the cursor. [See the documentation](https://app.socialfetch.dev/playground?path=/v1/reddit/subreddits/%7Bsubreddit%7D/posts&method=GET)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
app,
subreddit: {
propDefinition: [
app,
"subreddit",
],
},
sort: {
propDefinition: [
app,
"sort",
],
},
timeframe: {
propDefinition: [
app,
"timeframe",
],
},
cursor: {
propDefinition: [
app,
"cursor",
],
},
},
async run({ $ }) {
const MAX_POSTS = 10;
const response = await this.app.listSubredditPosts({
$,
subreddit: this.subreddit,
sort: this.sort,
timeframe: this.timeframe,
cursor: this.cursor,
});
truncateArrays(response?.data, MAX_POSTS);
$.export("$summary", "Successfully listed subreddit posts");
return response;
},
};
16 changes: 16 additions & 0 deletions components/social_fetch/common/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ export const TRANSCRIPT_PLATFORMS = [
"youtube",
];

export const SUBREDDIT_POST_SORT_OPTIONS = [
"best",
"hot",
"new",
"top",
"rising",
];

export const SUBREDDIT_POST_TIMEFRAME_OPTIONS = [
"all",
"day",
"week",
"month",
"year",
];

export const CONTENT_TYPE_OPTIONS = [
{
label: "Videos",
Expand Down
22 changes: 22 additions & 0 deletions components/social_fetch/common/routing.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ import {
URL_PROFILE_PLATFORMS,
} from "./constants.mjs";

/**
* Extract the canonical subreddit name from a bare name, an `r/`-prefixed
* name, or a full Reddit subreddit URL, so it can be safely used as a single
* path segment. Reddit's exact casing is preserved.
*
* @param {string | undefined} input
* @returns {string}
*/
export function normalizeSubreddit(input) {
const value = input?.trim();
if (!value) {
return "";
}
const urlMatch = value.match(/reddit\.com\/r\/([^/?#]+)/i);
if (urlMatch) {
return urlMatch[1];
}
return value
.replace(/^\/?r\//i, "")
.split(/[/?#]/)[0];
}

/**
* @param {Record<string, string | undefined>} query
* @param {string | undefined} cursor
Expand Down
25 changes: 25 additions & 0 deletions components/social_fetch/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
/**
* Truncate top-level arrays in a response `data` object to keep step exports
* manageable, flagging any array that was shortened.
*
* @param {Record<string, unknown> | undefined} data
* @param {number} max
*/
export function truncateArrays(data, max) {
if (!data || typeof data !== "object") {
return data;
}
const notices = [];
for (const key of Object.keys(data)) {
if (Array.isArray(data[key]) && data[key].length > max) {
const total = data[key].length;
data[key] = data[key].slice(0, max);
notices.push(`${key} truncated to ${max} of ${total} items`);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
if (notices.length) {
data._truncated = notices;
}
return data;
}

/**
* Recursively compare two objects and return a structured diff map.
*
Expand Down
2 changes: 1 addition & 1 deletion components/social_fetch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/social_fetch",
"version": "0.1.0",
"version": "0.2.0",
"description": "Pipedream Social Fetch Components",
"main": "social_fetch.app.mjs",
"keywords": [
Expand Down
Loading
Loading