fix: Improve drive search handling and bump manifest

This commit is contained in:
Himanshu
2026-05-18 13:29:53 +05:30
parent 8c161715f7
commit 1b2bda58d5
3 changed files with 503 additions and 403 deletions
+1 -1
View File
@@ -1 +1 @@
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__name=(target,value)=>__defProp(target,"name",{value:value,configurable:!0}),__export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&"object"==typeof from||"function"==typeof from)for(let key of __getOwnPropNames(from))__hasOwnProp.call(to,key)||key===except||__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to},__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod),__async=(__this,__arguments,generator)=>new Promise((resolve,reject)=>{var fulfilled=value=>{try{step(generator.next(value))}catch(e){reject(e)}},rejected=value=>{try{step(generator.throw(value))}catch(e){reject(e)}},step=x=>x.done?resolve(x.value):Promise.resolve(x.value).then(fulfilled,rejected);step((generator=generator.apply(__this,__arguments)).next())}),posts_exports={};__export(posts_exports,{getPosts:()=>getPosts,getSearchPosts:()=>getSearchPosts});var getPosts=__name(function(_0){return __async(this,arguments,function*({filter:filter,page:page,signal:signal,providerContext:providerContext}){const{getBaseUrl:getBaseUrl}=providerContext;return posts({url:`${(yield getBaseUrl("drive"))+filter}page/${page}/`,signal:signal,providerContext:providerContext})})},"getPosts"),getSearchPosts=__name(function(_0){return __async(this,arguments,function*({searchQuery:searchQuery,page:page,signal:signal,providerContext:providerContext}){const{getBaseUrl:getBaseUrl}=providerContext;return posts({url:`${yield getBaseUrl("drive")}page/${page}/?s=${searchQuery}`,signal:signal,providerContext:providerContext})})},"getSearchPosts");function posts(_0){return __async(this,arguments,function*({url:url,signal:signal,providerContext:providerContext}){try{console.log("Fetching URL:",url);const{cheerio:cheerio}=providerContext,res=yield fetch(url,{signal:signal}),data=yield res.text(),$=cheerio.load(data),catalog=[];return $(".poster-card").map((i,element)=>{const title=$(element).find(".poster-title").text(),link=$(element).parent().attr("href"),image=$(element).find(".poster-image img").attr("src");title&&link&&image&&catalog.push({title:title.replace("Download","").trim(),link:link,image:image})}),catalog}catch(err){return console.error("drive error ",err),[]}})}__name(posts,"posts"),exports.getPosts=getPosts,exports.getSearchPosts=getSearchPosts;
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__name=(target,value)=>__defProp(target,"name",{value:value,configurable:!0}),__export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&"object"==typeof from||"function"==typeof from)for(let key of __getOwnPropNames(from))__hasOwnProp.call(to,key)||key===except||__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to},__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod),__async=(__this,__arguments,generator)=>new Promise((resolve,reject)=>{var fulfilled=value=>{try{step(generator.next(value))}catch(e){reject(e)}},rejected=value=>{try{step(generator.throw(value))}catch(e){reject(e)}},step=x=>x.done?resolve(x.value):Promise.resolve(x.value).then(fulfilled,rejected);step((generator=generator.apply(__this,__arguments)).next())}),posts_exports={};__export(posts_exports,{getPosts:()=>getPosts,getSearchPosts:()=>getSearchPosts});var getPosts=__name(function(_0){return __async(this,arguments,function*({filter:filter,page:page,signal:signal,providerContext:providerContext}){const{getBaseUrl:getBaseUrl}=providerContext;return posts({url:`${(yield getBaseUrl("drive"))+filter}page/${page}/`,signal:signal,providerContext:providerContext})})},"getPosts"),getSearchPosts=__name(function(_0){return __async(this,arguments,function*({searchQuery:searchQuery,page:page,signal:signal,providerContext:providerContext}){const{getBaseUrl:getBaseUrl}=providerContext,baseUrl=yield getBaseUrl("drive");return searchPosts({url:buildSearchUrl(baseUrl,searchQuery,page),baseUrl:baseUrl,signal:signal})})},"getSearchPosts");function posts(_0){return __async(this,arguments,function*({url:url,signal:signal,providerContext:providerContext}){try{console.log("Fetching URL:",url);const{cheerio:cheerio}=providerContext,res=yield fetch(url,{signal:signal}),data=yield res.text(),$=cheerio.load(data),catalog=[];return $(".poster-card").map((i,element)=>{const title=$(element).find(".poster-title").text(),link=$(element).parent().attr("href"),image=$(element).find(".poster-image img").attr("src");title&&link&&image&&catalog.push({title:title.replace("Download","").trim(),link:link,image:image})}),catalog}catch(err){return console.error("drive error ",err),[]}})}function searchPosts(_0){return __async(this,arguments,function*({url:url,baseUrl:baseUrl,signal:signal}){var _a,_b;try{console.log("Fetching drive search URL:",url);const res=yield fetch(url,{signal:signal});if(!res.ok)throw new Error(`drive search failed with status ${res.status}`);return null!=(_b=null==(_a=(yield res.json()).hits)?void 0:_a.map(hit=>{var _a2;const document=hit.document,title=null==(_a2=null==document?void 0:document.post_title)?void 0:_a2.trim(),link=(null==document?void 0:document.permalink)?normalizeUrl(baseUrl,document.permalink):"",image=(null==document?void 0:document.post_thumbnail)?normalizeUrl(baseUrl,document.post_thumbnail):"";return title&&link&&image?{title:title,link:link,image:image}:null}).filter(post=>null!==post))?_b:[]}catch(err){return console.error("drive search error ",err),[]}})}function buildSearchUrl(baseUrl,searchQuery,page){const separator=baseUrl.includes("?")?"&":"?";return`${trimTrailingSlash(baseUrl)}/search.php${separator}q=${encodeURIComponent(searchQuery)}&page=${page}`}function normalizeUrl(baseUrl,value){return value?/^https?:\/\//i.test(value)?value:value.startsWith("//")?`https:${value}`:value.startsWith("/")?`${trimTrailingSlash(baseUrl)}${value}`:`${trimTrailingSlash(baseUrl)}/${trimLeadingSlash(value)}`:""}function trimTrailingSlash(value){return value.replace(/\/+$/,"")}function trimLeadingSlash(value){return value.replace(/^\/+/,"")}__name(posts,"posts"),__name(searchPosts,"searchPosts"),__name(buildSearchUrl,"buildSearchUrl"),__name(normalizeUrl,"normalizeUrl"),__name(trimTrailingSlash,"trimTrailingSlash"),__name(trimLeadingSlash,"trimLeadingSlash"),exports.getPosts=getPosts,exports.getSearchPosts=getSearchPosts;
+1 -1
View File
@@ -18,7 +18,7 @@
{
"display_name": "MoviesDrive",
"value": "drive",
"version": "2.0",
"version": "2.1",
"icon": "",
"type": "global",
"disabled": false
+102 -2
View File
@@ -32,8 +32,12 @@ export const getSearchPosts = async function ({
}): Promise<Post[]> {
const { getBaseUrl } = providerContext;
const baseUrl = await getBaseUrl("drive");
const url = `${baseUrl}page/${page}/?s=${searchQuery}`;
return posts({ url, signal, providerContext });
const url = buildSearchUrl(baseUrl, searchQuery, page);
return searchPosts({
url,
baseUrl,
signal,
});
};
async function posts({
@@ -70,3 +74,99 @@ async function posts({
return [];
}
}
async function searchPosts({
url,
baseUrl,
signal,
}: {
url: string;
baseUrl: string;
signal: AbortSignal;
}): Promise<Post[]> {
try {
console.log("Fetching drive search URL:", url);
const res = await fetch(url, { signal });
if (!res.ok) {
throw new Error(`drive search failed with status ${res.status}`);
}
const data = (await res.json()) as {
hits?: Array<{
document?: {
permalink?: string;
post_thumbnail?: string;
post_title?: string;
};
}>;
};
return (
data.hits
?.map((hit) => {
const document = hit.document;
const title = document?.post_title?.trim();
const link = document?.permalink
? normalizeUrl(baseUrl, document.permalink)
: "";
const image = document?.post_thumbnail
? normalizeUrl(baseUrl, document.post_thumbnail)
: "";
if (!title || !link || !image) {
return null;
}
return {
title,
link,
image,
};
})
.filter((post): post is Post => post !== null) ?? []
);
} catch (err) {
console.error("drive search error ", err);
return [];
}
}
function buildSearchUrl(
baseUrl: string,
searchQuery: string,
page: number,
): string {
const separator = baseUrl.includes("?") ? "&" : "?";
return `${trimTrailingSlash(baseUrl)}/search.php${separator}q=${encodeURIComponent(
searchQuery,
)}&page=${page}`;
}
function normalizeUrl(baseUrl: string, value: string): string {
if (!value) {
return "";
}
if (/^https?:\/\//i.test(value)) {
return value;
}
if (value.startsWith("//")) {
return `https:${value}`;
}
if (value.startsWith("/")) {
return `${trimTrailingSlash(baseUrl)}${value}`;
}
return `${trimTrailingSlash(baseUrl)}/${trimLeadingSlash(value)}`;
}
function trimTrailingSlash(value: string): string {
return value.replace(/\/+$/, "");
}
function trimLeadingSlash(value: string): string {
return value.replace(/^\/+/, "");
}