aboutsummaryrefslogtreecommitdiff
path: root/intimate/src/fetcher.js
diff options
context:
space:
mode:
authorStarscouts <starscouts@equestria.dev>2024-07-11 00:25:16 +0200
committerStarscouts <starscouts@equestria.dev>2024-07-11 00:25:16 +0200
commit1bbe60d3a237cfe99dc6d1a3aa14de542668dc6f (patch)
tree789f37ff1586904371bf02ff5ba3d7508a4d9eef /intimate/src/fetcher.js
parent6e63a80898695d07549a3ca28bff7eafaf8009ac (diff)
downloadfaunerie-3.2.0.tar.gz
faunerie-3.2.0.tar.bz2
faunerie-3.2.0.zip
Update intimate3.2.0
Diffstat (limited to 'intimate/src/fetcher.js')
-rwxr-xr-xintimate/src/fetcher.js64
1 files changed, 28 insertions, 36 deletions
diff --git a/intimate/src/fetcher.js b/intimate/src/fetcher.js
index bf80203..4375fe5 100755
--- a/intimate/src/fetcher.js
+++ b/intimate/src/fetcher.js
@@ -63,43 +63,24 @@ async function slideshowMain() {
initiateLoad();
let pageDerpibooru = 1;
- let pageE621 = 1;
let pageLocal = 1;
let seed = Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("hex");
console.log(config);
- async function loadNextPageE621() {
- if (!config.modules.e621 || !config._show.e621) return;
- console.log("Slideshow: Loading page " + pageE621 + " from e621");
-
- let res = await fetch("https://e621.net/posts.json?limit=" + Math.round(50 * config.modules.e621.proportion) + "&tags=order:random%20fav:" + encodeURIComponent(config.modules.e621.source) + "%20rating:" + (testMode ? "q" : "e") + "%20randseed:" + seed + "&page=" + pageE621);
- let json = await res.json();
-
- if (json["posts"].length === 0 && pageE621 !== 1) {
- console.log("Slideshow: Reached the end of e621, wrapping around");
- pageE621 = 1;
- await loadNextPageE621();
- return;
- }
-
- json["posts"] = json["posts"].map(i => {
- i["view_url"] = i["file"]["url"];
- i["mime_type"] = extToMime(i["file"]["ext"]);
- i["_source"] = "https://e621.net/posts/" + i["id"];
- return i;
- });
-
- window.displayQueue.push(...json["posts"]);
- window.displayQueue = window.displayQueue.sort(() => Math.random() - Math.random());
- pageE621++;
- }
-
async function loadNextPageDerpibooru() {
- if (!config.modules.derpibooru || !config._show.derpibooru) return;
+ if (!config.modules.derpibooru || !(config._sessionPreferences.sources === 0 || config._sessionPreferences.sources === 2)) return;
console.log("Slideshow: Loading page " + pageDerpibooru + " from Derpibooru");
- let res = await fetch("https://derpibooru.org/api/v1/json/search/images/?q=" + (testMode ? "suggestive" : "explicit") + ",%20faved_by:" + encodeURIComponent(config.modules.derpibooru.source) + "&per_page=" + Math.round(50 * config.modules.derpibooru.proportion) + "&filter_id=56027&sf=random:" + seed + "&page=" + pageDerpibooru);
+ let res = await fetch("https://derpibooru.org/api/v1/json/search/images/?q=" + (testMode ? "suggestive" : "explicit") + (
+ config._sessionPreferences.content === 0 ?
+ ",%20mime_type:image/*"
+ : (config._sessionPreferences.content === 1 ?
+ ",%20mime_type:video/*"
+ :
+ ""
+ )
+ ) + ",%20faved_by:" + encodeURIComponent(config.modules.derpibooru.source) + "&per_page=" + Math.round(50 * config.modules.derpibooru.proportion) + "&filter_id=56027&sf=random:" + seed + "&page=" + pageDerpibooru);
let json = await res.json();
if (json["images"].length === 0 && pageDerpibooru !== 1) {
@@ -114,19 +95,24 @@ async function slideshowMain() {
return i;
});
- window.displayQueue.push(...json["images"]);
+ window.displayQueue.push(...json["images"].map(i => {
+ if (!config.modules.derpibooru['faunerie_cache']) return i;
+ if (!fs.existsSync(config.modules.derpibooru['faunerie_cache'] + "/images/" + i['sha512_hash'].substring(0, 1) + "/" + i['sha512_hash'].substring(0, 2) + "/" + i['sha512_hash'].substring(0, 3) + "/10" + i['id'] + ".bin")) return i;
+ i['view_url'] = "pbip://" + config.modules.derpibooru['faunerie_cache'] + "/images/" + i['sha512_hash'].substring(0, 1) + "/" + i['sha512_hash'].substring(0, 2) + "/" + i['sha512_hash'].substring(0, 3) + "/10" + i['id'] + ".bin";
+ return i;
+ }));
window.displayQueue = window.displayQueue.sort(() => Math.random() - Math.random());
pageDerpibooru++;
}
let fullList;
- if (config.modules.local && config._show.local) {
- fullList = (await getFiles(config.modules.local.source)).filter(i => extToMime(path.extname(i)));
+ if (config.modules.local && (config._sessionPreferences.sources === 1 || config._sessionPreferences.sources === 2)) {
+ fullList = (await getFiles(config.modules.local.source)).filter(i => !path.basename(i).startsWith(".") && extToMime(path.extname(i)));
}
async function loadNextPageLocal() {
- if (!config.modules.local || !config._show.local) return;
+ if (!config.modules.derpibooru || !(config._sessionPreferences.sources === 1 || config._sessionPreferences.sources === 2)) return;
console.log("Slideshow: Loading page " + pageLocal + " from local filesystem");
let res = fullList.slice((pageLocal - 1) * Math.round(50 * config.modules.derpibooru.proportion), pageLocal * Math.round(50 * config.modules.derpibooru.proportion));
@@ -154,19 +140,25 @@ async function slideshowMain() {
});
window.displayQueue.push(...json["images"]);
- window.displayQueue = window.displayQueue.sort(() => Math.random() - Math.random());
+ window.displayQueue = window.displayQueue.sort(() => Math.random() - Math.random()).filter(i => {
+ if (config._sessionPreferences.content === 0) {
+ return i.mime_type.startsWith("image/");
+ } else if (config._sessionPreferences.content === 1) {
+ return i.mime_type.startsWith("video/");
+ } else {
+ return true;
+ }
+ });
pageLocal++;
}
console.log("Slideshow: Loading first page");
await loadNextPageDerpibooru();
- await loadNextPageE621();
await loadNextPageLocal();
console.log("Slideshow: Starting slideshow");
await startSlideshow(false, async () => {
await loadNextPageDerpibooru();
- await loadNextPageE621();
await loadNextPageLocal();
});