(()=>{var e={};e.id=32,e.ids=[32],e.modules={28303:e=>{function t(e){var t=Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}t.keys=()=>[],t.resolve=t,t.id=28303,e.exports=t},10846:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},44870:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},3295:e=>{"use strict";e.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},29294:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-async-storage.external.js")},63033:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},79428:e=>{"use strict";e.exports=require("buffer")},55511:e=>{"use strict";e.exports=require("crypto")},94735:e=>{"use strict";e.exports=require("events")},91645:e=>{"use strict";e.exports=require("net")},19771:e=>{"use strict";e.exports=require("process")},27910:e=>{"use strict";e.exports=require("stream")},41204:e=>{"use strict";e.exports=require("string_decoder")},66136:e=>{"use strict";e.exports=require("timers")},34631:e=>{"use strict";e.exports=require("tls")},79551:e=>{"use strict";e.exports=require("url")},28354:e=>{"use strict";e.exports=require("util")},74075:e=>{"use strict";e.exports=require("zlib")},4573:e=>{"use strict";e.exports=require("node:buffer")},99959:(e,t,s)=>{"use strict";s.r(t),s.d(t,{patchFetch:()=>p,routeModule:()=>l,serverHooks:()=>A,workAsyncStorage:()=>E,workUnitAsyncStorage:()=>d});var r={};s.r(r),s.d(r,{GET:()=>T});var o=s(42706),i=s(28203),n=s(45994),a=s(39187),c=s(27914),u=s(89768);async function T(){try{let[e]=await c.A.execute(`SELECT title, channel FROM algo_feed_snapshots
             WHERE crawled_at > NOW() - INTERVAL 12 HOUR
             ORDER BY crawled_at DESC LIMIT 300`);if(e.length<5)return a.NextResponse.json({clusters:[],message:"Not enough data — run the Crawl first."});let t=(0,u.w)(e,2);return a.NextResponse.json({clusters:t,total:e.length})}catch(e){return console.error("[Cluster]",e),a.NextResponse.json({error:e.message},{status:500})}}s(12241);let l=new o.AppRouteRouteModule({definition:{kind:i.RouteKind.APP_ROUTE,page:"/api/discover/cluster/route",pathname:"/api/discover/cluster",filename:"route",bundlePath:"app/api/discover/cluster/route"},resolvedPagePath:"C:\\Users\\HP\\Desktop\\youtubenichefinder\\src\\app\\api\\discover\\cluster\\route.ts",nextConfigOutput:"",userland:r}),{workAsyncStorage:E,workUnitAsyncStorage:d,serverHooks:A}=l;function p(){return(0,n.patchFetch)({workAsyncStorage:E,workUnitAsyncStorage:d})}},96487:()=>{},78335:()=>{},89768:(e,t,s)=>{"use strict";s.d(t,{w:()=>o});let r=new Set(["the","a","an","and","or","but","in","on","at","to","for","of","with","is","are","was","were","be","been","being","have","has","had","do","does","did","will","would","could","should","may","might","can","i","you","he","she","we","they","it","this","that","these","those","my","your","his","her","our","their","its","me","him","us","them","what","how","why","when","where","who","all","any","both","each","few","more","most","other","some","such","no","not","only","own","same","so","than","too","very","just","about","after","before","between","up","down","out","off","over","under","new","get","got","make","made","go","going","gone","also","from","by","into","through","during","s","t","re","m","ll","ve","d","isn","aren"]);function o(e,t=2){let s=e.map(e=>({...e,tokens:new Set(function(e){let t=e.toLowerCase().replace(/[^a-z0-9\s]/g," ").split(/\s+/).filter(e=>e.length>3&&!r.has(e)),s=[];for(let e=0;e<t.length-1;e++)s.push(`${t[e]} ${t[e+1]}`);return[...t,...s]}(e.title))})),i=s.map(e=>[...e.tokens]),n=function(e){let t=new Map,s=e.length;for(let s of e)for(let e of new Set(s))t.set(e,(t.get(e)||0)+1);let r=new Map;return t.forEach((e,t)=>{r.set(t,Math.log((s+1)/(e+1))+1)}),r}(i),a=new Map;for(let e of i)for(let t of e)a.set(t,(a.get(t)||0)+1);let c=i.length,u=[...a.entries()].filter(([,e])=>e>=t&&e<.7*c).sort((e,t)=>{let s=(n.get(e[0])||1)*e[1];return(n.get(t[0])||1)*t[1]-s}).slice(0,60).map(([e])=>e),T=new Set,l=[];for(let e of u){let r=s.map((e,t)=>({item:e,idx:t})).filter(({item:t,idx:s})=>!T.has(s)&&t.tokens.has(e));if(r.length<t)continue;let o=[];for(let e of u)r.filter(({item:t})=>t.tokens.has(e)).length>=t&&o.push(e);for(let{idx:e}of r)T.add(e);let i=new Set(r.map(e=>e.item.sessionId||"x")).size;l.push({name:o.slice(0,3).join(" \xb7 "),keywords:o.slice(0,10),titles:r.map(e=>e.item.title),channels:[...new Set(r.map(e=>e.item.channel))],score:20*i+5*r.length})}return l.sort((e,t)=>t.score-e.score).slice(0,20)}},27914:(e,t,s)=>{"use strict";s.d(t,{A:()=>r});let r=s(60820).createPool({host:process.env.DB_HOST||"localhost",user:process.env.DB_USER||"root",password:process.env.DB_PASSWORD||"",database:process.env.DB_NAME||"youtube",waitForConnections:!0,connectionLimit:10,maxIdle:10,idleTimeout:6e4,queueLimit:0,enableKeepAlive:!0,keepAliveInitialDelay:0})},12241:(e,t,s)=>{"use strict";var r=s(27914);let o=!1;(async function(){o||(o=!0,await r.A.execute(`
        CREATE TABLE IF NOT EXISTS algo_feed_snapshots (
            id          INT AUTO_INCREMENT PRIMARY KEY,
            session_id  VARCHAR(36) NOT NULL,
            title       TEXT NOT NULL,
            channel     VARCHAR(255),
            views       VARCHAR(50),
            video_id    VARCHAR(50),
            thumbnail   TEXT,
            source      VARCHAR(100) DEFAULT 'trending',
            crawled_at  TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
            INDEX idx_session (session_id),
            INDEX idx_crawled (crawled_at)
        )
    `),await r.A.execute(`
        CREATE TABLE IF NOT EXISTS discovered_niches (
            id              INT AUTO_INCREMENT PRIMARY KEY,
            name            VARCHAR(255) NOT NULL,
            keywords        TEXT,
            source          VARCHAR(50) DEFAULT 'algo_feed',
            session_count   INT DEFAULT 1,
            item_count      INT DEFAULT 1,
            score           FLOAT DEFAULT 0,
            sample_titles   TEXT,
            sample_channels TEXT,
            last_seen       TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            created_at      TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
            INDEX idx_source (source),
            INDEX idx_score (score DESC),
            INDEX idx_last_seen (last_seen)
        )
    `),await r.A.execute(`
        CREATE TABLE IF NOT EXISTS channel_snapshots (
            id              INT AUTO_INCREMENT PRIMARY KEY,
            channel_id      VARCHAR(100) NOT NULL,
            channel_title   VARCHAR(255),
            subscribers     BIGINT DEFAULT 0,
            total_views     BIGINT DEFAULT 0,
            video_count     INT DEFAULT 0,
            snapped_at      TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
            INDEX idx_channel (channel_id),
            INDEX idx_snapped (snapped_at)
        )
    `),await r.A.execute(`
        CREATE TABLE IF NOT EXISTS niche_score_history (
            id            INT AUTO_INCREMENT PRIMARY KEY,
            niche_name    VARCHAR(255) NOT NULL,
            score         FLOAT NOT NULL,
            session_count INT DEFAULT 1,
            item_count    INT DEFAULT 1,
            crawled_at    TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
            INDEX idx_name (niche_name),
            INDEX idx_crawled (crawled_at)
        )
    `),await r.A.execute(`
        CREATE TABLE IF NOT EXISTS saved_niches (
            id                INT AUTO_INCREMENT PRIMARY KEY,
            keyword           VARCHAR(255) NOT NULL UNIQUE,
            white_space_score INT DEFAULT 0,
            label             VARCHAR(100) DEFAULT '',
            notes             TEXT,
            saved_at          TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
            last_checked      TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            INDEX idx_keyword (keyword),
            INDEX idx_saved (saved_at DESC)
        )
    `))})().catch(e=>console.error("[DiscoverDB] init error:",e))}};var t=require("../../../../webpack-runtime.js");t.C(e);var s=e=>t(t.s=e),r=t.X(0,[638,452,820],()=>s(99959));module.exports=r})();