Spaces:
Runtime error
Runtime error
Commit ·
f0f2816
1
Parent(s): d5ba005
feat: Introduce database utility scripts, refactor video product retrieval, and ensure correct creator slug usage in the showcase service.
Browse files- check-slugs.ts +35 -0
- db-check.ts +29 -0
- src/features/vault/services/showcase.service.ts +6 -3
- src/features/vault/services/vault.service.ts +1 -0
check-slugs.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { db } from './src/lib/db';
|
| 2 |
+
import { youtubeChannels, youtubeVideos } from './src/lib/db/schema';
|
| 3 |
+
import { eq } from 'drizzle-orm';
|
| 4 |
+
|
| 5 |
+
async function check() {
|
| 6 |
+
try {
|
| 7 |
+
console.log('Fetching all channels...');
|
| 8 |
+
const channels = await db.select().from(youtubeChannels);
|
| 9 |
+
console.log('Channels found:', channels.length);
|
| 10 |
+
channels.forEach(c => {
|
| 11 |
+
console.log(`- Slug: ${c.creatorSlug}, ID: ${c.id}, Creator: ${c.creatorId}`);
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
const videoId = 'XSa42Zz_vps';
|
| 15 |
+
console.log(`\nChecking video associations for: ${videoId}`);
|
| 16 |
+
const videos = await db.select({
|
| 17 |
+
video: youtubeVideos,
|
| 18 |
+
channel: youtubeChannels
|
| 19 |
+
})
|
| 20 |
+
.from(youtubeVideos)
|
| 21 |
+
.innerJoin(youtubeChannels, eq(youtubeVideos.channelId, youtubeChannels.id))
|
| 22 |
+
.where(eq(youtubeVideos.videoId, videoId));
|
| 23 |
+
|
| 24 |
+
console.log('Video records found:', videos.length);
|
| 25 |
+
videos.forEach(v => {
|
| 26 |
+
console.log(`- Video Record ID: ${v.video.id}, Channel Slug: ${v.channel.creatorSlug}, Channel ID: ${v.channel.id}`);
|
| 27 |
+
});
|
| 28 |
+
|
| 29 |
+
} catch (err) {
|
| 30 |
+
console.error('Check failed:', err);
|
| 31 |
+
}
|
| 32 |
+
process.exit(0);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
check();
|
db-check.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { db } from './src/lib/db';
|
| 2 |
+
import { youtubeChannels, youtubeVideos } from './src/lib/db/schema';
|
| 3 |
+
import { eq, and } from 'drizzle-orm';
|
| 4 |
+
|
| 5 |
+
async function check() {
|
| 6 |
+
try {
|
| 7 |
+
const videoId = 'XSa42Zz_vps';
|
| 8 |
+
console.log(`Checking video: ${videoId}`);
|
| 9 |
+
|
| 10 |
+
const results = await db
|
| 11 |
+
.select({
|
| 12 |
+
id: youtubeVideos.id,
|
| 13 |
+
videoId: youtubeVideos.videoId,
|
| 14 |
+
channelId: youtubeVideos.channelId,
|
| 15 |
+
creatorSlug: youtubeChannels.creatorSlug,
|
| 16 |
+
creatorId: youtubeChannels.creatorId
|
| 17 |
+
})
|
| 18 |
+
.from(youtubeVideos)
|
| 19 |
+
.innerJoin(youtubeChannels, eq(youtubeVideos.channelId, youtubeChannels.id))
|
| 20 |
+
.where(eq(youtubeVideos.videoId, videoId));
|
| 21 |
+
|
| 22 |
+
console.log('Results:', JSON.stringify(results, null, 2));
|
| 23 |
+
} catch (err) {
|
| 24 |
+
console.error('Error:', err);
|
| 25 |
+
}
|
| 26 |
+
process.exit(0);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
check();
|
src/features/vault/services/showcase.service.ts
CHANGED
|
@@ -94,7 +94,6 @@ export class ShowcaseService {
|
|
| 94 |
const channel = videoResult[0]?.channel;
|
| 95 |
|
| 96 |
if (video && channel) {
|
| 97 |
-
console.log(`[getShowcaseVault] Found video record: ${video.id} (scanStatus: ${video.scanStatus})`);
|
| 98 |
// Attach channel for the 'with' equivalent
|
| 99 |
const videoWithChannel = { ...video, channel };
|
| 100 |
// Self-healing: If subscriberCount is missing or 0, trigger a background refresh
|
|
@@ -230,7 +229,7 @@ export class ShowcaseService {
|
|
| 230 |
channelName: channel.creatorId === DEMO_USER_ID ? channel.channelName : publicData.vault.channel.channelName,
|
| 231 |
subscriberCount: channel.creatorId === DEMO_USER_ID ? channel.subscriberCount : publicData.vault.channel.subscriberCount,
|
| 232 |
thumbnailUrl: channel.creatorId === DEMO_USER_ID ? channel.thumbnailUrl : publicData.vault.channel.thumbnailUrl,
|
| 233 |
-
creatorSlug: channel.
|
| 234 |
creatorId: channel.creatorId,
|
| 235 |
},
|
| 236 |
videos: [{
|
|
@@ -297,7 +296,11 @@ export class ShowcaseService {
|
|
| 297 |
* @param videoId - The YouTube video ID
|
| 298 |
* @param userId - Optional user ID to resolve the correct record in multi-tenant scenarios
|
| 299 |
*/
|
| 300 |
-
static async
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
const videoResult = await db
|
| 302 |
.select({
|
| 303 |
video: youtubeVideos,
|
|
|
|
| 94 |
const channel = videoResult[0]?.channel;
|
| 95 |
|
| 96 |
if (video && channel) {
|
|
|
|
| 97 |
// Attach channel for the 'with' equivalent
|
| 98 |
const videoWithChannel = { ...video, channel };
|
| 99 |
// Self-healing: If subscriberCount is missing or 0, trigger a background refresh
|
|
|
|
| 229 |
channelName: channel.creatorId === DEMO_USER_ID ? channel.channelName : publicData.vault.channel.channelName,
|
| 230 |
subscriberCount: channel.creatorId === DEMO_USER_ID ? channel.subscriberCount : publicData.vault.channel.subscriberCount,
|
| 231 |
thumbnailUrl: channel.creatorId === DEMO_USER_ID ? channel.thumbnailUrl : publicData.vault.channel.thumbnailUrl,
|
| 232 |
+
creatorSlug: channel.creatorSlug, // CRITICAL: Use the real DB slug for routing
|
| 233 |
creatorId: channel.creatorId,
|
| 234 |
},
|
| 235 |
videos: [{
|
|
|
|
| 296 |
* @param videoId - The YouTube video ID
|
| 297 |
* @param userId - Optional user ID to resolve the correct record in multi-tenant scenarios
|
| 298 |
*/
|
| 299 |
+
static async getVideoProducts(videoId: string, creatorSlug?: string) {
|
| 300 |
+
// Build where conditions
|
| 301 |
+
const whereConditions = [
|
| 302 |
+
sql`${youtubeVideos.id} = ${videoId} OR ${youtubeVideos.videoId} = ${videoId}`
|
| 303 |
+
];
|
| 304 |
const videoResult = await db
|
| 305 |
.select({
|
| 306 |
video: youtubeVideos,
|
src/features/vault/services/vault.service.ts
CHANGED
|
@@ -642,6 +642,7 @@ export class VaultService {
|
|
| 642 |
* @param creatorSlug - Optional creator slug to resolve the correct record in multi-tenant scenarios
|
| 643 |
*/
|
| 644 |
static async getVideoProducts(videoId: string, creatorSlug?: string) {
|
|
|
|
| 645 |
// Build where conditions
|
| 646 |
const whereConditions = [
|
| 647 |
sql`${youtubeVideos.id} = ${videoId} OR ${youtubeVideos.videoId} = ${videoId}`
|
|
|
|
| 642 |
* @param creatorSlug - Optional creator slug to resolve the correct record in multi-tenant scenarios
|
| 643 |
*/
|
| 644 |
static async getVideoProducts(videoId: string, creatorSlug?: string) {
|
| 645 |
+
console.log(`[getVideoProducts] videoId: ${videoId}, creatorSlug: ${creatorSlug}`);
|
| 646 |
// Build where conditions
|
| 647 |
const whereConditions = [
|
| 648 |
sql`${youtubeVideos.id} = ${videoId} OR ${youtubeVideos.videoId} = ${videoId}`
|