hello new update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { getCookie } from "./roblox";
|
||||
import { proxyFetch } from "./utils";
|
||||
|
||||
type RecommendationEntry = {
|
||||
contentType: "Game"|string,
|
||||
@@ -59,11 +60,8 @@ export type OmniRecommendation = {
|
||||
}
|
||||
|
||||
export async function getOmniRecommendationsHome(): Promise<OmniRecommendation> {
|
||||
const data = await fetch(`${document.baseURI}api/discovery/omni-recommendation`,{
|
||||
const data = await proxyFetch(`https://apis.roblox.com/discovery-api/omni-recommendation`,{
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `${getCookie()}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
pageType: "Home",
|
||||
sessionId: crypto.randomUUID(),
|
||||
@@ -72,7 +70,10 @@ export async function getOmniRecommendationsHome(): Promise<OmniRecommendation>
|
||||
cpuCores: 4,
|
||||
maxResolution: "1920x1080",
|
||||
maxMemory: 8192
|
||||
})
|
||||
}),
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
})
|
||||
return await data.json() as OmniRecommendation
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getCookie } from "./roblox"
|
||||
import { proxyFetch } from "./utils"
|
||||
|
||||
export type UserProfileDetails = {
|
||||
description: string,
|
||||
@@ -16,11 +17,11 @@ export async function getLoggedInUser(): Promise<{
|
||||
name: string,
|
||||
displayName: string
|
||||
}> {
|
||||
const data = await fetch(`${document.baseURI}api/user/authenticated`, {
|
||||
const data = await proxyFetch(`https://users.roblox.com/v1/users/authenticated`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `${getCookie()}`
|
||||
},
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
})
|
||||
return (await data.json() as any) as {
|
||||
id: number,
|
||||
@@ -30,11 +31,11 @@ export async function getLoggedInUser(): Promise<{
|
||||
}
|
||||
|
||||
export async function getUserByUserId(userid: string): Promise<UserProfileDetails> {
|
||||
const data = await fetch(`${document.baseURI}api/user?id=${userid}`, {
|
||||
const data = await proxyFetch(`https://users.roblox.com/v1/users/${userid}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `${getCookie()}`
|
||||
},
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
})
|
||||
return (await data.json() as any) as UserProfileDetails
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
"use client";
|
||||
export function setCookie(cookie: string): void {}
|
||||
|
||||
export function setCookie(cookie: string): void {
|
||||
window.localStorage.roblosecurity = cookie;
|
||||
}
|
||||
|
||||
export function getCookie() {
|
||||
return window.localStorage.roblosecurity
|
||||
export async function getCookie(): Promise<string> {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -1,54 +1,67 @@
|
||||
"use client";
|
||||
|
||||
import { addThumbnail } from "@/hooks/use-lazy-load";
|
||||
import { getCookie } from "./roblox";
|
||||
import { proxyFetch } from "./utils";
|
||||
|
||||
export type AssetThumbnail = {
|
||||
requestId: string,
|
||||
errorCode: number,
|
||||
errorMessage: string,
|
||||
targetId: number,
|
||||
state: "Completed" | string,
|
||||
imageUrl: string,
|
||||
version: string
|
||||
}
|
||||
requestId: string;
|
||||
errorCode: number;
|
||||
errorMessage: string;
|
||||
targetId: number;
|
||||
state: "Completed" | string;
|
||||
imageUrl: string;
|
||||
version: string;
|
||||
};
|
||||
|
||||
export type ThumbnailRequest = {
|
||||
type: "GameThumbnail",
|
||||
targetId: number,
|
||||
format: "webp",
|
||||
size: string
|
||||
}
|
||||
type: "GameThumbnail" | "AvatarHeadShot";
|
||||
targetId: number;
|
||||
format: "webp";
|
||||
size: string;
|
||||
};
|
||||
|
||||
export async function getThumbnails(b: ThumbnailRequest[]): Promise<AssetThumbnail[]> {
|
||||
const data = await fetch(`${document.baseURI}api/thumbnails/batch`,{
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `${getCookie()}`
|
||||
},
|
||||
body: JSON.stringify(
|
||||
b.map(a=>{
|
||||
return {
|
||||
requestId: `${a.targetId}::${a.type}:${a.size}:${a.format}:regular`,
|
||||
type: a.type,
|
||||
targetId: a.targetId,
|
||||
token: "",
|
||||
format: a.format,
|
||||
size: a.size
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
return (await data.json() as any).data as AssetThumbnail[]
|
||||
/*
|
||||
! WARNING: DO NOT USE
|
||||
*/
|
||||
export async function getThumbnails(
|
||||
b: ThumbnailRequest[]
|
||||
): Promise<AssetThumbnail[]> {
|
||||
const batchSize = 50;
|
||||
const results: AssetThumbnail[] = [];
|
||||
for (let i = 0; i < b.length; i += batchSize) {
|
||||
const batch = b.slice(i, i + batchSize);
|
||||
const data = await proxyFetch(
|
||||
`https://thumbnails.roblox.com/v1/batch`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify(
|
||||
batch.map((a) => ({
|
||||
requestId: `${a.targetId}::${a.type}:${a.size}:${a.format}:regular`,
|
||||
type: a.type,
|
||||
targetId: a.targetId,
|
||||
token: "",
|
||||
format: a.format,
|
||||
size: a.size,
|
||||
}))
|
||||
),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
const json = await data.json();
|
||||
json.data.forEach((a: AssetThumbnail) => {
|
||||
// match GameThumbnail from 4972273297::GameThumbnail:384x216:webp:regular and any like- string
|
||||
const ty = b.find((c) => c.targetId == a.targetId)!;
|
||||
addThumbnail(ty.type + "_" + a.targetId.toString(), a.imageUrl);
|
||||
});
|
||||
results.push(...(json.data as AssetThumbnail[]));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
export async function loadThumbnails(b: ThumbnailRequest[]): Promise<void> {
|
||||
const th = await getThumbnails(b);
|
||||
th.forEach(a=>{
|
||||
// match GameThumbnail from 4972273297::GameThumbnail:384x216:webp:regular and any like- string
|
||||
const ty = b.find(c=>c.targetId==a.targetId)!
|
||||
addThumbnail(ty.type+'_'+a.targetId.toString(), a.imageUrl)
|
||||
})
|
||||
}
|
||||
|
||||
// https://apis.roblox.com/discovery-api/omni-recommendation
|
||||
// https://apis.roblox.com/discovery-api/omni-recommendation
|
||||
|
||||
32
lib/utils.ts
32
lib/utils.ts
@@ -1,6 +1,32 @@
|
||||
import { clsx, type ClassValue } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
import { clsx, type ClassValue } from "clsx";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
|
||||
export async function proxyFetch(
|
||||
input: RequestInfo | URL,
|
||||
init?: RequestInit
|
||||
): Promise<Response> {
|
||||
const url =
|
||||
typeof input === "string"
|
||||
? input
|
||||
: input instanceof Request
|
||||
? input.url
|
||||
: "";
|
||||
const proxyUrl = `/api/proxy?url=${encodeURIComponent(url)}`;
|
||||
|
||||
// fix headers
|
||||
const headers = new Headers(init?.headers || {});
|
||||
headers.delete("accept-encoding"); // prevent stupid encoding bug
|
||||
|
||||
const fetchInit: RequestInit = {
|
||||
...init,
|
||||
method: init?.method || "GET",
|
||||
headers,
|
||||
body: init?.body,
|
||||
};
|
||||
|
||||
return window.fetch(proxyUrl, fetchInit);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user