Post one toot at a time, save lastProcessedPostId after each one
⚠️ Untested change ⚠️ This jumped out at me as a potential problem if there were a number of toots to be cross-posted in one go. Firing them all off at once means that they could potentially end up on bluesky out-of-order. Additionally, if any failed to cross-post, saving after each successful one would allow the script to pick up where it left off. I was thinking about changing the script to copy over all of my toots, not just future ones, but I realized that just writing a 1 to the lastProcessedPostId.txt would do that, and then this change would ensure it went in order and was recoverable. I'll try it out sometime soon - I was going to just file a bug report, but I figured it'd be easier to make the change than to describe it.
This commit is contained in:
parent
28a8829128
commit
49eb29b463
1 changed files with 4 additions and 2 deletions
6
main.js
6
main.js
|
@ -64,7 +64,7 @@ async function fetchNewPosts() {
|
||||||
|
|
||||||
let newTimestampId = 0;
|
let newTimestampId = 0;
|
||||||
|
|
||||||
reversed.forEach(item => {
|
for(let item of reversed) {
|
||||||
const currentTimestampId = Date.parse(item.published);
|
const currentTimestampId = Date.parse(item.published);
|
||||||
|
|
||||||
if(currentTimestampId > newTimestampId) {
|
if(currentTimestampId > newTimestampId) {
|
||||||
|
@ -73,7 +73,9 @@ async function fetchNewPosts() {
|
||||||
|
|
||||||
if(currentTimestampId > lastProcessedPostId && lastProcessedPostId != 0) {
|
if(currentTimestampId > lastProcessedPostId && lastProcessedPostId != 0) {
|
||||||
const text = removeHtmlTags(item.object.content);
|
const text = removeHtmlTags(item.object.content);
|
||||||
postToBluesky(text);
|
await postToBluesky(text);
|
||||||
|
lastProcessedPostId = newTimestampId;
|
||||||
|
await saveLastProcessedPostId();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue