-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[Sources] Wordpress_com #16500
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
base: master
Are you sure you want to change the base?
[Sources] Wordpress_com #16500
Changes from 4 commits
bbe6eac
1b6788e
e2be15a
c1859ac
588ac45
3a5c75e
41b4d37
bbf87b2
0d8115e
25c3d7b
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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -4,7 +4,7 @@ export default { | |||||||
key: "wordpress_com-delete-post", | ||||||||
name: "Delete Post", | ||||||||
description: "Deletes a post. [See the documentation](https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/posts/%24post_ID/delete/)", | ||||||||
version: "0.0.1", | ||||||||
version: "0.0.2", | ||||||||
type: "action", | ||||||||
props: { | ||||||||
wordpress, | ||||||||
|
@@ -48,7 +48,8 @@ export default { | |||||||
wordpress.throwCustomError("Could not delete post", error, warnings); | ||||||||
}; | ||||||||
|
||||||||
$.export("$summary", `Post ID = ${response?.ID} successfully deleted.` + "\n- " + warnings.join("\n- ")); | ||||||||
$.export("$summary", `Post ID “${response?.ID}” has been successfully deleted` + | ||||||||
"\n- " + warnings.join("\n- ")); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the warnings stuff here. Just export the summary as plain text
Suggested change
|
||||||||
}, | ||||||||
}; | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,9 +4,19 @@ export default { | |||||||||||||||||||||||||||||
key: "wordpress_com-new-comment", | ||||||||||||||||||||||||||||||
name: "New Comment", | ||||||||||||||||||||||||||||||
description: "Emit new event for each new comment added since the last run. If no new comments, emit nothing.", | ||||||||||||||||||||||||||||||
version: "0.0.1", | ||||||||||||||||||||||||||||||
version: "0.0.3", | ||||||||||||||||||||||||||||||
type: "source", | ||||||||||||||||||||||||||||||
dedupe: "unique", | ||||||||||||||||||||||||||||||
methods: { | ||||||||||||||||||||||||||||||
getWordpressComments($) { | ||||||||||||||||||||||||||||||
return this.wordpress.getWordpressComments({ | ||||||||||||||||||||||||||||||
$, | ||||||||||||||||||||||||||||||
site: this.site, | ||||||||||||||||||||||||||||||
postId: this.postId, | ||||||||||||||||||||||||||||||
number: this.number, | ||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
props: { | ||||||||||||||||||||||||||||||
wordpress, | ||||||||||||||||||||||||||||||
db: "$.service.db", | ||||||||||||||||||||||||||||||
|
@@ -36,28 +46,54 @@ export default { | |||||||||||||||||||||||||||||
min: 1, | ||||||||||||||||||||||||||||||
max: 100, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
timer: { | ||||||||||||||||||||||||||||||
type: "$.interface.timer", | ||||||||||||||||||||||||||||||
label: "Timer", | ||||||||||||||||||||||||||||||
description: "How often to poll WordPress for new comments.", | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add default timer
Suggested change
|
||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
hooks: { | ||||||||||||||||||||||||||||||
async activate() { | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const warnings = []; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const { | ||||||||||||||||||||||||||||||
wordpress, | ||||||||||||||||||||||||||||||
db, | ||||||||||||||||||||||||||||||
site, | ||||||||||||||||||||||||||||||
} = this; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
warnings.push(...wordpress.checkDomainOrId(site)); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (warnings.length > 0) { | ||||||||||||||||||||||||||||||
console.log("Warnings:\n- " + warnings.join("\n- ")); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
await this.db.set("lastCommentId", null); //reset | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const response = await this.getWordpressComments(this.wordpress._mock$); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const comments = response.comments || []; | ||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
await wordpress.initialize(comments, db, "lastCommentId"); | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
async run({ $ }) { | ||||||||||||||||||||||||||||||
const warnings = []; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const { | ||||||||||||||||||||||||||||||
wordpress, | ||||||||||||||||||||||||||||||
db, | ||||||||||||||||||||||||||||||
site, | ||||||||||||||||||||||||||||||
postId, | ||||||||||||||||||||||||||||||
number, | ||||||||||||||||||||||||||||||
} = this; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
warnings.push(...wordpress.checkDomainOrId(site)); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
let response; | ||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||
response = await wordpress.getWordpressComments({ | ||||||||||||||||||||||||||||||
$, | ||||||||||||||||||||||||||||||
site, | ||||||||||||||||||||||||||||||
postId, | ||||||||||||||||||||||||||||||
number, | ||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
response = await this.getWordpressComments($); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||||||||||||
wordpress.throwCustomError("Failed to fetch comments from WordPress:", error, warnings); | ||||||||||||||||||||||||||||||
|
@@ -66,22 +102,7 @@ export default { | |||||||||||||||||||||||||||||
const comments = response.comments || []; | ||||||||||||||||||||||||||||||
const lastCommentId = Number(await db.get("lastCommentId")); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// First run: Initialize cursor | ||||||||||||||||||||||||||||||
if (!lastCommentId) { | ||||||||||||||||||||||||||||||
if (!comments.length) { | ||||||||||||||||||||||||||||||
console.log("No comments found on first run. Source initialized with no cursor."); | ||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const newest = comments[0]?.ID; | ||||||||||||||||||||||||||||||
if (!newest) { | ||||||||||||||||||||||||||||||
throw new Error("Failed to initialize: The latest comment does not have a valid ID."); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
await db.set("lastCommentId", newest); | ||||||||||||||||||||||||||||||
console.log(`Initialized lastCommentId on first run with comment ID ${newest}.`); | ||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
if (!lastCommentId) await wordpress.initialize(comments, db, "lastCommentId"); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
let maxCommentIdTracker = lastCommentId; | ||||||||||||||||||||||||||||||
const newComments = []; | ||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,9 +4,19 @@ export default { | |||||||||||||||||||||||||||||
key: "wordpress_com-new-follower", | ||||||||||||||||||||||||||||||
name: "New Follower", | ||||||||||||||||||||||||||||||
description: "Emit new event for each new follower that subscribes to the site.", | ||||||||||||||||||||||||||||||
version: "0.0.1", | ||||||||||||||||||||||||||||||
version: "0.0.3", | ||||||||||||||||||||||||||||||
type: "source", | ||||||||||||||||||||||||||||||
dedupe: "unique", | ||||||||||||||||||||||||||||||
methods: { | ||||||||||||||||||||||||||||||
getWordpressFollowers($) { | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return this.wordpress.getWordpressFollowers({ | ||||||||||||||||||||||||||||||
$, | ||||||||||||||||||||||||||||||
site: this.site, | ||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
props: { | ||||||||||||||||||||||||||||||
wordpress, | ||||||||||||||||||||||||||||||
db: "$.service.db", | ||||||||||||||||||||||||||||||
|
@@ -16,7 +26,39 @@ export default { | |||||||||||||||||||||||||||||
"siteId", | ||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
timer: { | ||||||||||||||||||||||||||||||
type: "$.interface.timer", | ||||||||||||||||||||||||||||||
label: "Timer", | ||||||||||||||||||||||||||||||
description: "How often to poll WordPress for new followers.", | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add default timer
Suggested change
|
||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
hooks: { | ||||||||||||||||||||||||||||||
async activate() { | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const warnings = []; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const { | ||||||||||||||||||||||||||||||
wordpress, | ||||||||||||||||||||||||||||||
db, | ||||||||||||||||||||||||||||||
site, | ||||||||||||||||||||||||||||||
} = this; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
warnings.push(...wordpress.checkDomainOrId(site)); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (warnings.length > 0) { | ||||||||||||||||||||||||||||||
console.log("Warnings:\n- " + warnings.join("\n- ")); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
await this.db.set("lastFollowerId", null); //reset | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const response = await this.getWordpressFollowers(this.wordpress._mock$); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const followers = response.subscribers || []; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
await wordpress.initialize(followers, db, "lastFollowerId"); | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
async run({ $ }) { | ||||||||||||||||||||||||||||||
const warnings = []; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
@@ -30,10 +72,7 @@ export default { | |||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
let response; | ||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||
response = await wordpress.getWordpressFollowers({ | ||||||||||||||||||||||||||||||
$, | ||||||||||||||||||||||||||||||
site, | ||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
response = await this.getWordpressFollowers($); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||||||||||||
wordpress.throwCustomError("Failed to fetch followers from WordPress:", error, warnings); | ||||||||||||||||||||||||||||||
|
@@ -43,22 +82,7 @@ export default { | |||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const lastFollowerId = Number(await db.get("lastFollowerId")); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// First run: Initialize cursor | ||||||||||||||||||||||||||||||
if (!lastFollowerId) { | ||||||||||||||||||||||||||||||
if (!followers.length) { | ||||||||||||||||||||||||||||||
console.log("No followers found on first run. Source initialized with no cursor."); | ||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const newest = followers[0]?.ID; | ||||||||||||||||||||||||||||||
if (!newest) { | ||||||||||||||||||||||||||||||
throw new Error("Failed to initialize: The latest follower does not have a valid ID."); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
await db.set("lastFollowerId", newest); | ||||||||||||||||||||||||||||||
console.log(`Initialized lastFollowerId on first run with follower ID ${newest}.`); | ||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
if (!lastFollowerId) await wordpress.initialize(followers, db, "lastPostId"); | ||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
let maxFollowerIdTracker = lastFollowerId; | ||||||||||||||||||||||||||||||
const newFollowers = []; | ||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,7 +4,7 @@ export default { | |||||||||||||||||||||||||||||
key: "wordpress_com-new-post", | ||||||||||||||||||||||||||||||
name: "New Post", | ||||||||||||||||||||||||||||||
description: "Emit new event for each new post published since the last run. If no new posts, emit nothing.", | ||||||||||||||||||||||||||||||
version: "0.0.1", | ||||||||||||||||||||||||||||||
version: "0.0.4", | ||||||||||||||||||||||||||||||
type: "source", | ||||||||||||||||||||||||||||||
dedupe: "unique", | ||||||||||||||||||||||||||||||
props: { | ||||||||||||||||||||||||||||||
|
@@ -45,7 +45,53 @@ export default { | |||||||||||||||||||||||||||||
min: 1, | ||||||||||||||||||||||||||||||
max: 100, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
timer: { | ||||||||||||||||||||||||||||||
type: "$.interface.timer", | ||||||||||||||||||||||||||||||
label: "Timer", | ||||||||||||||||||||||||||||||
description: "How often to poll WordPress for new posts.", | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add default timer
Suggested change
|
||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
methods: { | ||||||||||||||||||||||||||||||
getWordpressPosts($) { | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return this.wordpress.getWordpressPosts({ | ||||||||||||||||||||||||||||||
$, | ||||||||||||||||||||||||||||||
site: this.site, | ||||||||||||||||||||||||||||||
type: this.type, | ||||||||||||||||||||||||||||||
number: this.number, | ||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
hooks: { | ||||||||||||||||||||||||||||||
async activate() { | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const warnings = [] | ||||||||||||||||||||||||||||||
; const { | ||||||||||||||||||||||||||||||
wordpress, | ||||||||||||||||||||||||||||||
db, | ||||||||||||||||||||||||||||||
type, | ||||||||||||||||||||||||||||||
site, | ||||||||||||||||||||||||||||||
} = this; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
warnings.push(...wordpress.checkDomainOrId(site)); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (warnings.length > 0) { | ||||||||||||||||||||||||||||||
console.log("Warnings:\n- " + warnings.join("\n- ")); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
await this.db.set("lastPostId", null); // reset | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const response = await this.getWordpressPosts(this.wordpress._mock$); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
const posts = (type === "attachment") | ||||||||||||||||||||||||||||||
? (response.media || []) | ||||||||||||||||||||||||||||||
: (response.posts || []); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
await wordpress.initialize(posts, db, "lastPostId"); | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
async run({ $ }) { | ||||||||||||||||||||||||||||||
const warnings = []; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
@@ -54,45 +100,18 @@ export default { | |||||||||||||||||||||||||||||
db, | ||||||||||||||||||||||||||||||
site, | ||||||||||||||||||||||||||||||
type, | ||||||||||||||||||||||||||||||
number, | ||||||||||||||||||||||||||||||
} = this; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
warnings.push(...wordpress.checkDomainOrId(site)); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
let response; | ||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||
response = await wordpress.getWordpressPosts({ | ||||||||||||||||||||||||||||||
$, | ||||||||||||||||||||||||||||||
site, | ||||||||||||||||||||||||||||||
type, | ||||||||||||||||||||||||||||||
number, | ||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
} catch (error) { | ||||||||||||||||||||||||||||||
wordpress.throwCustomError("Failed to fetch posts from WordPress:", error, warnings); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
const response = await this.getWordpressPosts($); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
SokolovskyiK marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
const posts = (type === "attachment") | ||||||||||||||||||||||||||||||
? (response.media || []) | ||||||||||||||||||||||||||||||
: (response.posts || []); | ||||||||||||||||||||||||||||||
const lastPostId = Number(await db.get("lastPostId")); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// First run: Initialize cursor | ||||||||||||||||||||||||||||||
if (!lastPostId) { | ||||||||||||||||||||||||||||||
if (!posts.length) { | ||||||||||||||||||||||||||||||
console.log("No posts found on first run. Source initialized with no cursor."); | ||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const newest = posts[0]?.ID; | ||||||||||||||||||||||||||||||
if (!newest) { | ||||||||||||||||||||||||||||||
throw new Error("Failed to initialize: The latest post does not have a valid ID."); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
await db.set("lastPostId", newest); | ||||||||||||||||||||||||||||||
console.log(`Initialized lastPostId on first run with post ID ${newest}.`); | ||||||||||||||||||||||||||||||
return; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
if (!lastPostId) await wordpress.initialize(posts, db, "lastPostId"); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
let maxPostIdTracker = lastPostId; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the warnings stuff here. Just export the summary as plain text