switch on guest token cache (borked)

This commit is contained in:
dangered wolf 2022-08-18 00:49:57 -04:00
parent 45da5e3ecb
commit 4ae10034db
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
4 changed files with 10 additions and 8 deletions

View file

@ -138,9 +138,10 @@ const populateTweetProperties = async (
available for free using api.fxtwitter.com. */
export const statusAPI = async (
status: string,
language: string | undefined
language: string | undefined,
event: FetchEvent
): Promise<APIResponse> => {
const conversation = await fetchUsingGuest(status);
const conversation = await fetchUsingGuest(status, event);
const tweet = conversation?.globalObjects?.tweets?.[status] || {};
/* Fallback for if Tweet did not load */

View file

@ -1,6 +1,6 @@
import { Constants } from './constants';
export const fetchUsingGuest = async (status: string): Promise<TimelineBlobPartial> => {
export const fetchUsingGuest = async (status: string, event: FetchEvent): Promise<TimelineBlobPartial> => {
let apiAttempts = 0;
let cachedTokenFailed = false;
@ -121,9 +121,8 @@ export const fetchUsingGuest = async (status: string): Promise<TimelineBlobParti
cachedTokenFailed = true;
continue;
}
/* Once we've confirmed we have a working guest token, let's cache it! */
// event.waitUntil(cache.put(guestTokenRequest, activate.clone()));
event.waitUntil(cache.put(guestTokenRequest, activate.clone()));
conversation.guestToken = guestToken;
return conversation;
}

View file

@ -90,7 +90,8 @@ const statusRequest = async (
mediaNumber ? parseInt(mediaNumber) : undefined,
userAgent,
flags,
language
language,
event
);
/* Complete responses are normally sent just by errors. Normal embeds send a `text` value. */

View file

@ -24,12 +24,13 @@ export const handleStatus = async (
mediaNumber?: number,
userAgent?: string,
flags?: InputFlags,
language?: string
language?: string,
event?: FetchEvent
// eslint-disable-next-line sonarjs/cognitive-complexity
): Promise<StatusResponse> => {
console.log('Direct?', flags?.direct);
const api = await statusAPI(status, language);
const api = await statusAPI(status, language, event as FetchEvent);
const tweet = api?.tweet as APITweet;
/* Catch this request if it's an API response */