-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[COMPONENTS] wordpress_com. Actions + sources #16461
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
Changes from 5 commits
9964c4a
b780b29
79d8a49
2a40c5d
8fbc421
fb9ec32
68d1235
9e00ce2
f62e918
7ed271c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import wordpress from "../wordpress_com.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "wordpress_com-create-post", | ||
| name: "Create New Post", | ||
| description: "Creates a new post on a WordPress.com site.", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| wordpress, | ||
| site: { | ||
| type: "string", | ||
| label: "Site ID or domain", | ||
| description: "Enter a site ID or domain (e.g. testsit38.wordpress.com). Do not include 'https://' or 'www'." | ||
| }, | ||
| title: { | ||
| type: "string", | ||
| label: "Post Title", | ||
| description: "The title of the post.", | ||
| }, | ||
| content: { | ||
| type: "string", | ||
| label: "Post Content", | ||
| description: "The content of the post (HTML or text).", | ||
| }, | ||
SokolovskyiK marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| status: { | ||
| type: "string", | ||
| label: "Status", | ||
| description: "The status of the post.", | ||
| options: [ | ||
| "publish", | ||
| "draft", | ||
| "private", | ||
| "pending", | ||
| ], | ||
| default: "draft", | ||
| }, | ||
| type: { | ||
| type: "string", | ||
| label: "Post Type", | ||
| description: "The type of the post (post or page). For attachments, use the 'Upload Media' action.", | ||
| options: [ | ||
| { label: "Post", value: "post" }, | ||
|
Check failure on line 43 in components/wordpress_com/actions/create-post.mjs
|
||
| { label: "Page", value: "page" }, | ||
|
Check failure on line 44 in components/wordpress_com/actions/create-post.mjs
|
||
| ], | ||
| default: "post", | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
|
|
||
| async run({ $ }) { | ||
|
|
||
| const warnings = []; | ||
|
|
||
| const { | ||
| site, | ||
| wordpress, | ||
| ...fields | ||
| } = this; | ||
|
|
||
| warnings.push(...wordpress.checkDomainOrId(site)); // TEST | ||
|
|
||
| let response; | ||
|
|
||
| try { | ||
| response = await wordpress.createWordpressPost({ //TEST | ||
|
|
||
| $, | ||
| site, | ||
| data : { | ||
| ...fields | ||
| } | ||
| }); | ||
|
|
||
| } catch (error) { | ||
| wordpress.throwCustomError("Could not create post", error, warnings); | ||
| }; | ||
|
|
||
| $.export("$summary", `Post successfully created. ID = ${response?.ID}` + "\n- " + warnings.join("\n- ")); | ||
SokolovskyiK marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
|
|
||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import wordpress from "../wordpress_com.app.mjs"; | ||
|
|
||
| export default { | ||
|
|
||
| key: "wordpress_com-delete-post", | ||
| name: "Delete Post", | ||
| description: "Deletes a post", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| wordpress, | ||
| site: { | ||
| type: "string", | ||
| description: "Enter a site ID or domain (e.g. testsit38.wordpress.com).", | ||
| }, | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| postId: { | ||
| type: "integer", | ||
| label: "Post ID", | ||
| description: "The ID of the post you want to delete.", | ||
| }, | ||
| }, | ||
|
|
||
| async run({ $ }) { | ||
|
|
||
| const warnings = []; | ||
|
|
||
| const { | ||
| site, | ||
| wordpress, | ||
| postId | ||
| } = this; | ||
|
|
||
|
|
||
| warnings.push(...wordpress.checkDomainOrId(site)); | ||
|
|
||
| let response; | ||
|
|
||
| try { | ||
| response = await wordpress.deleteWordpressPost({$, site, postId}); | ||
| } catch (error) { | ||
| wordpress.throwCustomError("Could not delete post", error, warnings); | ||
| }; | ||
|
|
||
| $.export("$summary", `Post ID = ${response?.ID} successfully deleted.` + "\n- " + warnings.join("\n- ")); | ||
| }, | ||
SokolovskyiK marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import {prepareMediaUpload} from "../common/utils.mjs"; | ||
| import wordpress from "../wordpress_com.app.mjs"; | ||
|
|
||
| export default { | ||
|
|
||
| key: "wordpress_com-upload-media", | ||
| name: "Upload Media", | ||
| description: "Uploads a media file from a URL to the specified WordPress.com site.", | ||
| version: "0.0.1", | ||
| type: "action", | ||
|
|
||
| props: { | ||
| wordpress, | ||
| site: { | ||
| type: "string", | ||
| label: "Site ID or domain", | ||
| description: "Enter a site ID or domain (e.g. testsit38.wordpress.com).", | ||
| }, | ||
| media: { | ||
| type: "any", | ||
| label: "Media URL", | ||
| description: "A direct media URL, or a FormData object with the file attached under the field name 'media[]'.", | ||
| }, | ||
| title: { | ||
| type: "string", | ||
| label: "Title", | ||
| description: "Title of the media.", | ||
| optional: true, | ||
| }, | ||
| caption: { | ||
| type: "string", | ||
| label: "Caption", | ||
| optional: true, | ||
| }, | ||
| description: { | ||
| type: "string", | ||
| label: "Description", | ||
| optional: true, | ||
| }, | ||
| }, | ||
|
|
||
| async run({ $ }) { | ||
|
|
||
| const warnings = []; | ||
|
|
||
| const | ||
| { | ||
| wordpress, | ||
| site, | ||
| media, | ||
| ...fields | ||
| } = this; | ||
|
|
||
| warnings.push(...wordpress.checkDomainOrId(site)); | ||
|
|
||
| let form; | ||
|
|
||
| // If not form data | ||
| if (wordpress.isFormData(media)){ | ||
|
|
||
| console.log("Media was received as multipart/form-data"); | ||
| warnings.push("Media was received as multipart/form-data"); | ||
|
|
||
| form = media; | ||
|
|
||
| } else { | ||
|
|
||
| warnings.push("Media was received as URL"); | ||
| warnings.push(...wordpress.checkIfUrlValid(media)); | ||
|
|
||
| form = await prepareMediaUpload(media, fields, $); | ||
| } | ||
|
|
||
| let response; | ||
|
|
||
| try { | ||
|
|
||
| response = await wordpress.uploadWordpressMedia({ | ||
| $, | ||
| contentType : form.getHeaders()["content-type"], | ||
| site, | ||
| data : form, | ||
| }); | ||
|
|
||
| const media = response.media[0]; | ||
|
|
||
| $.export("$summary", `Media "${media.title}" uploaded successfully (ID: ${media.ID})` + "\n- " + warnings.join("\n- ")); | ||
|
|
||
| console.log(response); | ||
| return response; | ||
|
|
||
| } catch (error) { | ||
|
|
||
| wordpress.throwCustomError("Failed to upload media", error, warnings); | ||
|
|
||
| }; | ||
| }, | ||
| }; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.