web & api: rename stream to tunnel

- updated the endpoint to /tunnel
- updated status to tunnel
- fixed one incorrectly named error in web
This commit is contained in:
wukko 2024-09-05 00:26:48 +06:00
parent 49460bd16d
commit fff1c6c7a6
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2
13 changed files with 99 additions and 99 deletions

2
.github/test.sh vendored
View file

@ -23,7 +23,7 @@ test_api() {
echo "API_RESPONSE=$API_RESPONSE" echo "API_RESPONSE=$API_RESPONSE"
STATUS=$(echo "$API_RESPONSE" | jq -r .status) STATUS=$(echo "$API_RESPONSE" | jq -r .status)
STREAM_URL=$(echo "$API_RESPONSE" | jq -r .url) STREAM_URL=$(echo "$API_RESPONSE" | jq -r .url)
[ "$STATUS" = stream ] || exit 1; [ "$STATUS" = tunnel ] || exit 1;
S=$(curl -I -m 3 "$STREAM_URL") S=$(curl -I -m 3 "$STREAM_URL")
CONTENT_LENGTH=$(echo "$S" \ CONTENT_LENGTH=$(echo "$S" \

View file

@ -141,7 +141,7 @@ export const runAPI = (express, app, __dirname) => {
}); });
app.post('/', apiLimiter); app.post('/', apiLimiter);
app.use('/stream', apiLimiterStream); app.use('/tunnel', apiLimiterStream);
app.use('/', express.json({ limit: 1024 })); app.use('/', express.json({ limit: 1024 }));
app.use('/', (err, _, res, next) => { app.use('/', (err, _, res, next) => {
@ -225,7 +225,7 @@ export const runAPI = (express, app, __dirname) => {
} }
}) })
app.get('/stream', (req, res) => { app.get('/tunnel', (req, res) => {
const id = String(req.query.id); const id = String(req.query.id);
const exp = String(req.query.exp); const exp = String(req.query.exp);
const sig = String(req.query.sig); const sig = String(req.query.sig);
@ -256,7 +256,7 @@ export const runAPI = (express, app, __dirname) => {
return stream(res, streamInfo); return stream(res, streamInfo);
}) })
app.get('/istream', (req, res) => { app.get('/itunnel', (req, res) => {
if (!req.ip.endsWith('127.0.0.1')) { if (!req.ip.endsWith('127.0.0.1')) {
return res.sendStatus(403); return res.sendStatus(403);
} }

View file

@ -38,7 +38,7 @@ export async function runTest(url, params, expect) {
throw error.join('\n'); throw error.join('\n');
} }
if (result.body.status === 'stream') { if (result.body.status === 'tunnel') {
// TODO: stream testing // TODO: stream testing
} }
} }

View file

@ -6,7 +6,7 @@ import { createStream } from "../stream/manage.js";
export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disableMetadata, filenameStyle, twitterGif, requestIP, audioBitrate, alwaysProxy }) { export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disableMetadata, filenameStyle, twitterGif, requestIP, audioBitrate, alwaysProxy }) {
let action, let action,
responseType = "stream", responseType = "tunnel",
defaultParams = { defaultParams = {
u: r.urls, u: r.urls,
headers: r.headers, headers: r.headers,
@ -197,7 +197,7 @@ export default function({ r, host, audioFormat, isAudioOnly, isAudioMuted, disab
} }
if (alwaysProxy && responseType === "redirect") { if (alwaysProxy && responseType === "redirect") {
responseType = "stream"; responseType = "tunnel";
params.type = "proxy"; params.type = "proxy";
} }

View file

@ -41,7 +41,7 @@ export function createResponse(responseType, responseData) {
} }
break; break;
case "stream": case "tunnel":
response = { response = {
url: createStream(responseData), url: createStream(responseData),
} }

View file

@ -118,7 +118,7 @@ export default async function(obj) {
} }
return { return {
typeId: "stream", typeId: "tunnel",
type: "merge", type: "merge",
urls: [video, audioFileLink], urls: [video, audioFileLink],
audioFilename: `reddit_${id}_audio`, audioFilename: `reddit_${id}_audio`,

View file

@ -53,7 +53,7 @@ export function createStream(obj) {
encryptStream(streamData, iv, secret) encryptStream(streamData, iv, secret)
) )
let streamLink = new URL('/stream', env.apiURL); let streamLink = new URL('/tunnel', env.apiURL);
const params = { const params = {
'id': streamID, 'id': streamID,
@ -103,7 +103,7 @@ export function createInternalStream(url, obj = {}) {
dispatcher dispatcher
}; };
let streamLink = new URL('/istream', `http://127.0.0.1:${env.apiPort}`); let streamLink = new URL('/itunnel', `http://127.0.0.1:${env.apiPort}`);
streamLink.searchParams.set('id', streamID); streamLink.searchParams.set('id', streamID);
const cleanup = () => { const cleanup = () => {

View file

@ -62,7 +62,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -74,7 +74,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -86,7 +86,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -98,7 +98,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -168,7 +168,7 @@
"canFail": true, "canFail": true,
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -203,7 +203,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -215,7 +215,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -226,7 +226,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -238,7 +238,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -250,7 +250,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -259,7 +259,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -268,7 +268,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -277,7 +277,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
} }
], ],
@ -291,7 +291,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -303,7 +303,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -315,7 +315,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -327,7 +327,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -340,7 +340,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -353,7 +353,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -367,7 +367,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -381,7 +381,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -393,7 +393,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -404,7 +404,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -416,7 +416,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -436,7 +436,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -448,7 +448,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -457,7 +457,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -477,7 +477,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -488,7 +488,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -499,7 +499,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -508,7 +508,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -519,7 +519,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -528,7 +528,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -548,7 +548,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -586,7 +586,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -597,7 +597,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -606,7 +606,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -617,7 +617,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -626,7 +626,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -635,7 +635,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
} }
], ],
@ -673,7 +673,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -684,7 +684,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
} }
], ],
@ -759,7 +759,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -770,7 +770,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -781,7 +781,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -808,7 +808,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
} }
], ],
@ -857,7 +857,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -868,7 +868,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -953,7 +953,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -964,7 +964,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
} }
], ],
@ -986,7 +986,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -997,7 +997,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1082,7 +1082,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1093,7 +1093,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1113,7 +1113,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1124,7 +1124,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1135,7 +1135,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
} }
], ],
@ -1146,7 +1146,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1157,7 +1157,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1175,7 +1175,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1185,7 +1185,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1194,7 +1194,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1205,7 +1205,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1216,7 +1216,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1225,7 +1225,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
} }
], ],
@ -1236,7 +1236,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
} }
], ],
@ -1247,7 +1247,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1256,7 +1256,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1265,7 +1265,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
} }
], ],
@ -1316,7 +1316,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1405,7 +1405,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1414,7 +1414,7 @@
"params": {}, "params": {},
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1425,7 +1425,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {
@ -1436,7 +1436,7 @@
}, },
"expected": { "expected": {
"code": 200, "code": 200,
"status": "stream" "status": "tunnel"
} }
}, },
{ {

View file

@ -39,13 +39,13 @@ the response will always be a JSON object containing the `status` key, which wil
- `error` - something went wrong - `error` - something went wrong
- `picker` - we have multiple items to choose from - `picker` - we have multiple items to choose from
- `redirect` - you are being redirected to the direct service URL - `redirect` - you are being redirected to the direct service URL
- `stream` - cobalt is proxying the download for you - `tunnel` - cobalt is proxying the download for you
### stream/redirect response ### tunnel/redirect response
| key | type | values | | key | type | values |
|:-------------|:---------|:------------------------------------------------------------| |:-------------|:---------|:------------------------------------------------------------|
| `status` | `string` | `stream / redirect` | | `status` | `string` | `tunnel / redirect` |
| `url` | `string` | url for the cobalt stream, or redirect to an external link | | `url` | `string` | url for the cobalt tunnel, or redirect to an external link |
### picker response ### picker response
| key | type | values | | key | type | values |

View file

@ -4,7 +4,7 @@
"import.unknown": "couldn't load data from the file. it may be corrupted or of wrong format. here's the error i got:\n\n{{ value }}", "import.unknown": "couldn't load data from the file. it may be corrupted or of wrong format. here's the error i got:\n\n{{ value }}",
"remux.corrupted": "couldn't read the metadata from this file, it may be corrupted.", "remux.corrupted": "couldn't read the metadata from this file, it may be corrupted.",
"stream.probe": "couldn't verify whether you can download this file. try again in a few seconds!", "tunnel.probe": "couldn't verify whether you can download this file. try again in a few seconds!",
"api.auth.jwt.missing": "couldn't confirm whether you're not a robot because the processing server didn't receive the human access token. try again in a few seconds or reload the page!", "api.auth.jwt.missing": "couldn't confirm whether you're not a robot because the processing server didn't receive the human access token. try again in a few seconds or reload the page!",
"api.auth.jwt.invalid": "couldn't confirm whether you're not a robot because your human access token expired and wasn't renewed. try again in a few seconds or reload the page!", "api.auth.jwt.invalid": "couldn't confirm whether you're not a robot because your human access token expired and wasn't renewed. try again in a few seconds or reload the page!",

View file

@ -87,10 +87,10 @@
return downloadFile(response.url); return downloadFile(response.url);
} }
if (response.status === "stream") { if (response.status === "tunnel") {
changeDownloadButton("check"); changeDownloadButton("check");
const probeResult = await API.probeCobaltStream(response.url); const probeResult = await API.probeCobaltTunnel(response.url);
if (probeResult === 200) { if (probeResult === 200) {
changeDownloadButton("done"); changeDownloadButton("done");
@ -101,7 +101,7 @@
return createDialog({ return createDialog({
...defaultErrorPopup, ...defaultErrorPopup,
bodyText: $t("error.stream.failed_probe"), bodyText: $t("error.tunnel.probe"),
}); });
} }
} }

View file

@ -79,7 +79,7 @@ const request = async (url: string) => {
return response; return response;
} }
const probeCobaltStream = async (url: string) => { const probeCobaltTunnel = async (url: string) => {
const request = await fetch(`${url}&p=1`).catch(() => {}); const request = await fetch(`${url}&p=1`).catch(() => {});
if (request?.status === 200) { if (request?.status === 200) {
return request?.status; return request?.status;
@ -89,5 +89,5 @@ const probeCobaltStream = async (url: string) => {
export default { export default {
request, request,
probeCobaltStream, probeCobaltTunnel,
} }

View file

@ -2,7 +2,7 @@ enum CobaltResponseType {
Error = 'error', Error = 'error',
Picker = 'picker', Picker = 'picker',
Redirect = 'redirect', Redirect = 'redirect',
Stream = 'stream', Tunnel = 'tunnel',
} }
export type CobaltErrorResponse = { export type CobaltErrorResponse = {
@ -34,8 +34,8 @@ type CobaltRedirectResponse = {
status: CobaltResponseType.Redirect, status: CobaltResponseType.Redirect,
} & CobaltPartialURLResponse; } & CobaltPartialURLResponse;
type CobaltStreamResponse = { type CobaltTunnelResponse = {
status: CobaltResponseType.Stream, status: CobaltResponseType.Tunnel,
} & CobaltPartialURLResponse; } & CobaltPartialURLResponse;
export type CobaltSession = { export type CobaltSession = {
@ -64,4 +64,4 @@ export type CobaltServerInfoResponse = CobaltServerInfo | CobaltErrorResponse;
export type CobaltAPIResponse = CobaltErrorResponse export type CobaltAPIResponse = CobaltErrorResponse
| CobaltPickerResponse | CobaltPickerResponse
| CobaltRedirectResponse | CobaltRedirectResponse
| CobaltStreamResponse; | CobaltTunnelResponse;