fix proxy
This commit is contained in:
parent
1dd7e97f94
commit
b313b868f8
4 changed files with 11 additions and 111 deletions
|
|
@ -1,65 +0,0 @@
|
||||||
export async function onRequest(context) {
|
|
||||||
const { request } = context;
|
|
||||||
const url = new URL(request.url);
|
|
||||||
const targetUrl = url.searchParams.get('url');
|
|
||||||
|
|
||||||
if (!targetUrl) {
|
|
||||||
return new Response('Missing url parameter', { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const cacheUrl = new URL(request.url);
|
|
||||||
try {
|
|
||||||
const tidalUrl = new URL(targetUrl);
|
|
||||||
cacheUrl.searchParams.set('cache_key', tidalUrl.pathname);
|
|
||||||
} catch (e) {}
|
|
||||||
|
|
||||||
const cacheKey = new Request(cacheUrl.toString(), request);
|
|
||||||
const cache = caches.default;
|
|
||||||
let response = await cache.match(cacheKey);
|
|
||||||
|
|
||||||
if (!response) {
|
|
||||||
const headers = new Headers(request.headers);
|
|
||||||
headers.delete('host');
|
|
||||||
headers.delete('referer');
|
|
||||||
headers.set('Origin', 'https://listen.tidal.com');
|
|
||||||
headers.set(
|
|
||||||
'User-Agent',
|
|
||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
|
||||||
);
|
|
||||||
|
|
||||||
response = await fetch(targetUrl, {
|
|
||||||
method: request.method,
|
|
||||||
headers: headers,
|
|
||||||
redirect: 'follow',
|
|
||||||
cf: {
|
|
||||||
cacheTtl: 2592000,
|
|
||||||
cacheEverything: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (request.method === 'GET' && response.ok) {
|
|
||||||
const cacheResponse = new Response(response.body, response);
|
|
||||||
cacheResponse.headers.set('Access-Control-Allow-Origin', '*');
|
|
||||||
cacheResponse.headers.set('Cache-Control', 'public, max-age=2592000');
|
|
||||||
|
|
||||||
cacheResponse.headers.delete('Set-Cookie');
|
|
||||||
|
|
||||||
context.waitUntil(cache.put(cacheKey, cacheResponse.clone()));
|
|
||||||
response = cacheResponse;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
|
|
||||||
const newResponse = new Response(response.body, response);
|
|
||||||
newResponse.headers.set('Access-Control-Allow-Origin', '*');
|
|
||||||
newResponse.headers.set('Access-Control-Allow-Methods', 'GET, HEAD, OPTIONS');
|
|
||||||
newResponse.headers.set('Access-Control-Expose-Headers', '*');
|
|
||||||
newResponse.headers.delete('content-security-policy');
|
|
||||||
newResponse.headers.delete('x-frame-options');
|
|
||||||
|
|
||||||
return newResponse;
|
|
||||||
} catch (error) {
|
|
||||||
return new Response('Proxy Error: ' + error.message, { status: 500 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1732,8 +1732,11 @@
|
||||||
<div id="server-disruption-banner" class="server-disruption-sidebar" style="display: none">
|
<div id="server-disruption-banner" class="server-disruption-sidebar" style="display: none">
|
||||||
<span class="disruption-icon">⚠</span>
|
<span class="disruption-icon">⚠</span>
|
||||||
<span
|
<span
|
||||||
>Services are currently unstable. <br /><br />For Hi-Res streaming, use Chrome or
|
>Services are currently unstable. <br /><br />Use the extension
|
||||||
Safari.</span
|
<a href="https://github.com/monochrome-music/monochrome/tree/main/extension"
|
||||||
|
>here</a
|
||||||
|
>
|
||||||
|
for the best experience.</span
|
||||||
>
|
>
|
||||||
<button id="dismiss-disruption-btn" class="disruption-dismiss" title="Dismiss">
|
<button id="dismiss-disruption-btn" class="disruption-dismiss" title="Dismiss">
|
||||||
×
|
×
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
export const getProxyUrl = (url) => {
|
export const getProxyUrl = (url) => {
|
||||||
if (window.__tidalOriginExtension) return url;
|
if (window.__tidalOriginExtension) return url;
|
||||||
return `/proxy-audio?url=${encodeURIComponent(url)}`;
|
return `https://audio-proxy.binimum.org/proxy-audio?url=${encodeURIComponent(url)}`;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,58 +1,20 @@
|
||||||
|
import path from 'path';
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import { VitePWA } from 'vite-plugin-pwa';
|
import { VitePWA } from 'vite-plugin-pwa';
|
||||||
import authGatePlugin from './vite-plugin-auth-gate.js';
|
import authGatePlugin from './vite-plugin-auth-gate.js';
|
||||||
import path from 'path';
|
|
||||||
import uploadPlugin from './vite-plugin-upload.js';
|
|
||||||
import blobAssetPlugin from './vite-plugin-blob.js';
|
import blobAssetPlugin from './vite-plugin-blob.js';
|
||||||
import svgUse from './vite-plugin-svg-use.js';
|
import svgUse from './vite-plugin-svg-use.js';
|
||||||
|
import uploadPlugin from './vite-plugin-upload.js';
|
||||||
// import purgecss from 'vite-plugin-purgecss';
|
// import purgecss from 'vite-plugin-purgecss';
|
||||||
import purgecss from 'vite-plugin-purgecss';
|
|
||||||
import { execSync } from 'child_process';
|
|
||||||
import { playwright } from '@vitest/browser-playwright';
|
import { playwright } from '@vitest/browser-playwright';
|
||||||
|
import { execSync } from 'child_process';
|
||||||
|
import purgecss from 'vite-plugin-purgecss';
|
||||||
|
|
||||||
function proxyAudioPlugin() {
|
function proxyAudioPlugin() {
|
||||||
return {
|
return {
|
||||||
name: 'proxy-audio-dev',
|
name: 'proxy-audio-dev',
|
||||||
configureServer(server) {
|
configureServer(server) {
|
||||||
server.middlewares.use('/proxy-audio', async (req, res) => {
|
// No longer needed: local proxy-audio middleware replaced by remote proxy
|
||||||
const url = new URL(req.url, 'http://localhost');
|
|
||||||
const targetUrl = url.searchParams.get('url');
|
|
||||||
|
|
||||||
if (!targetUrl) {
|
|
||||||
res.writeHead(400);
|
|
||||||
res.end('Missing url parameter');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const headers = new Headers();
|
|
||||||
headers.set('Origin', 'https://listen.tidal.com');
|
|
||||||
headers.set(
|
|
||||||
'User-Agent',
|
|
||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
|
||||||
);
|
|
||||||
|
|
||||||
const upstream = await fetch(targetUrl, {
|
|
||||||
method: req.method,
|
|
||||||
headers,
|
|
||||||
redirect: 'follow',
|
|
||||||
});
|
|
||||||
|
|
||||||
const body = Buffer.from(await upstream.arrayBuffer());
|
|
||||||
|
|
||||||
res.writeHead(upstream.status, {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Methods': 'GET, HEAD, OPTIONS',
|
|
||||||
'Access-Control-Expose-Headers': '*',
|
|
||||||
'content-type': upstream.headers.get('content-type') || 'application/octet-stream',
|
|
||||||
'content-length': body.length,
|
|
||||||
});
|
|
||||||
res.end(body);
|
|
||||||
} catch (error) {
|
|
||||||
res.writeHead(500);
|
|
||||||
res.end('Proxy Error: ' + error.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue