Upload files to "/"

This commit is contained in:
2025-11-23 23:23:51 +01:00
parent 591b664375
commit c59ba1d556
5 changed files with 683 additions and 0 deletions

113
ZeroChan.js Normal file
View File

@@ -0,0 +1,113 @@
class ZeroChan {
baseUrl = "https://zerochan.net";
constructor(fetchPath, cheerioPath, browser) {
this.browser = browser;
this.type = "image-board";
}
async fetchSearchResult(query = "hello", page = 1, perPage = 48) {
const url = `${this.baseUrl}/${query.trim().replace(/\s+/g, "+")}?p=${page}`;
const data = await this.browser.scrape(
url,
() => {
const list = document.querySelectorAll("#thumbs2 li");
if (list.length === 0) {
return { results: [], hasNextPage: false };
}
const results = [];
list.forEach(li => {
const id = li.getAttribute("data-id");
if (!id) return;
const img = li.querySelector("img");
const imgUrl =
img?.getAttribute("data-src") ||
img?.getAttribute("src") ||
null;
if (!imgUrl) return;
const tagLinks = li.querySelectorAll("p a");
const tags = [...tagLinks]
.map(a => a.textContent.trim())
.filter(Boolean);
results.push({
id,
image: imgUrl,
sampleImageUrl: imgUrl,
tags,
type: "preview"
});
});
const hasNextPage = document.querySelector('nav.pagination a[rel="next"]') !== null;
return {
results,
hasNextPage
};
},
{ waitSelector: "#thumbs2 li", timeout: 15000, renderWaitTime: 3000, loadImages: true }
);
console.log(data)
return {
results: data.results,
hasNextPage: data.hasNextPage,
page
};
}
async fetchInfo(id) {
const url = `${this.baseUrl}/${id}`;
const data = await this.browser.scrape(
url,
() => {
const preview = document.querySelector("a.preview");
if (!preview) {
return {
fullImage: null,
tags: [],
createdAt: Date.now()
};
}
const fullImage = preview.getAttribute("href") || null;
const img = preview.querySelector("img");
const alt = img?.getAttribute("alt") || "";
let tags = [];
if (alt.startsWith("Tags:")) {
tags = alt
.replace("Tags:", "")
.split(",")
.map(t => t.trim())
.filter(Boolean);
}
return {
fullImage,
tags,
createdAt: Date.now()
};
},
{ waitSelector: "a.preview img", timeout: 15000 }
);
return {
id,
fullImage: data.fullImage,
tags: data.tags,
createdAt: data.createdAt,
rating: "Unknown"
};
}
}
module.exports = { ZeroChan };