This commit is contained in:
dangered wolf 2022-07-23 14:16:22 -04:00
parent bdc233be42
commit 71653d5b1a
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
7 changed files with 26 additions and 14 deletions

2
src/env.d.ts vendored
View file

@ -3,4 +3,4 @@ declare const BRANDING_NAME_DISCORD: string;
declare const DIRECT_MEDIA_DOMAINS: string;
declare const HOST_URL: string;
declare const REDIRECT_URL: string;
declare const MOSAIC_DOMAIN_LIST: string;
declare const MOSAIC_DOMAIN_LIST: string;

View file

@ -1,6 +1,9 @@
import { Constants } from './constants';
export const fetchUsingGuest = async (status: string, event: FetchEvent): Promise<TimelineBlobPartial> => {
export const fetchUsingGuest = async (
status: string,
event: FetchEvent
): Promise<TimelineBlobPartial> => {
let apiAttempts = 0;
let cachedTokenFailed = false;
@ -54,7 +57,7 @@ export const fetchUsingGuest = async (status: string, event: FetchEvent): Promis
This can effectively mean virtually unlimited (read) access to Twitter's API,
which is very funny. */
activate = await fetch(guestTokenRequest);
activate = await fetch(guestTokenRequest);
}
/* Let's grab that guest_token so we can use it */

View file

@ -1,4 +1,4 @@
import { Constants } from "./constants"
import { Constants } from './constants';
export const handleMosaic = async (mediaList: TweetMedia[]): Promise<TweetMedia> => {
let mosaicDomains = Constants.MOSAIC_DOMAIN_LIST;
@ -8,7 +8,7 @@ export const handleMosaic = async (mediaList: TweetMedia[]): Promise<TweetMedia>
let domain = mosaicDomains[Math.floor(Math.random() * mosaicDomains.length)];
// let response = await fetch(`https://${domain}/ping`);
// if (response.status === 200) {
selectedDomain = domain;
selectedDomain = domain;
// } else {
// mosaicDomains = mosaicDomains.filter(d => d !== domain);
// console.log(`${domain} is not available, removing from list`);
@ -20,7 +20,11 @@ export const handleMosaic = async (mediaList: TweetMedia[]): Promise<TweetMedia>
return mediaList[0];
} else {
console.log('mediaList', mediaList);
let mosaicMedia = mediaList.map(media => media.media_url_https?.match(/(?<=\/media\/)[a-zA-Z0-9_\-]+(?=[\.\?])/g)?.[0] || '');
let mosaicMedia = mediaList.map(
media =>
media.media_url_https?.match(/(?<=\/media\/)[a-zA-Z0-9_\-]+(?=[\.\?])/g)?.[0] ||
''
);
console.log('mosaicMedia', mosaicMedia);
let constructUrl = `https://${selectedDomain}/1`;
if (mosaicMedia[0]) {
@ -35,7 +39,7 @@ export const handleMosaic = async (mediaList: TweetMedia[]): Promise<TweetMedia>
if (mosaicMedia[3]) {
constructUrl += `/${mosaicMedia[3]}`;
}
return {
media_url_https: constructUrl,
original_info: {
@ -45,4 +49,4 @@ export const handleMosaic = async (mediaList: TweetMedia[]): Promise<TweetMedia>
type: 'photo'
} as TweetMedia;
}
}
};

View file

@ -5,12 +5,17 @@ import { Strings } from './strings';
const router = Router();
const statusRequest = async (request: Request, event: FetchEvent, flags: InputFlags = {}) => {
const statusRequest = async (
request: Request,
event: FetchEvent,
flags: InputFlags = {}
) => {
const { handle, id, mediaNumber } = request.params;
const url = new URL(request.url);
const userAgent = request.headers.get('User-Agent') || '';
let isBotUA = userAgent.match(/bot|facebook|embed|got|Firefox\/92|curl|wget/gi) !== null;
let isBotUA =
userAgent.match(/bot|facebook|embed|got|Firefox\/92|curl|wget/gi) !== null;
if (
url.pathname.match(/\/status(es)?\/\d+\.(mp4|png|jpg)/g) !== null ||

View file

@ -344,4 +344,4 @@ export const handleStatus = async (
headers: headers.join('')
})
};
};
};

4
src/types.d.ts vendored
View file

@ -13,5 +13,5 @@ interface StatusResponse {
interface Request {
params: {
[param: string]: string;
}
}
};
}

View file

@ -34,7 +34,7 @@ module.exports = {
}),
new webpack.DefinePlugin({
MOSAIC_DOMAIN_LIST: `'${process.env.MOSAIC_DOMAIN_LIST}'`
}),
})
],
optimization: {
mangleExports: 'size'