Skip to content

Commit

Permalink
Add optional name parameter to direct file url
Browse files Browse the repository at this point in the history
  • Loading branch information
ccloli authored Dec 31, 2024
1 parent 295c5b7 commit 5080eaa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/embed/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ export const handleStatus = async (
}

if (redirectUrl) {
// TODO: only append name if it's an image
if (flags.name) {
redirectUrl = `${redirectUrl}:${flags.name}`;
}
return c.redirect(redirectUrl, 302);
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/realms/twitter/routes/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ export const statusRequest = async (c: Context) => {
flags.direct = true;
}

/* Support redirecting to specific quality of image, like:
https://pbs.twimg.com/media/foobar.jpg:orig
TODO: Should we support video file like :1280x720, though it's not the offical way */
if (flags.direct) {
// check if the name is in search params, e.g. /i/status/1234567890?name=orig
const nameFromSearchParams = url.searchParams.get('name');
if (nameFromSearchParams) {
flags.name = nameFromSearchParams;
} else {
// check if the status ends with :<name>, e.g. /i/status/1234567890.jpg:orig
const matched = url.pathname.match(/\/status(?:es)?\/\d{2,20}(?:\..*?):(.*?)$/);
const nameFromUrl = matched && matched[1];
if (nameFromUrl) {
flags.name = nameFromUrl;
}
}
}

/* TODO: Figure out what we're doing with FixTweet / FixupX branding in future */
if (/fixup/g.test(url.href)) {
console.log(`We're using x domain`);
Expand Down
1 change: 1 addition & 0 deletions src/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type InputFlags = {
archive?: boolean;
gallery?: boolean;
nativeMultiImage?: boolean;
name?: string;
};

interface StatusResponse {
Expand Down

0 comments on commit 5080eaa

Please sign in to comment.