@@ -80,7 +80,6 @@ export default {
8080 return respondJSON ( origin , allowed , { error : "Invalid or missing Gumroad username." } , 400 ) ;
8181 }
8282
83- const profileUrl = `https://${ u } .gumroad.com/` ;
8483 const cache = caches . default ;
8584 const dataKey = new Request ( `https://gumroad-products.internal/cache?u=${ encodeURIComponent ( u ) } ` ) ;
8685 const metaKey = new Request ( `https://gumroad-products.internal/meta?u=${ encodeURIComponent ( u ) } ` ) ;
@@ -96,7 +95,7 @@ export default {
9695 if ( cachedBody && age <= S_MAX_AGE ) {
9796 return new Response ( cachedBody , {
9897 headers : {
99- "Content-Type" : "application/json ; charset=utf-8" ,
98+ "Content-Type" : "text/html ; charset=utf-8" ,
10099 "Cache-Control" : `public, max-age=${ S_MAX_AGE } ` ,
101100 "X-Cache" : "HIT" ,
102101 "X-Upstream-Status" : "none" ,
@@ -136,7 +135,7 @@ export default {
136135 if ( cachedBody && age <= ( S_MAX_AGE + STALE_WINDOW ) ) {
137136 return new Response ( cachedBody , {
138137 headers : {
139- "Content-Type" : "application/json ; charset=utf-8" ,
138+ "Content-Type" : "text/html ; charset=utf-8" ,
140139 "Cache-Control" : `public, max-age=0, stale-while-revalidate=${ STALE_WINDOW } ` ,
141140 "X-Cache" : "STALE" ,
142141 "X-Upstream-Status" : String ( upstream . status ) ,
@@ -153,22 +152,11 @@ export default {
153152
154153 const html = await upstream . text ( ) ;
155154
156- const products = extractProducts ( html ) ;
157-
158- const payload = {
159- username : u ,
160- profile_url : profileUrl ,
161- count : products . length ,
162- products,
163- fetched_at : new Date ( ) . toISOString ( ) ,
164- } ;
165- const body = JSON . stringify ( payload ) ;
166-
167155 // Update cache
168156 const now = Math . floor ( Date . now ( ) / 1000 ) ;
169- const dataResp = new Response ( body , {
157+ const dataResp = new Response ( html , {
170158 headers : {
171- "Content-Type" : "application/json ; charset=utf-8" ,
159+ "Content-Type" : "text/html ; charset=utf-8" ,
172160 "Cache-Control" : `public, max-age=${ S_MAX_AGE } ` ,
173161 } ,
174162 } ) ;
@@ -178,9 +166,9 @@ export default {
178166 ctx . waitUntil ( cache . put ( dataKey , dataResp . clone ( ) ) ) ;
179167 ctx . waitUntil ( cache . put ( metaKey , metaResp . clone ( ) ) ) ;
180168
181- return new Response ( body , {
169+ return new Response ( html , {
182170 headers : {
183- "Content-Type" : "application/json ; charset=utf-8" ,
171+ "Content-Type" : "text/html ; charset=utf-8" ,
184172 "Cache-Control" : `public, max-age=${ S_MAX_AGE } ` ,
185173 "X-Cache" : cachedBody ? "MISS-REVAL" : "MISS" ,
186174 "X-Upstream-Status" : "200" ,
@@ -189,31 +177,3 @@ export default {
189177 } ) ;
190178 } ,
191179} ;
192-
193- function extractProducts ( html ) {
194- // Lightweight HTML parsing without DOM: heuristic regex over links.
195- // For more robustness, you could use an HTML parser lib with Workers Bundler.
196- const linkRe = / < a \b [ ^ > ] * h r e f = [ " ' ] ( [ ^ " ' ] * \/ l \/ [ ^ " ' ] * ) [ " ' ] [ ^ > ] * > ( [ \s \S ] * ?) < \/ a > / gi;
197- const tagRe = / < \/ ? [ ^ > ] + > / g;
198- const nbspRe = / & n b s p ; / g;
199-
200- const seen = new Set ( ) ;
201- const items = [ ] ;
202- let m ;
203- while ( ( m = linkRe . exec ( html ) ) !== null ) {
204- const href = m [ 1 ] ;
205- let title = m [ 2 ] . replace ( tagRe , '' ) . replace ( nbspRe , ' ' ) . trim ( ) ;
206- if ( ! title ) continue ;
207-
208- // Normalize absolute vs relative
209- const url = href . startsWith ( 'http' ) ? href : new URL ( href , 'https://example.com' ) . href ;
210- const slug = url . split ( '/' ) . filter ( Boolean ) . pop ( ) ;
211-
212- const key = url + '|' + title ;
213- if ( seen . has ( key ) ) continue ;
214- seen . add ( key ) ;
215-
216- items . push ( { title, url, slug } ) ;
217- }
218- return items ;
219- }
0 commit comments