update
This commit is contained in:
parent
ccb1717b3d
commit
00f5b112cc
9 changed files with 194 additions and 34 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
@ -9,9 +9,9 @@
|
||||||
"SCRIPT_SRC": "",
|
"SCRIPT_SRC": "",
|
||||||
"DOMAIN": "example.org",
|
"DOMAIN": "example.org",
|
||||||
|
|
||||||
"DEFAULT_VIDEO_PROXY": "https://v.minpluto.org",
|
"DEFAULT_VIDEO_PROXY": "https://yt.sudovanilla.org",
|
||||||
"DEFAULT_DATA_PROXY": "https://v.minpluto.org",
|
"DEFAULT_DATA_PROXY": "https://yt.sudovanilla.org",
|
||||||
"DEFAULT_IMAGE_PROXY": "https://i.minpluto.org",
|
"DEFAULT_IMAGE_PROXY": "http://192.168.1.118:6014",
|
||||||
"DEFAULT_PLAYER": "Zorn",
|
"DEFAULT_PLAYER": "Zorn",
|
||||||
|
|
||||||
"SIDEBAR_CATEGORIES": true,
|
"SIDEBAR_CATEGORIES": true,
|
||||||
|
|
157
image-proxy.js
Normal file
157
image-proxy.js
Normal file
|
@ -0,0 +1,157 @@
|
||||||
|
const express = require("express");
|
||||||
|
const fetch = require("node-fetch");
|
||||||
|
const { URL } = require("url");
|
||||||
|
const { Readable } = require("node:stream");
|
||||||
|
|
||||||
|
// Array of hostnames that will be proxied
|
||||||
|
const URL_WHITELIST = [
|
||||||
|
"i.ytimg.com",
|
||||||
|
"cdn.jsdelivr.net",
|
||||||
|
"yt3.ggpht.com",
|
||||||
|
"twemoji.maxcdn.com",
|
||||||
|
"unpkg.com",
|
||||||
|
"lite.duckduckgo.com",
|
||||||
|
"youtube.com",
|
||||||
|
"returnyoutubedislikeapi.com",
|
||||||
|
"yt.sudovanilla.org",
|
||||||
|
"yt.sudovanilla.org:9200"
|
||||||
|
];
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
app.use(express.json()); // for parsing application/json
|
||||||
|
app.use(express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
|
||||||
|
|
||||||
|
app.use(function (req, res, next) {
|
||||||
|
console.log(`=> ${req.method} ${req.originalUrl.slice(1)}`);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
app.use(function (_req, res, next) {
|
||||||
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
|
res.setHeader("Cache-Control", "public, max-age=864000"); // cache header
|
||||||
|
res.setHeader("poketube-cacher", "PROXY_FILES");
|
||||||
|
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {express.Request} req
|
||||||
|
* @param {express.Response} res
|
||||||
|
*/
|
||||||
|
const proxy = async (req, res) => {
|
||||||
|
const { fetch } = await import("undici")
|
||||||
|
res.setHeader("Cache-Control", "public, max-age=864000"); // cache header
|
||||||
|
|
||||||
|
try {
|
||||||
|
let url;
|
||||||
|
|
||||||
|
try {
|
||||||
|
url = new URL("https://" + req.originalUrl.slice(8));
|
||||||
|
} catch (e) {
|
||||||
|
console.log("==> Cannot parse URL: " + e);
|
||||||
|
return res.status(400).send("Malformed URL");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sanity check, to avoid being used as an open proxy
|
||||||
|
if (!URL_WHITELIST.includes(url.host)) {
|
||||||
|
console.log(`==> Refusing to proxy host ${url.host}`);
|
||||||
|
res.status(401).send(`Hostname '${url.host}' is not permitted`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`==> Proxying request`);
|
||||||
|
|
||||||
|
let f = await fetch(url + `?cachefixer=${btoa(Date.now())}`, {
|
||||||
|
method: req.method,
|
||||||
|
});
|
||||||
|
|
||||||
|
Readable.fromWeb(f.body).pipe(res);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(`==> Error: ${e}`);
|
||||||
|
res.status(500).send("Internal server error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const listener = (req, res) => {
|
||||||
|
proxy(req, res);
|
||||||
|
};
|
||||||
|
|
||||||
|
app.get("/", (req, res) => {
|
||||||
|
var json = {
|
||||||
|
status: "200",
|
||||||
|
version: "1.3.0",
|
||||||
|
URL_WHITELIST,
|
||||||
|
cache: "max-age-864000",
|
||||||
|
};
|
||||||
|
|
||||||
|
res.json(json);
|
||||||
|
});
|
||||||
|
|
||||||
|
const apiUrls = [
|
||||||
|
"https://returnyoutubedislikeapi.com/votes?videoId=",
|
||||||
|
"https://prod-poketube.testing.poketube.fun/api?v=",
|
||||||
|
"https://ipv6-t.poketube.fun/api?v="
|
||||||
|
];
|
||||||
|
|
||||||
|
// Define a cache object
|
||||||
|
const cache = {};
|
||||||
|
|
||||||
|
app.get("/api", async (req, res) => {
|
||||||
|
const { fetch } = await import("undici")
|
||||||
|
|
||||||
|
try {
|
||||||
|
const cacheKey = req.query.v;
|
||||||
|
|
||||||
|
// Check if the result is already cached
|
||||||
|
if (cache[cacheKey] && Date.now() - cache[cacheKey].timestamp < 3600000) {
|
||||||
|
// If the cached result is less than 1 hour old, return it
|
||||||
|
const cachedData = cache[cacheKey].data;
|
||||||
|
const cachedDate = new Date(cache[cacheKey].timestamp);
|
||||||
|
return res.json(cachedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize an array to store errors when trying different URLs
|
||||||
|
const errors = [];
|
||||||
|
|
||||||
|
for (const apiUrl of apiUrls) {
|
||||||
|
try {
|
||||||
|
// Fetch data from the current URL
|
||||||
|
const engagement = await fetch(apiUrl + req.query.v).then((res) => res.json());
|
||||||
|
|
||||||
|
// Cache the result for future requests
|
||||||
|
cache[cacheKey] = {
|
||||||
|
data: engagement,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
};
|
||||||
|
|
||||||
|
res.json(engagement);
|
||||||
|
return; // Exit the loop if successful
|
||||||
|
} catch (err) {
|
||||||
|
// Log the error for this URL and continue to the next URL
|
||||||
|
console.log(`Error fetching data from ${apiUrl}: ${err.message}`);
|
||||||
|
errors.push(err.message);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If all URLs fail, return an error response
|
||||||
|
res.status(500).json({ error: "All API endpoints failed", errors });
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get("/bangs", async (req, res) => {
|
||||||
|
|
||||||
|
let f = await fetch("https://lite.duckduckgo.com/lite/?q=" + req.query.q, {
|
||||||
|
method: req.method,
|
||||||
|
});
|
||||||
|
|
||||||
|
res.redirect(f);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
app.all("/*", listener);
|
||||||
|
|
||||||
|
app.listen(6014, () => console.log("Listening on 0.0.0.0:6014"));
|
14
package.json
14
package.json
|
@ -12,7 +12,7 @@
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
"type": "SudoVanilla",
|
"type": "SudoVanilla",
|
||||||
"url": "https://sudovanilla.com/donate/"
|
"url": "https://sudovanilla.org/donate/"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
@ -27,12 +27,14 @@
|
||||||
"translate": "astro-i18next generate"
|
"translate": "astro-i18next generate"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@astrojs/node": "^8.2.1",
|
"@astrojs/node": "^8.3.2",
|
||||||
"@astrojs/vue": "^4.0.8",
|
"@astrojs/vue": "^4.5.0",
|
||||||
"@iconoir/vue": "^7.4.0",
|
"@iconoir/vue": "^7.7.0",
|
||||||
"astro": "^4.4.5",
|
"astro": "^4.11.5",
|
||||||
"astro-i18next": "^1.0.0-beta.21",
|
"astro-i18next": "^1.0.0-beta.21",
|
||||||
"rss-to-json": "^2.1.1"
|
"express": "^4.19.2",
|
||||||
|
"rss-to-json": "^2.1.1",
|
||||||
|
"undici": "^6.19.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sudovanilla/zorn": "^2024.2.26-1",
|
"@sudovanilla/zorn": "^2024.2.26-1",
|
||||||
|
|
|
@ -51,7 +51,7 @@ let ViewsFormat = ViewsConversion.format(Views);
|
||||||
<p style="font-weight: bold; font-size: 24px;">{video.title}</p>
|
<p style="font-weight: bold; font-size: 24px;">{video.title}</p>
|
||||||
<div class="rea-details-start">
|
<div class="rea-details-start">
|
||||||
<a style="text-decoration: none;" href={video.authorUrl} class="rea-channel">
|
<a style="text-decoration: none;" href={video.authorUrl} class="rea-channel">
|
||||||
<img src={video.authorThumbnails[1].url} />
|
<img src={DEFAULT_IMAGE_PROXY + "/" + video.authorThumbnails[1].url} />
|
||||||
<div
|
<div
|
||||||
style="display: flex; flex-direction: column; align-items: left;"
|
style="display: flex; flex-direction: column; align-items: left;"
|
||||||
>
|
>
|
||||||
|
@ -196,12 +196,12 @@ function ShareDialogHide() {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-gap: 12px;
|
grid-gap: 12px;
|
||||||
a {
|
a {
|
||||||
background: rgb(51 51 51);
|
background: rgb(51 51 51);
|
||||||
border: 2px rgba(255,255,255,0.05) solid;
|
border: 2px rgba(255,255,255,0.05) solid;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
padding: 9px 16px;
|
padding: 9px 16px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -48,7 +48,7 @@ const GamingSplit = GamingData.slice(0, 1)
|
||||||
</div>
|
</div>
|
||||||
<div class="category-select-grid">
|
<div class="category-select-grid">
|
||||||
{TrendingSplit.map((data) =>
|
{TrendingSplit.map((data) =>
|
||||||
<a href={'/' + i18next.language + '/category/trending'} style={'background: url("' + DEFAULT_IMAGE_PROXY + '/https://i.ytimg.com/' + data.videoThumbnails[1].url + '")'} class="goin-card">
|
<a href={'/' + i18next.language + '/category/trending'} style={'background: url("' + DEFAULT_IMAGE_PROXY + '/' + DEFAULT_DATA_PROXY + '/vi/' + data.videoId + '/mqdefault.jpg")'} class="goin-card">
|
||||||
<div class="goin-card-content">
|
<div class="goin-card-content">
|
||||||
<GraphUp viewBox="0 0 10 24"/>
|
<GraphUp viewBox="0 0 10 24"/>
|
||||||
<p>{t("SIDEBAR.CATEGORY_LIST.TRENDING")}</p>
|
<p>{t("SIDEBAR.CATEGORY_LIST.TRENDING")}</p>
|
||||||
|
@ -56,7 +56,7 @@ const GamingSplit = GamingData.slice(0, 1)
|
||||||
</a>
|
</a>
|
||||||
)}
|
)}
|
||||||
{MoviesSplit.map((data) =>
|
{MoviesSplit.map((data) =>
|
||||||
<a href={'/' + i18next.language + '/category/movies'} style={'background: url("' + DEFAULT_IMAGE_PROXY + '/https://i.ytimg.com/' + data.videoThumbnails[1].url + '")'} class="goin-card">
|
<a href={'/' + i18next.language + '/category/movies'} style={'background: url("' + DEFAULT_IMAGE_PROXY + '/' + DEFAULT_DATA_PROXY + '/vi/' + data.videoId + '/mqdefault.jpg")'} class="goin-card">
|
||||||
<div class="goin-card-content">
|
<div class="goin-card-content">
|
||||||
<Movie viewBox="0 0 10 24"/>
|
<Movie viewBox="0 0 10 24"/>
|
||||||
<p>{t("SIDEBAR.CATEGORY_LIST.MOVIES")}</p>
|
<p>{t("SIDEBAR.CATEGORY_LIST.MOVIES")}</p>
|
||||||
|
@ -64,7 +64,7 @@ const GamingSplit = GamingData.slice(0, 1)
|
||||||
</a>
|
</a>
|
||||||
)}
|
)}
|
||||||
{MusicSplit.map((data) =>
|
{MusicSplit.map((data) =>
|
||||||
<a href={'/' + i18next.language + '/category/music'} style={'background: url("' + DEFAULT_IMAGE_PROXY + '/https://i.ytimg.com/' + data.videoThumbnails[1].url + '")'} class="goin-card">
|
<a href={'/' + i18next.language + '/category/music'} style={'background: url("' + DEFAULT_IMAGE_PROXY + '/' + DEFAULT_DATA_PROXY + '/vi/' + data.videoId + '/mqdefault.jpg")'} class="goin-card">
|
||||||
<div class="goin-card-content">
|
<div class="goin-card-content">
|
||||||
<MusicDoubleNote viewBox="0 0 10 24"/>
|
<MusicDoubleNote viewBox="0 0 10 24"/>
|
||||||
<p>{t("SIDEBAR.CATEGORY_LIST.MUSIC")}</p>
|
<p>{t("SIDEBAR.CATEGORY_LIST.MUSIC")}</p>
|
||||||
|
@ -72,7 +72,7 @@ const GamingSplit = GamingData.slice(0, 1)
|
||||||
</a>
|
</a>
|
||||||
)}
|
)}
|
||||||
{GamingSplit.map((data) =>
|
{GamingSplit.map((data) =>
|
||||||
<a href={'/' + i18next.language + '/category/gaming'} style={'background: url("' + DEFAULT_IMAGE_PROXY + '/https://i.ytimg.com/' + data.videoThumbnails[1].url + '")'} class="goin-card">
|
<a href={'/' + i18next.language + '/category/gaming'} style={'background: url("' + DEFAULT_IMAGE_PROXY + '/' + DEFAULT_DATA_PROXY + '/vi/' + data.videoId + '/mqdefault.jpg")'} class="goin-card">
|
||||||
<div class="goin-card-content">
|
<div class="goin-card-content">
|
||||||
<Gamepad viewBox="0 0 10 24"/>
|
<Gamepad viewBox="0 0 10 24"/>
|
||||||
<p>{t("SIDEBAR.CATEGORY_LIST.GAMES")}</p>
|
<p>{t("SIDEBAR.CATEGORY_LIST.GAMES")}</p>
|
||||||
|
|
|
@ -51,7 +51,7 @@ let ViewsFormat = ViewsConversion.format(Views);
|
||||||
<p style="font-weight: bold; font-size: 24px;">{video.title}</p>
|
<p style="font-weight: bold; font-size: 24px;">{video.title}</p>
|
||||||
<div class="rea-details-start">
|
<div class="rea-details-start">
|
||||||
<a style="text-decoration: none;" href={video.authorUrl} class="rea-channel">
|
<a style="text-decoration: none;" href={video.authorUrl} class="rea-channel">
|
||||||
<img src={video.authorThumbnails[1].url} />
|
<img src={DEFAULT_IMAGE_PROXY + "/" + video.authorThumbnails[1].url} />
|
||||||
<div
|
<div
|
||||||
style="display: flex; flex-direction: column; align-items: left;"
|
style="display: flex; flex-direction: column; align-items: left;"
|
||||||
>
|
>
|
||||||
|
@ -196,12 +196,12 @@ function ShareDialogHide() {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-gap: 12px;
|
grid-gap: 12px;
|
||||||
a {
|
a {
|
||||||
background: rgb(51 51 51);
|
background: rgb(51 51 51);
|
||||||
border: 2px rgba(255,255,255,0.05) solid;
|
border: 2px rgba(255,255,255,0.05) solid;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
padding: 9px 16px;
|
padding: 9px 16px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -51,7 +51,7 @@ let ViewsFormat = ViewsConversion.format(Views);
|
||||||
<p style="font-weight: bold; font-size: 24px;">{video.title}</p>
|
<p style="font-weight: bold; font-size: 24px;">{video.title}</p>
|
||||||
<div class="rea-details-start">
|
<div class="rea-details-start">
|
||||||
<a style="text-decoration: none;" href={video.authorUrl} class="rea-channel">
|
<a style="text-decoration: none;" href={video.authorUrl} class="rea-channel">
|
||||||
<img src={video.authorThumbnails[1].url} />
|
<img src={DEFAULT_IMAGE_PROXY + "/" + video.authorThumbnails[1].url} />
|
||||||
<div
|
<div
|
||||||
style="display: flex; flex-direction: column; align-items: left;"
|
style="display: flex; flex-direction: column; align-items: left;"
|
||||||
>
|
>
|
||||||
|
@ -196,12 +196,12 @@ function ShareDialogHide() {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-gap: 12px;
|
grid-gap: 12px;
|
||||||
a {
|
a {
|
||||||
background: rgb(51 51 51);
|
background: rgb(51 51 51);
|
||||||
border: 2px rgba(255,255,255,0.05) solid;
|
border: 2px rgba(255,255,255,0.05) solid;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
padding: 9px 16px;
|
padding: 9px 16px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
---
|
---
|
||||||
import { t, changeLanguage } from "i18next"
|
import { t, changeLanguage } from "i18next"
|
||||||
import Base from "@layouts/Default.astro"
|
import Base from "@layouts/Default.astro"
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
import { DEFAULT_DATA_PROXY, DEFAULT_IMAGE_PROXY } from "../../config.json"
|
import { DEFAULT_DATA_PROXY, DEFAULT_IMAGE_PROXY } from "../../config.json"
|
||||||
|
|
||||||
|
|
Reference in a new issue