-
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9964c4a
Initialization
SokolovskyiK b780b29
Add [COMPONENTS] Wordpress.com
SokolovskyiK 79d8a49
CodeRabbit change
SokolovskyiK 2a40c5d
update bnpm-lock.yaml
SokolovskyiK 8fbc421
CodeRabbit change 2
SokolovskyiK fb9ec32
Lint: fix eslint errors in WordPress.com components
SokolovskyiK 68d1235
Fix keys
SokolovskyiK 9e00ce2
Minor fix
SokolovskyiK f62e918
updates
michelle0927 7ed271c
doc link
michelle0927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import wordpress from "../wordpress_com.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "worpress_com-create-post", | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name: "Create New Post", | ||
| description: "Retrieves the authenticated user's account information.", | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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'." | ||
| }, | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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" }, | ||
| { label: "Page", value: "page" }, | ||
| ], | ||
| 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.onAxiosCatch("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
SokolovskyiK marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
|
|
||
| }; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import wordpress from "../wordpress_com.app.mjs"; | ||
|
|
||
| export default { | ||
|
|
||
| key: "worpress_com-delete-post", | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name: "Delete Post", | ||
| description: "Delete 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.onAxiosCatch("Could not delete post", error, warnings); | ||
| }; | ||
SokolovskyiK marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| $.export("$summary", `Post ID = ${response?.ID} successfully deleted.` + "\n- " + warnings.join("\n- ")); | ||
| }, | ||
SokolovskyiK marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
SokolovskyiK marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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- ")); | ||
SokolovskyiK marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| console.log(response); | ||
| return response; | ||
|
|
||
| } catch (error) { | ||
|
|
||
| wordpress.onAxiosCatch("Failed to upload media", error, warnings); | ||
|
|
||
| }; | ||
SokolovskyiK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }; | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.