@@ -1200,40 +1200,34 @@ async function determineIsRelativeAndBaseUrl(
12001200 userBaseUrl : string | undefined ,
12011201 feedUrl : string | undefined ,
12021202) : Promise < { isRelative : boolean ; baseUrl : string | undefined } > {
1203+ // If user explicitly set both isRelative and baseUrl, use those
12031204 if ( typeof userIsRelative === "boolean" && userBaseUrl ) {
12041205 return { isRelative : userIsRelative , baseUrl : userBaseUrl } ;
12051206 }
1207+
1208+ // If user explicitly set isRelative
12061209 if ( typeof userIsRelative === "boolean" ) {
12071210 if ( userIsRelative && ! userBaseUrl && feedUrl ) {
12081211 return { isRelative : true , baseUrl : feedUrl } ;
12091212 }
12101213 return { isRelative : userIsRelative , baseUrl : userBaseUrl } ;
12111214 }
1215+
1216+ // If user provided baseUrl but not isRelative, detect from URL format
12121217 if ( userBaseUrl ) {
1213- if ( isLikelyAbsoluteUrl ( url ) ) {
1214- return { isRelative : false , baseUrl : userBaseUrl } ;
1215- } else {
1216- return { isRelative : true , baseUrl : userBaseUrl } ;
1217- }
1218+ const isAbs = isLikelyAbsoluteUrl ( url ) ;
1219+ return { isRelative : ! isAbs , baseUrl : userBaseUrl } ;
12181220 }
1219- if ( isLikelyAbsoluteUrl ( url ) ) {
1220- try {
1221- const resp = await axios . head ( url , {
1222- maxRedirects : 2 ,
1223- validateStatus : ( ) => true ,
1224- } ) ;
1225- if ( resp . status >= 200 && resp . status < 600 ) {
1226- return { isRelative : false , baseUrl : undefined } ;
1227- }
1228- } catch {
1229- if ( feedUrl ) return { isRelative : true , baseUrl : feedUrl } ;
1230- return { isRelative : true , baseUrl : undefined } ;
1231- }
1232- if ( feedUrl ) return { isRelative : true , baseUrl : feedUrl } ;
1233- return { isRelative : true , baseUrl : undefined } ;
1221+
1222+ // Auto-detect based on URL format
1223+ const isAbsolute = isLikelyAbsoluteUrl ( url ) ;
1224+
1225+ if ( isAbsolute ) {
1226+ return { isRelative : false , baseUrl : undefined } ;
1227+ } else {
1228+ // Relative URL - use feedUrl as base if available
1229+ return { isRelative : true , baseUrl : feedUrl } ;
12341230 }
1235- if ( feedUrl ) return { isRelative : true , baseUrl : feedUrl } ;
1236- return { isRelative : true , baseUrl : undefined } ;
12371231}
12381232
12391233function extractSampleUrlFromHtml (
@@ -1242,12 +1236,27 @@ function extractSampleUrlFromHtml(
12421236 attribute ?: string ,
12431237) : string {
12441238 const $ = cheerio . load ( html ) ;
1245- const el = $ ( selector ) . first ( ) ;
1246- if ( ! el . length ) return "" ;
1247- if ( attribute ) {
1248- return el . attr ( attribute ) || "" ;
1239+ const elements = $ ( selector ) . slice ( 0 , 5 ) ; // Check first 5 elements
1240+
1241+ if ( elements . length === 0 ) return "" ;
1242+
1243+ // Try to find a non-empty URL from the sample
1244+ for ( let i = 0 ; i < elements . length ; i ++ ) {
1245+ const el = elements . eq ( i ) ;
1246+ let url = "" ;
1247+ if ( attribute ) {
1248+ url = el . attr ( attribute ) || "" ;
1249+ } else {
1250+ url = el . attr ( "href" ) || el . attr ( "src" ) || "" ;
1251+ }
1252+
1253+ // Return first non-empty URL found
1254+ if ( url && url . trim ( ) ) {
1255+ return url . trim ( ) ;
1256+ }
12491257 }
1250- return el . attr ( "href" ) || el . attr ( "src" ) || "" ;
1258+
1259+ return "" ;
12511260}
12521261
12531262async function buildCSSTarget (
@@ -1287,6 +1296,7 @@ async function buildCSSTarget(
12871296 ) ;
12881297 isRelative = result . isRelative ;
12891298 baseUrl = result . baseUrl ;
1299+ console . log ( `[Preview ${ prefix } ] Sample URL: "${ urlSample } " → isRelative: ${ isRelative } , baseUrl: ${ baseUrl } ` ) ;
12901300 }
12911301
12921302 // Extract drill chain data directly if it was pre-processed into an array of objects
@@ -1564,9 +1574,12 @@ async function generatePreview(feedConfig: any) {
15641574 } ,
15651575 maxContentLength : 2 * 1024 * 1024 ,
15661576 maxBodyLength : 2 * 1024 * 1024 ,
1577+ timeout : 30000 , // 30 second timeout
15671578 } ) ;
1579+ console . log ( "[Preview] Page fetched, building RSS..." ) ;
15681580 const html = response . data ;
15691581 rssXml = await buildRSS ( html , feedConfig ) ;
1582+ console . log ( "[Preview] RSS build complete" ) ;
15701583 }
15711584 } else if ( feedConfig . feedType === "api" ) {
15721585 // feedConfig.config contains API call details (baseUrl, route, method, params, apiSpecificHeaders, apiSpecificBody)
0 commit comments