feat: fetchtype 'false'
This commit is contained in:
@@ -6,7 +6,7 @@ import "@/style.css";
|
||||
import App from "./components/App";
|
||||
|
||||
if (!import.meta.env.PROD) {
|
||||
document.querySelectorAll("img").forEach((item) => (item.style.visibility = "hidden"));
|
||||
// document.querySelectorAll("img").forEach((item) => (item.style.visibility = "hidden"));
|
||||
}
|
||||
|
||||
function main() {
|
||||
|
||||
@@ -55,8 +55,11 @@ export interface SiteItem_parser extends SiteItemBase {
|
||||
// postParams: Record<string, any>;
|
||||
// domQuery: DomQuery_parser;
|
||||
// }
|
||||
export interface SiteItem_false extends SiteItemBase {
|
||||
fetchType: "false";
|
||||
}
|
||||
|
||||
export type SiteItem = SiteItem_get | SiteItem_parser;
|
||||
export type SiteItem = SiteItem_get | SiteItem_parser | SiteItem_false;
|
||||
|
||||
/** 在线网站列表 */
|
||||
export const siteList: SiteItem[] = [
|
||||
@@ -308,11 +311,11 @@ export const siteList: SiteItem[] = [
|
||||
name: "JAVLib",
|
||||
hostname: "javlibrary.com",
|
||||
url: "https://www.javlibrary.com/cn/vl_searchbyid.php?keyword={{code}}",
|
||||
fetchType: "parser",
|
||||
domQuery: {
|
||||
linkQuery: ".videothumblist .video[id]:first-child>a",
|
||||
titleQuery: ".videothumblist .video[id]:first-child>a>div.id",
|
||||
},
|
||||
fetchType: "false",
|
||||
// domQuery: {
|
||||
// linkQuery: ".videothumblist .video[id]:first-child>a",
|
||||
// titleQuery: ".videothumblist .video[id]:first-child>a>div.id",
|
||||
// },
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { gmGet, isCaseInsensitiveEqual, isErrorCode, tagsQuery } from "./";
|
||||
import type { DomQuery_get, SiteItem, SiteItem_parser } from "./siteList";
|
||||
import type { DomQuery_get, SiteItem, SiteItem_get, SiteItem_parser } from "./siteList";
|
||||
|
||||
export type FetchResult = {
|
||||
isSuccess: boolean;
|
||||
@@ -87,14 +87,21 @@ type Args = {
|
||||
targetLink: string;
|
||||
CODE: string;
|
||||
};
|
||||
export const baseFetcher = async ({ siteItem, targetLink, CODE }: Args): Promise<FetchResult> => {
|
||||
|
||||
const baseFetcher = async ({ siteItem, targetLink, CODE }: Args): Promise<FetchResult> => {
|
||||
if (siteItem.fetchType === "false") {
|
||||
return Promise.resolve({
|
||||
isSuccess: true,
|
||||
resultLink: targetLink,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await gmGet({ url: targetLink });
|
||||
if (isErrorCode(response.status)) {
|
||||
// 请求 404,大概是对应网站没有资源
|
||||
throw Error(String(response.status));
|
||||
}
|
||||
|
||||
if (siteItem.fetchType === "get") {
|
||||
// 直接 get 网页,成功,需要进一步解析 videoPage,获取字幕等信息
|
||||
return {
|
||||
@@ -114,7 +121,7 @@ export const baseFetcher = async ({ siteItem, targetLink, CODE }: Args): Promise
|
||||
};
|
||||
|
||||
/** jable 有些域名是带 -c */
|
||||
export const javbleFetcher = async (args: Args): Promise<FetchResult> => {
|
||||
const javbleFetcher = async (args: Args): Promise<FetchResult> => {
|
||||
const res = await baseFetcher(args);
|
||||
if (res.isSuccess) return res;
|
||||
const newLink = args.targetLink.slice(0, -1) + "-c/";
|
||||
|
||||
Reference in New Issue
Block a user