feat(reddit): add create link post action

This commit is contained in:
Rıdvan Akca
2023-11-10 18:18:26 +03:00
parent 97bcd3792b
commit ff00644e62
5 changed files with 71 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
import defineAction from '../../../../helpers/define-action';
import { URLSearchParams } from 'url';
export default defineAction({
name: 'Create link post',
key: 'createLinkPost',
description: 'Create a new link post within a subreddit.',
arguments: [
{
label: 'Title',
key: 'title',
type: 'string' as const,
required: true,
description:
'Heading for the recent post. Limited to 300 characters or less.',
variables: true,
},
{
label: 'Subreddit',
key: 'subreddit',
type: 'string' as const,
required: true,
description: 'The subreddit for posting. Note: Exclude /r/.',
variables: true,
},
{
label: 'Url',
key: 'url',
type: 'string' as const,
required: true,
description: '',
variables: true,
},
],
async run($) {
const { title, subreddit, url } = $.step.parameters;
const params = new URLSearchParams({
kind: 'link',
api_type: 'json',
title: title as string,
sr: subreddit as string,
url: url as string,
});
const { data } = await $.http.post('/api/submit', params.toString());
$.setActionItem({
raw: data,
});
},
});

View File

@@ -0,0 +1,3 @@
import createLinkPost from './create-link-post';
export default [createLinkPost];

View File

@@ -2,6 +2,7 @@ import defineApp from '../../helpers/define-app';
import addAuthHeader from './common/add-auth-header'; import addAuthHeader from './common/add-auth-header';
import auth from './auth'; import auth from './auth';
import triggers from './triggers'; import triggers from './triggers';
import actions from './actions';
export default defineApp({ export default defineApp({
name: 'Reddit', name: 'Reddit',
@@ -15,4 +16,5 @@ export default defineApp({
beforeRequest: [addAuthHeader], beforeRequest: [addAuthHeader],
auth, auth,
triggers, triggers,
actions,
}); });

View File

@@ -295,6 +295,7 @@ export default defineConfig({
collapsed: true, collapsed: true,
items: [ items: [
{ text: 'Triggers', link: '/apps/reddit/triggers' }, { text: 'Triggers', link: '/apps/reddit/triggers' },
{ text: 'Actions', link: '/apps/reddit/actions' },
{ text: 'Connection', link: '/apps/reddit/connection' }, { text: 'Connection', link: '/apps/reddit/connection' },
], ],
}, },

View File

@@ -0,0 +1,12 @@
---
favicon: /favicons/reddit.svg
items:
- name: Create link post
desc: Create a new link post within a subreddit.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />