ReviewOS

also looking at this

stacks/postline

feat: crossposting — media (LinkedIn/IG/Threads), OAuth token refresh, and X/Twitter

#30
Merged glennmichael123 wants to merge feat/crosspost-media-and-token-refresh into main
28 files +1810 -109
app/Services/Social/support.tsmodified+23-0
Changes to app/Services/Social/support.ts
@@ -7,6 +7,29 @@ export function now(): string {
77 return new Date().toISOString().slice(0, 19).replace('T', ' ')
88}
99
10/**
11 * A SQLite `YYYY-MM-DD HH:MM:SS` (UTC) timestamp `secondsFromNow` in the
12 * future — used to record when an OAuth access token will expire. Returns null
13 * when the provider didn't report a lifetime, so callers can store NULL.
14 */
15export function expiresAt(secondsFromNow: number | null | undefined): string | null {
16 if (!secondsFromNow || secondsFromNow <= 0) return null
17 return new Date(Date.now() + secondsFromNow * 1000).toISOString().slice(0, 19).replace('T', ' ')
18}
19
20/**
21 * Whether a stored `token_expires_at` (SQLite `YYYY-MM-DD HH:MM:SS`, UTC) is
22 * already past or falls within `withinSeconds` of now — the trigger for a
23 * proactive token refresh before publishing. Unknown/blank/unparseable expiry
24 * returns false: there's nothing to refresh against, so leave the token alone.
25 */
26export function isExpiringSoon(value: string | null | undefined, withinSeconds = 7 * 24 * 60 * 60): boolean {
27 if (!value) return false
28 const expiry = Date.parse(`${String(value).replace(' ', 'T')}Z`)
29 if (Number.isNaN(expiry)) return false
30 return expiry - Date.now() <= withinSeconds * 1000
31}
32
1033export function uuid(): string {
1134 return crypto.randomUUID()
1235}