mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-18 21:48:29 +03:00
Parse user agent header
This commit is contained in:
@@ -18,6 +18,7 @@ import { getReputation } from "../utils/reputation";
|
||||
import { APIVideoData, APIVideoInfo } from "../types/youtubeApi.model";
|
||||
import { UserID } from "../types/user.model";
|
||||
import { isUserVIP } from "../utils/isUserVIP";
|
||||
import { parseUserAgent } from "../utils/userAgent";
|
||||
|
||||
type CheckResult = {
|
||||
pass: boolean,
|
||||
@@ -550,8 +551,7 @@ function preprocessInput(req: Request) {
|
||||
}
|
||||
});
|
||||
|
||||
const userAgentAsArray = req.get("user-agent");
|
||||
const userAgent = userAgentAsArray || "";
|
||||
const userAgent = req.get("user-agent") ?? parseUserAgent(req.get("User-Agent")) ?? "";
|
||||
|
||||
return {videoID, userID, service, videoDuration, videoDurationParam, segments, userAgent};
|
||||
}
|
||||
|
||||
13
src/utils/userAgent.ts
Normal file
13
src/utils/userAgent.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export function parseUserAgent(userAgent: string): string {
|
||||
const ua = userAgent.toLowerCase();
|
||||
|
||||
if (ua.includes("com.google.android.youtube/") || ua.includes("com.vanced.android.youtube/")) {
|
||||
return `Vanced/${ua.match(/.android.youtube\/([^\s]+)/)[1]}`;
|
||||
}
|
||||
|
||||
if (ua.includes("mpv_sponsorblock/")) {
|
||||
return ua;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
Reference in New Issue
Block a user