64 lines
2.2 KiB
JavaScript
64 lines
2.2 KiB
JavaScript
async function e(e) {
|
|
const t = await async function(e, t) {
|
|
const o = t.cookies.SAPISID || t.cookies["__Secure-3PAPISID"];
|
|
if (!o) return {
|
|
success: !1,
|
|
code: 400,
|
|
message: "Missing cookie"
|
|
};
|
|
const n = new URL(t.href).origin,
|
|
a = Math.floor(Date.now() / 1e3),
|
|
s = await async function(e) {
|
|
const t = await crypto.subtle.digest("SHA-1", (new TextEncoder).encode(e));
|
|
return Array.from(new Uint8Array(t)).map((e => e.toString(16).padStart(2, "0"))).join("")
|
|
}(`${a} ${o} ${n}`), c = {
|
|
"x-origin": n,
|
|
authorization: `SAPISIDHASH ${a}_${s}`,
|
|
"x-goog-authuser": t.authUser,
|
|
cookie: Object.entries(t.cookies).map((([e, t]) => `${e}=${t}`)).join(";")
|
|
};
|
|
t.pageId && (c["x-goog-pageid"] = t.pageId);
|
|
const i = await fetch(`https://www.youtube.com${e}?key=${t.key}`, {
|
|
method: "POST",
|
|
headers: c,
|
|
body: JSON.stringify({
|
|
context: t.context
|
|
})
|
|
});
|
|
return {
|
|
success: !0,
|
|
data: await i.json()
|
|
}
|
|
}("/youtubei/v1/account/account_menu", e);
|
|
if (!t.success) return t;
|
|
const o = t.data;
|
|
try {
|
|
const e = o.actions[0].openPopupAction.popup.multiPageMenuRenderer,
|
|
t = e.header.activeAccountHeaderRenderer,
|
|
n = e.sections[0].multiPageMenuSectionRenderer.items[0].compactLinkRenderer.navigationEndpoint.browseEndpoint.browseId.trim().replace(/\n/g, ""),
|
|
a = o.responseContext.mainAppWebResponseContext.datasyncId.split("||")[0];
|
|
return /^UC.{22}$/.test(n) ? {
|
|
success: !0,
|
|
data: {
|
|
id: n,
|
|
googleUserId: a,
|
|
profile: t.accountPhoto.thumbnails[0].url,
|
|
username: t.accountName.simpleText
|
|
}
|
|
} : {
|
|
success: !1,
|
|
code: 400,
|
|
message: "Failed to authenticate"
|
|
}
|
|
} catch (e) {
|
|
return {
|
|
success: !1,
|
|
code: 400,
|
|
message: "Failed to authenticate"
|
|
}
|
|
}
|
|
}
|
|
|
|
export {
|
|
e
|
|
}; |