ReviewOS

also looking at this

stacks/postline

feat: crosspost to LinkedIn and Instagram

#1
Merged chris wants to merge feat/crosspost-linkedin-instagram into main
31 files +2335 -87
app/Services/Social/support.tsadded+46-0
Changes to app/Services/Social/support.ts
@@ -0,0 +1,46 @@
1import { db } from '@stacksjs/database'
2
3const database = db as any
4
5/** SQLite-friendly `YYYY-MM-DD HH:MM:SS` timestamp. */
6export function now(): string {
7 return new Date().toISOString().slice(0, 19).replace('T', ' ')
8}
9
10export function uuid(): string {
11 return crypto.randomUUID()
12}
13
14/**
15 * Postline is currently single-account. Return the existing account id, or
16 * create the default workspace on first use. Shared by every social service
17 * so a crosspost groups all of its targets under one account/post.
18 */
19export async function ensureAccount(): Promise<number> {
20 const existing = await database
21 .selectFrom('accounts')
22 .select(['id'])
23 .orderBy('id', 'asc')
24 .executeTakeFirst()
25
26 if (existing?.id) return Number(existing.id)
27
28 const accountUuid = uuid()
29 await database.insertInto('accounts').values({
30 uuid: accountUuid,
31 name: 'Chris Breuer',
32 workspace_name: 'Postline',
33 timezone: 'America/Los_Angeles',
34 default_audience: 'public',
35 created_at: now(),
36 updated_at: now(),
37 }).execute()
38
39 const account = await database
40 .selectFrom('accounts')
41 .select(['id'])
42 .where('uuid', '=', accountUuid)
43 .executeTakeFirstOrThrow()
44
45 return Number(account.id)
46}