-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,38 @@ | ||
import supabase from '../../db/supabase.js' | ||
|
||
const dev_channelids = process.env.DEV_CHANNELIDS?.split(',') ?? [] | ||
export async function getAccountIds(): Promise<string[]> { | ||
console.log('[TWITCHSETUP] Running getAccountIds') | ||
|
||
if (process.env.NODE_ENV === 'development') { | ||
if (!dev_channelids.length) throw new Error('Missing DEV_CHANNELIDS') | ||
return dev_channelids | ||
} | ||
const devIds = process.env.DEV_CHANNELIDS?.split(',') ?? [] | ||
const isDevMode = process.env.NODE_ENV === 'development' | ||
let providerIds: string[] = [] | ||
|
||
if (isDevMode) { | ||
if (!devIds.length) throw new Error('Missing DEV_CHANNELIDS') | ||
|
||
const { data } = await supabase | ||
.from('users') | ||
.select('id,accounts(providerAccountId)') | ||
.in('name', process.env.DEV_CHANNELS?.split(',') ?? []) | ||
.neq('accounts.requires_refresh', true) | ||
.order('followers', { ascending: false, nullsFirst: false }) | ||
|
||
const { data: users } = await supabase | ||
.from('users') | ||
.select('id') | ||
.order('followers', { ascending: false, nullsFirst: false }) | ||
providerIds = | ||
data?.map((user) => user?.accounts?.[0]?.providerAccountId as string) ?? providerIds | ||
} else { | ||
const { data } = await supabase | ||
.from('users') | ||
.select('id,accounts(providerAccountId)') | ||
.not('name', 'in', `(${process.env.DEV_CHANNELS})`) | ||
.neq('accounts.requires_refresh', true) | ||
.order('followers', { ascending: false, nullsFirst: false }) | ||
|
||
providerIds = | ||
data?.map((user) => user?.accounts?.[0]?.providerAccountId as string) ?? providerIds | ||
} | ||
|
||
const accountIds: string[] = users?.map((user) => user.id as string) ?? [] | ||
providerIds = providerIds.filter(Boolean) | ||
console.log('joining', providerIds.length, 'channels') | ||
|
||
return accountIds | ||
return providerIds | ||
} |