From ddf88ed2fc74c2688e2bd402391ee99321caa7a4 Mon Sep 17 00:00:00 2001 From: Jon Dough <49297268+stjet@users.noreply.github.com> Date: Fri, 29 Mar 2024 06:38:52 +0000 Subject: [PATCH] anime quality, https --- .gitattributes | 1 + .gitignore | 4 ++- .torrc | 2 +- README.md | 2 ++ build.ts | 67 +++++++++++++++++++++----------------------- host.ts | 14 +++++++-- package.json | 1 + templates/anime.html | 21 +++++++++++++- 8 files changed, 72 insertions(+), 40 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..07764a7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf \ No newline at end of file diff --git a/.gitignore b/.gitignore index 59a0ed4..8e207b3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ static_assets favourites_info.json *.js package-lock.json -build \ No newline at end of file +build +*.key +*.cert \ No newline at end of file diff --git a/.torrc b/.torrc index 95c0348..1709a17 100644 --- a/.torrc +++ b/.torrc @@ -1,4 +1,4 @@ HiddenServiceDir ./tor/hidden_service HiddenServicePort 80 0.0.0.0:8043 - + ContactInfo Billy Bob \ No newline at end of file diff --git a/README.md b/README.md index 7132732..8ee2218 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Most of the code is a modification of [hedgeblog](https://github.com/jetstream0/ Since TOR is pretty slow to download large files (eg, videos), the videos are streamed so load time isn't as bad as one might expect (HTTP protocol is amazing, browsers are amazing). +Optionally, this site can be run locally or on the regular web with HTTP(S). + # Running After first cloning or downloading the repository: diff --git a/build.ts b/build.ts index aece329..3ff67eb 100644 --- a/build.ts +++ b/build.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import { readdirSync } from 'fs'; +import { readdirSync, existsSync } from 'fs'; import { Renderer } from './ryuji.js'; import { Builder } from './saki.js'; import _favourites_info from './favourites_info.json'; @@ -23,21 +23,21 @@ interface DirectoryVars { chapters: string[]; //name of all the chapters } -interface AnimeVars { +interface ListingVars { listing: Listing; chapter: string; next_chapter?: string | boolean; prev_chapter?: string | boolean; } -type MusicVars = AnimeVars; +type MusicVars = ListingVars; -interface MangaVars { - listing: Listing; - chapter: string; +interface AnimeVars extends ListingVars { + higher_quality_available: boolean; +}; + +interface MangaVars extends ListingVars { images: string[]; //file names of all the images in the chapter - next_chapter?: string | boolean; - prev_chapter?: string | boolean; } const favourites_info: Record = _favourites_info; @@ -92,48 +92,45 @@ let manga_pages_count: number = 0; for (let i = 0; i < listings.length; i++) { const listing: Listing = listings[i]; directory_serve_paths.push(`/${listing.type}/${listing.name}`); - const chapters: string[] = readdirSync(path.join(__dirname, `/static_assets/${listing.type}_assets/${listing.name}`), { withFileTypes: true }).map((d) => d.name.replace(".mp4", "").replace(".mp3", "")); + const chapters: string[] = readdirSync(path.join(__dirname, `/static_assets/${listing.type}_assets/${listing.name}`), { withFileTypes: true }).map((d) => d.name.replace(".mp4", "").replace(".mp3", "")).filter( + (chapter: string) => + !(listing.type === "anime" && chapter.endsWith("_higher_quality")) + ); //filter out the higher quality anime videos, we want those to be on the same page as the low quality (select quality with dropdown), not listed as a separate episode directory_vars.push({ listing, chapters, }); - if (listing.type === "anime") { - for (let j = 0; j < chapters.length; j++) { - const chapter: string = chapters[j]; - anime_serve_paths.push(`/${listing.type}/${listing.name}/${chapter}`); + for (let j = 0; j < chapters.length; j++) { + const chapter: string = chapters[j]; + const base = { + listing, + chapter, + next_chapter: chapters[j + 1] ? chapters[j + 1] : false, + prev_chapter: j > 0 ? chapters[j - 1] : false, + }; + const serve_path = `/${listing.type}/${listing.name}/${chapter}`; + if (listing.type === "anime") { + anime_serve_paths.push(serve_path); anime_vars.push({ - listing, - chapter, - next_chapter: chapters[j + 1] ? chapters[j + 1] : false, - prev_chapter: j > 0 ? chapters[j - 1] : false, + ...base, + higher_quality_available: existsSync(path.join(__dirname, `/static_assets/${listing.type}_assets/${listing.name}`, `${chapter}_higher_quality.mp4`)), }); - } - } else if (listing.type === "manga") { - for (let j = 0; j < chapters.length; j++) { - const chapter: string = chapters[j]; - manga_serve_paths.push(`/${listing.type}/${listing.name}/${chapter}`); + } else if (listing.type === "manga") { + manga_serve_paths.push(serve_path); const images: string[] = readdirSync(path.join(__dirname, `/static_assets/${listing.type}_assets/${listing.name}/${chapter}`), { withFileTypes: true }).map((d) => d.name); manga_pages_count += images.length; manga_vars.push({ - listing, - chapter, + ...base, images, - next_chapter: chapters[j + 1] ? chapters[j + 1] : false, - prev_chapter: j > 0 ? chapters[j - 1] : false, }); - } - } else if (listing.type === "music") { - for (let j = 0; j < chapters.length; j++) { - const chapter: string = chapters[j]; + } else if (listing.type === "music") { + music_serve_paths.push(serve_path); songs.push(`${listing.name}/${chapter}`); - music_serve_paths.push(`/${listing.type}/${listing.name}/${chapter}`); music_vars.push({ - listing, - chapter, - next_chapter: chapters[j + 1] ? chapters[j + 1] : false, - prev_chapter: j > 0 ? chapters[j - 1] : false, + ...base, }); } + // } } diff --git a/host.ts b/host.ts index 13b8963..3db5d0d 100644 --- a/host.ts +++ b/host.ts @@ -1,4 +1,5 @@ import { createServer } from 'http'; +import { createServer as createServerHttps } from 'https'; import * as path from 'path'; import { existsSync, readFileSync, statSync, createReadStream } from 'fs'; import { createHash } from 'crypto'; @@ -16,7 +17,7 @@ function get_password(date: Date = new Date()): string { const port: number = 8043; const stream_chunk_size: number = 2 * 1024 * 1024; //2 MiB -createServer((req, res) => { +const request_handler = (req, res) => { const todays_password: string = get_password(); let req_path: string; if (req.url.includes("..")) { @@ -162,6 +163,15 @@ createServer((req, res) => { } //end response return res.end(); -}).listen(port); +}; +if (process.argv[2] === "--https") { + createServerHttps({ + key: readFileSync("server.key"), + cert: readFileSync("server.cert"), + }, request_handler).listen(port + 1); + console.log(`Hosting HTTPS on port ${port + 1}`); +} + +createServer(request_handler).listen(port); console.log(`Hosting on port ${port}`); diff --git a/package.json b/package.json index 9abab92..7f33080 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "compile": "tsc -p .", "build": "node build.js", "host": "node host.js", + "host-https": "node host.js --https", "start": "npm run compile && npm run build && npm run host" }, "repository": { diff --git a/templates/anime.html b/templates/anime.html index fcc96af..743671d 100644 --- a/templates/anime.html +++ b/templates/anime.html @@ -24,7 +24,26 @@

[[ listing.name ]] [[ chapter ]]

- + +
+ [[ if:higher_quality_available ]] + + + + [[ endif ]] [[ component:nav ]]