File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,8 +15,18 @@ const NEWS_CONFIG = {
1515 proxyUrl : 'https://proxy-for-blogs-rss-in-dashboard.greptime.workers.dev' ,
1616}
1717const CACHE_KEY = 'greptime_news_cache'
18+ const UID_KEY = 'greptime_anon_id'
1819const TTL_MS = 10 * 60 * 1000
1920
21+ const getAnonId = ( ) => {
22+ let id = localStorage . getItem ( UID_KEY )
23+ if ( ! id ) {
24+ id = crypto . randomUUID ( )
25+ localStorage . setItem ( UID_KEY , id )
26+ }
27+ return id
28+ }
29+
2030const setCachedNews = ( items : NewsItem [ ] ) => {
2131 const data = {
2232 items,
@@ -91,14 +101,16 @@ const parseXmlRss = (xmlString: string): NewsItem[] => {
91101export const fetchGreptimeNews = async ( ) : Promise < NewsResponse > => {
92102 try {
93103 const cached = getCachedNews ( )
104+ const anonId = getAnonId ( )
94105 if ( cached ) {
95106 return cached
96107 }
97108
98109 const response = await fetch ( NEWS_CONFIG . proxyUrl , {
99110 method : 'GET' ,
100111 headers : {
101- Accept : 'application/xml, text/xml, */*' ,
112+ 'Accept' : 'application/xml, text/xml, */*' ,
113+ 'X-Oss-Uid' : anonId ,
102114 } ,
103115 } )
104116
You can’t perform that action at this time.
0 commit comments