(()=>{var e={};e.id=473,e.ids=[473],e.modules={28303:e=>{function s(e){var s=Error("Cannot find module '"+e+"'");throw s.code="MODULE_NOT_FOUND",s}s.keys=()=>[],s.resolve=s,s.id=28303,e.exports=s},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")},5209:(e,s,t)=>{"use strict";t.r(s),t.d(s,{patchFetch:()=>_,routeModule:()=>E,serverHooks:()=>d,workAsyncStorage:()=>A,workUnitAsyncStorage:()=>u});var r={};t.r(r),t.d(r,{GET:()=>c});var i=t(42706),o=t(28203),n=t(45994),a=t(39187),T=t(27914);async function c(){try{let[e]=await T.A.execute(`
            SELECT
                c.id, c.title, c.thumbnailUrl,
                s_now.subscriberCount AS subs,
                s_now.viewCount AS views_now,
                s_48.viewCount AS views_48h,
                s_7d.viewCount AS views_7d,
                ROUND(
                    (s_now.viewCount - s_48.viewCount) /
                    NULLIF((s_7d.viewCount / 7), 0) * 100, 1
                ) AS velocity_pct
            FROM channels c
            JOIN channel_stats s_now ON c.id = s_now.channel_id
                AND s_now.date = (SELECT MAX(date) FROM channel_stats WHERE channel_id = c.id)
            LEFT JOIN channel_stats s_48 ON c.id = s_48.channel_id
                AND s_48.date = DATE_SUB(CURDATE(), INTERVAL 2 DAY)
            LEFT JOIN channel_stats s_7d ON c.id = s_7d.channel_id
                AND s_7d.date = DATE_SUB(CURDATE(), INTERVAL 7 DAY)
            WHERE s_48.viewCount IS NOT NULL
              AND s_7d.viewCount IS NOT NULL
              AND s_now.viewCount > s_48.viewCount
            HAVING velocity_pct > 150
            ORDER BY velocity_pct DESC
            LIMIT 20
        `);return a.NextResponse.json({tracked:e,fresh:[]})}catch(e){return console.error("[Anomalies]",e),a.NextResponse.json({error:e.message},{status:500})}}t(12241);let E=new i.AppRouteRouteModule({definition:{kind:o.RouteKind.APP_ROUTE,page:"/api/discover/anomalies/route",pathname:"/api/discover/anomalies",filename:"route",bundlePath:"app/api/discover/anomalies/route"},resolvedPagePath:"C:\\Users\\HP\\Desktop\\youtubenichefinder\\src\\app\\api\\discover\\anomalies\\route.ts",nextConfigOutput:"",userland:r}),{workAsyncStorage:A,workUnitAsyncStorage:u,serverHooks:d}=E;function _(){return(0,n.patchFetch)({workAsyncStorage:A,workUnitAsyncStorage:u})}},96487:()=>{},78335:()=>{},27914:(e,s,t)=>{"use strict";t.d(s,{A:()=>r});let r=t(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,s,t)=>{"use strict";var r=t(27914);let i=!1;(async function(){i||(i=!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 s=require("../../../../webpack-runtime.js");s.C(e);var t=e=>s(s.s=e),r=s.X(0,[638,452,820],()=>t(5209));module.exports=r})();