mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-04 10:00:55 +01:00
Improved routing
This commit is contained in:
parent
f7eda358e3
commit
02dbda4669
2 changed files with 6 additions and 34 deletions
|
@ -4,6 +4,7 @@ import { profileRequest } from '../twitter/routes/profile';
|
|||
import { Strings } from '../../strings';
|
||||
import { Constants } from '../../constants';
|
||||
import { linkHitRequest } from './hit';
|
||||
import { trimTrailingSlash } from 'hono/trailing-slash'
|
||||
|
||||
export const api = new Hono();
|
||||
|
||||
|
@ -20,21 +21,19 @@ api.use('*', async (c, next) => {
|
|||
await next();
|
||||
});
|
||||
|
||||
api.use(trimTrailingSlash())
|
||||
|
||||
api.get('/2/hit', linkHitRequest);
|
||||
|
||||
/* Current v1 API endpoints. Currently, these still go through the Twitter embed requests. API v2+ won't do this. */
|
||||
api.get('/status/:id', statusRequest);
|
||||
api.get('/status/:id/', statusRequest);
|
||||
api.get('/status/:id/:language', statusRequest);
|
||||
api.get('/status/:id/:language/', statusRequest);
|
||||
api.get('/:handle/status/:id', statusRequest);
|
||||
api.get('/:handle/status/:id/', statusRequest);
|
||||
api.get('/:handle/status/:id/:language', statusRequest);
|
||||
api.get('/:handle/status/:id/:language/', statusRequest);
|
||||
api.get('/robots.txt', async c => c.text(Strings.ROBOTS_TXT_API));
|
||||
|
||||
api.get('/:handle', profileRequest);
|
||||
api.get('/:handle/', profileRequest);
|
||||
|
||||
/* TODO: Figure out why / won't resolve but * does */
|
||||
api.get('*', async c => c.redirect(Constants.API_DOCS_URL, 302));
|
||||
|
|
|
@ -7,6 +7,7 @@ import { genericTwitterRedirect, setRedirectRequest } from './routes/redirects';
|
|||
import { profileRequest } from './routes/profile';
|
||||
import { statusRequest } from './routes/status';
|
||||
import { oembed } from './routes/oembed';
|
||||
import { trimTrailingSlash } from 'hono/trailing-slash';
|
||||
|
||||
export const twitter = new Hono();
|
||||
|
||||
|
@ -29,67 +30,41 @@ export const getBaseRedirectUrl = (c: Context) => {
|
|||
/* Workaround for some dumb maybe-build time issue where statusRequest isn't ready or something because none of these trigger*/
|
||||
const twitterStatusRequest = async (c: Context) => await statusRequest(c);
|
||||
const _profileRequest = async (c: Context) => await profileRequest(c);
|
||||
/* How can hono not handle trailing slashes? This is so stupid,
|
||||
|
||||
serious TODO: Figure out how to make this not stupid. */
|
||||
twitter.use(trimTrailingSlash())
|
||||
twitter.get('/:endpoint{status(es)?}/:id', twitterStatusRequest);
|
||||
twitter.get('/:endpoint{status(es)?}/:id/', twitterStatusRequest);
|
||||
twitter.get('/:endpoint{status(es)?}/:id/:language/', twitterStatusRequest);
|
||||
twitter.get('/:endpoint{status(es)?}/:id/:language', twitterStatusRequest);
|
||||
twitter.get('/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id/:language', twitterStatusRequest);
|
||||
twitter.get('/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id/:language/', twitterStatusRequest);
|
||||
twitter.get('/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id', twitterStatusRequest);
|
||||
twitter.get('/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id/', twitterStatusRequest);
|
||||
twitter.get(
|
||||
'/:prefix{(dir|dl)}/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id/:language',
|
||||
twitterStatusRequest
|
||||
);
|
||||
twitter.get(
|
||||
'/:prefix{(dir|dl)}/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id/:language/',
|
||||
twitterStatusRequest
|
||||
);
|
||||
twitter.get(
|
||||
'/:prefix{(dir|dl)}/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id',
|
||||
twitterStatusRequest
|
||||
);
|
||||
twitter.get(
|
||||
'/:prefix{(dir|dl)}/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id/',
|
||||
twitterStatusRequest
|
||||
);
|
||||
twitter.get(
|
||||
'/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id/:mediaType{(photos?|videos?)}/:mediaNumber{[1-4]}',
|
||||
twitterStatusRequest
|
||||
);
|
||||
twitter.get(
|
||||
'/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id/:mediaType{(photos?|videos?)}/:mediaNumber{[1-4]}/',
|
||||
twitterStatusRequest
|
||||
);
|
||||
twitter.get(
|
||||
'/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id/:mediaType{(photos?|videos?)}/:mediaNumber{[1-4]}/:language',
|
||||
twitterStatusRequest
|
||||
);
|
||||
twitter.get(
|
||||
'/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id/:mediaType{(photos?|videos?)}/:mediaNumber{[1-4]}/:language/',
|
||||
twitterStatusRequest
|
||||
);
|
||||
twitter.get(
|
||||
'/:prefix{(dir|dl)}/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id/:mediaType{(photos?|videos?)}/:mediaNumber{[1-4]}',
|
||||
twitterStatusRequest
|
||||
);
|
||||
twitter.get(
|
||||
'/:prefix{(dir|dl)}/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id/:mediaType{(photos?|videos?)}/:mediaNumber{[1-4]}/',
|
||||
twitterStatusRequest
|
||||
);
|
||||
twitter.get(
|
||||
'/:prefix{(dir|dl)}/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id/:mediaType{(photos?|videos?)}/:mediaNumber{[1-4]}/:language',
|
||||
twitterStatusRequest
|
||||
);
|
||||
twitter.get(
|
||||
'/:prefix{(dir|dl)}/:handle{[0-9a-zA-Z_]+}/:endpoint{status(es)?}/:id/:mediaType{(photos?|videos?)}/:mediaNumber{[1-4]}/:language/',
|
||||
'/:handle/:endpoint{status(es)?}/:id/*',
|
||||
twitterStatusRequest
|
||||
);
|
||||
|
||||
twitter.get('/version/', versionRoute);
|
||||
twitter.get('/version', versionRoute);
|
||||
twitter.get('/set_base_redirect', setRedirectRequest);
|
||||
/* Yes, I actually made the endpoint /owoembed. Deal with it. */
|
||||
|
@ -101,10 +76,8 @@ twitter.get('/i/events/:id', genericTwitterRedirect);
|
|||
twitter.get('/i/trending/:id', genericTwitterRedirect);
|
||||
twitter.get('/hashtag/:hashtag', genericTwitterRedirect);
|
||||
|
||||
twitter.get('/:handle/', _profileRequest);
|
||||
twitter.get('/:handle', _profileRequest);
|
||||
/* Redirect profile subpages in case someone links them for some reason (https://github.com/FixTweet/FxTwitter/issues/603) */
|
||||
twitter.get('/:handle/:subpage', genericTwitterRedirect);
|
||||
twitter.get('/:handle/:subpage/', genericTwitterRedirect);
|
||||
|
||||
twitter.all('*', async c => c.redirect(Constants.REDIRECT_URL, 302));
|
||||
|
|
Loading…
Add table
Reference in a new issue