mirror of
https://github.com/vega-org/vega-providers.git
synced 2026-04-17 23:51:44 +00:00
1 line
3.0 KiB
JavaScript
1 line
3.0 KiB
JavaScript
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__name=(e,t)=>__defProp(e,"name",{value:t,configurable:!0}),__export=(e,t)=>{for(var r in t)__defProp(e,r,{get:t[r],enumerable:!0})},__copyProps=(e,t,r,a)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let o of __getOwnPropNames(t))__hasOwnProp.call(e,o)||o===r||__defProp(e,o,{get:()=>t[o],enumerable:!(a=__getOwnPropDesc(t,o))||a.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),__async=(e,t,r)=>new Promise((a,o)=>{var s=e=>{try{i(r.next(e))}catch(e){o(e)}},n=e=>{try{i(r.throw(e))}catch(e){o(e)}},i=e=>e.done?a(e.value):Promise.resolve(e.value).then(s,n);i((r=r.apply(e,t)).next())}),posts_exports={};__export(posts_exports,{getPosts:()=>getPosts,getSearchPosts:()=>getSearchPosts});var defaultHeaders={Referer:"https://www.google.com","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",Accept:"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Accept-Language":"en-US,en;q=0.9",Pragma:"no-cache","Cache-Control":"no-cache"};function getPosts(e){return __async(this,arguments,function*({filter:e,page:t=1,signal:r,providerContext:a}){return fetchPosts({filter:e,page:t,query:"",signal:r,providerContext:a})})}function getSearchPosts(e){return __async(this,arguments,function*({searchQuery:e,page:t=1,signal:r,providerContext:a}){return fetchPosts({filter:"",page:t,query:e,signal:r,providerContext:a})})}function fetchPosts(e){return __async(this,arguments,function*({filter:e,query:t,page:r=1,signal:a,providerContext:o}){try{const s=yield o.getBaseUrl("zeefliz");let n;if(t&&t.trim()){const e=new URLSearchParams;e.append("s",t.trim()),r>1&&e.append("paged",r.toString()),n=`${s}/?${e.toString()}`}else n=e?e.startsWith("/")?`${s}${e.replace(/\/$/,"")}${r>1?`/page/${r}`:""}`:`${s}/${e}${r>1?`/page/${r}`:""}`:`${s}${r>1?`/page/${r}`:""}`;const{axios:i,cheerio:c}=o,l=yield i.get(n,{headers:defaultHeaders,signal:a}),p=c.load(l.data||""),g=__name(e=>(null==e?void 0:e.startsWith("http"))?e:new URL(e,s).href,"resolveUrl"),_=new Set,f=[];return p("section.site-main article.post").each((e,t)=>{var r;const a=p(t);let o=a.find("a[href]").first().attr("href")||"";if(!o)return;if(o=g(o),_.has(o))return;let s=a.find("h3.entry-title a").text().trim()||a.find("a[rel='bookmark']").text().trim()||(null==(r=a.find("a[title]").attr("title"))?void 0:r.trim())||"";if(s=s.replace(/^Download\s*/i,"").trim(),!s)return;let n=a.find("img").attr("bv-data-src")||a.find("img").attr("src")||a.find("img").attr("data-src")||a.find("img").attr("data-original")||"";const i=n?g(n):"";_.add(o),f.push({title:s,link:o,image:i})}),f.slice(0,100)}catch(e){return[]}})}__name(getPosts,"getPosts"),__name(getSearchPosts,"getSearchPosts"),__name(fetchPosts,"fetchPosts"),exports.getPosts=getPosts,exports.getSearchPosts=getSearchPosts; |