tangled
alpha
login
or
join now
socksthewolf.com
/
skyscheduler
2
fork
atom
Schedule posts to Bluesky with Cloudflare workers.
skyscheduler.work
cf
tool
bsky-tool
cloudflare
bluesky
schedule
bsky
service
social-media
cloudflare-workers
2
fork
atom
overview
issues
pulls
pipelines
small cleanup
SocksTheWolf
1 month ago
fbb86501
a22309d5
+18
-16
2 changed files
expand all
collapse all
unified
split
src
utils
db
data.ts
dbQuery.ts
+2
-2
src/utils/db/data.ts
···
1
1
import {
2
2
-
and, eq, inArray,
2
2
+
and, eq, inArray, asc,
3
3
lte, ne, notInArray, sql
4
4
} from "drizzle-orm";
5
5
import { BatchItem } from "drizzle-orm/batch";
···
45
45
)
46
46
));
47
47
const results = await db.with(postsToMake).select().from(postsToMake)
48
48
-
.where(notInArray(postsToMake.userId, violationUsers)).all();
48
48
+
.where(notInArray(postsToMake.userId, violationUsers)).orderBy(asc(postsToMake.createdAt)).all();
49
49
return results.map((item) => createPostObject(item));
50
50
};
51
51
+16
-14
src/utils/dbQuery.ts
···
142
142
}
143
143
}
144
144
145
145
-
// Check to see if this post already exists
146
146
-
let rootPostID = undefined;
147
147
-
let parentPostID = undefined;
145
145
+
// Check to see if this post already exists for thread
146
146
+
let rootPostID:string|undefined = undefined;
147
147
+
let parentPostID:string|undefined = undefined;
148
148
+
let rootPostData: Post|null = null;
148
149
if (uuidValid(rootPost)) {
149
149
-
if (await doesPostExist(c.env, userId, rootPost!)) {
150
150
-
rootPostID = rootPost!;
150
150
+
// returns null if the post doesn't appear on this account
151
151
+
rootPostData = await getPostById(c, rootPost!);
152
152
+
if (rootPostData !== null) {
153
153
+
if (rootPostData.posted) {
154
154
+
return { ok: false, msg: "You cannot make threads off already posted posts"};
155
155
+
}
156
156
+
rootPostID = rootPostData.rootPost!;
151
157
// If this isn't a direct reply, check directly underneath it
152
158
if (rootPost !== parentPost) {
153
159
if (uuidValid(parentPost)) {
···
164
170
return { ok: false, msg: "The given root post cannot be found on your account"};
165
171
}
166
172
}
167
167
-
const isThreadedPost: boolean = (rootPostID !== undefined && parentPostID !== undefined);
173
173
+
const isThreadedPost:boolean = (rootPostID !== undefined && parentPostID !== undefined);
168
174
169
175
// Create repost metadata
170
170
-
let scheduleGUID:string|undefined;
171
171
-
let repostInfo:RepostInfo|undefined;
172
172
-
if (!isThreadedPost) {
173
173
-
scheduleGUID = uuidv4();
174
174
-
repostInfo = createRepostInfo(scheduleGUID, scheduleDate, false, repostData);
175
175
-
}
176
176
+
const scheduleGUID = (!isThreadedPost) ? uuidv4() : undefined;
177
177
+
const repostInfo = (!isThreadedPost) ? createRepostInfo(scheduleGUID!, scheduleDate, false, repostData) : undefined;
176
178
177
179
// Create the posts
178
180
const postUUID = uuidv4();
···
181
183
content,
182
184
uuid: postUUID,
183
185
postNow: makePostNow,
184
184
-
scheduledDate: scheduleDate,
186
186
+
scheduledDate: (!isThreadedPost) ? scheduleDate : new Date(rootPostData?.scheduledDate!),
185
187
/*isThread: isThreadedPost,
186
188
rootPost: rootPostID,
187
189
parentPost: parentPostID,*/
188
188
-
repostInfo: !isThreadedPost ? [repostInfo!] : [],
190
190
+
repostInfo: (!isThreadedPost) ? [repostInfo!] : [],
189
191
embedContent: embeds,
190
192
contentLabel: label || PostLabel.None,
191
193
userId: userId