feat(sync): sélecteur de chaîne YouTube (multi-chaînes/marque) via PageId

This commit is contained in:
2026-09-27 08:05:01 -04:00
parent d3836989ea
commit f038f19b71
7 changed files with 216 additions and 4 deletions
+16
View File
@@ -1397,6 +1397,12 @@ function ensureOAuthTables() {
PRIMARY KEY (user_id, provider)
);`);
db.exec(`CREATE INDEX IF NOT EXISTS idx_oauth_connections_user ON oauth_connections(user_id);`);
// Chaîne YouTube sélectionnée (multi-chaînes / marque) : ajout idempotent.
try {
const cols = db.prepare(`PRAGMA table_info(oauth_connections)`).all().map((c) => c.name);
if (!cols.includes('yt_channel_id')) db.exec(`ALTER TABLE oauth_connections ADD COLUMN yt_channel_id TEXT`);
if (!cols.includes('yt_page_id')) db.exec(`ALTER TABLE oauth_connections ADD COLUMN yt_page_id TEXT`);
} catch {}
} catch {}
}
ensureOAuthTables();
@@ -1417,9 +1423,19 @@ function oauthRowToDto(row, withTokens = false) {
dto.accessToken = row.access_token || null;
dto.refreshToken = row.refresh_token || null;
}
dto.ytChannelId = row.yt_channel_id || null;
dto.ytPageId = row.yt_page_id || null;
return dto;
}
export function setOAuthChannel(userId, provider, { channelId, pageId }) {
ensureOAuthTables();
db.prepare(`UPDATE oauth_connections SET yt_channel_id = ?, yt_page_id = ?, updated_at = ?
WHERE user_id = ? AND provider = ?`)
.run(channelId || null, pageId || null, Date.now(), userId, provider);
return getOAuthConnection(userId, provider);
}
export function upsertOAuthConnection({ userId, provider, externalUserId, displayName, avatarUrl, accessToken, refreshToken, expiresAt, scopes }) {
ensureOAuthTables();
const now = Date.now();