ditto/src/app.ts

130 lines
5.5 KiB
TypeScript
Raw Normal View History

2023-04-30 15:16:33 -05:00
import { type Context, cors, type Handler, Hono, type HonoEnv, logger, type MiddlewareHandler } from '@/deps.ts';
2023-07-08 18:41:11 -05:00
import { type Event } from '@/event.ts';
import '@/loopback.ts';
2023-03-04 19:55:28 -06:00
2023-07-27 10:36:19 -05:00
import { actorController } from './controllers/activitypub/actor.ts';
2023-04-29 16:35:44 -05:00
import {
accountController,
accountLookupController,
accountSearchController,
accountStatusesController,
createAccountController,
2023-04-29 17:59:42 -05:00
relationshipsController,
2023-06-11 14:41:16 -05:00
updateCredentialsController,
verifyCredentialsController,
2023-04-30 14:45:30 -05:00
} from './controllers/api/accounts.ts';
import { appCredentialsController, createAppController } from './controllers/api/apps.ts';
import { emptyArrayController, emptyObjectController } from './controllers/api/fallback.ts';
2023-07-07 15:07:20 -05:00
import { homeController, publicController } from './controllers/api/timelines.ts';
2023-04-30 14:45:30 -05:00
import instanceController from './controllers/api/instance.ts';
import { createTokenController, oauthAuthorizeController, oauthController } from './controllers/api/oauth.ts';
import { frontendConfigController } from './controllers/api/pleroma.ts';
2023-05-13 14:27:49 -05:00
import { preferencesController } from './controllers/api/preferences.ts';
import { searchController } from './controllers/api/search.ts';
2023-05-07 12:32:24 -05:00
import {
contextController,
createStatusController,
favouriteController,
statusController,
} from './controllers/api/statuses.ts';
import { streamingController } from './controllers/api/streaming.ts';
import { trendingTagsController } from './controllers/api/trends.ts';
2023-04-30 14:51:56 -05:00
import { indexController } from './controllers/site.ts';
2023-07-09 18:50:47 -05:00
import { hostMetaController } from './controllers/well-known/host-meta.ts';
2023-07-09 20:32:45 -05:00
import { nodeInfoController, nodeInfoSchemaController } from './controllers/well-known/nodeinfo.ts';
2023-07-09 12:55:37 -05:00
import { nostrController } from './controllers/well-known/nostr.ts';
2023-07-09 18:50:47 -05:00
import { webfingerController } from './controllers/well-known/webfinger.ts';
2023-07-08 18:41:11 -05:00
import { auth19, requireAuth } from './middleware/auth19.ts';
import { auth98 } from './middleware/auth98.ts';
2023-03-04 20:19:57 -06:00
2023-04-29 15:22:10 -05:00
interface AppEnv extends HonoEnv {
Variables: {
/** Hex pubkey for the current user. If provided, the user is considered "logged in." */
2023-04-29 15:22:10 -05:00
pubkey?: string;
/** Hex secret key for the current user. Optional, but easiest way to use legacy Mastodon apps. */
2023-04-29 15:22:10 -05:00
seckey?: string;
2023-05-20 19:39:05 -05:00
/** UUID from the access token. Used for WebSocket event signing. */
session?: string;
2023-07-08 18:41:11 -05:00
/** NIP-98 signed event proving the pubkey is owned by the user. */
proof?: Event<27235>;
2023-04-29 15:22:10 -05:00
};
}
2023-03-04 19:55:28 -06:00
2023-04-29 15:22:10 -05:00
type AppContext = Context<AppEnv>;
type AppMiddleware = MiddlewareHandler<AppEnv>;
type AppController = Handler<AppEnv>;
const app = new Hono<AppEnv>();
app.use('*', logger());
app.get('/api/v1/streaming', streamingController);
app.get('/api/v1/streaming/', streamingController);
2023-07-08 18:41:11 -05:00
app.use('*', cors({ origin: '*', exposeHeaders: ['link'] }), auth19, auth98());
2023-03-04 22:49:08 -06:00
2023-07-09 16:08:49 -05:00
app.get('/.well-known/webfinger', webfingerController);
app.get('/.well-known/host-meta', hostMetaController);
2023-07-09 20:32:45 -05:00
app.get('/.well-known/nodeinfo', nodeInfoController);
2023-07-09 12:55:37 -05:00
app.get('/.well-known/nostr.json', nostrController);
2023-07-27 10:36:19 -05:00
app.get('/users/:username', actorController);
2023-07-09 20:32:45 -05:00
app.get('/nodeinfo/:version', nodeInfoSchemaController);
2023-03-04 20:19:57 -06:00
app.get('/api/v1/instance', instanceController);
2023-03-04 19:55:28 -06:00
app.get('/api/v1/apps/verify_credentials', appCredentialsController);
2023-03-04 20:59:39 -06:00
app.post('/api/v1/apps', createAppController);
2023-03-04 21:36:53 -06:00
app.post('/oauth/token', createTokenController);
2023-03-05 00:36:37 -06:00
app.post('/oauth/revoke', emptyObjectController);
2023-04-30 13:28:49 -05:00
app.post('/oauth/authorize', oauthAuthorizeController);
app.get('/oauth/authorize', oauthController);
2023-03-04 21:36:53 -06:00
app.post('/api/v1/acccounts', createAccountController);
app.get('/api/v1/accounts/verify_credentials', requireAuth, verifyCredentialsController);
2023-06-11 14:41:16 -05:00
app.patch('/api/v1/accounts/update_credentials', requireAuth, updateCredentialsController);
app.get('/api/v1/accounts/search', accountSearchController);
2023-04-29 16:23:23 -05:00
app.get('/api/v1/accounts/lookup', accountLookupController);
2023-04-29 17:59:42 -05:00
app.get('/api/v1/accounts/relationships', relationshipsController);
app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/statuses', accountStatusesController);
2023-04-29 16:35:44 -05:00
app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}', accountController);
2023-04-29 20:23:51 -05:00
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}/context', contextController);
2023-04-29 17:26:56 -05:00
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}', statusController);
2023-05-07 12:32:24 -05:00
app.post('/api/v1/statuses/:id{[0-9a-f]{64}}/favourite', favouriteController);
2023-04-29 15:22:10 -05:00
app.post('/api/v1/statuses', requireAuth, createStatusController);
2023-03-04 23:26:25 -06:00
2023-04-29 15:22:10 -05:00
app.get('/api/v1/timelines/home', requireAuth, homeController);
2023-07-07 15:07:20 -05:00
app.get('/api/v1/timelines/public', publicController);
2023-03-18 14:49:44 -05:00
2023-05-13 14:27:49 -05:00
app.get('/api/v1/preferences', preferencesController);
2023-05-13 14:45:13 -05:00
app.get('/api/v1/search', searchController);
app.get('/api/v2/search', searchController);
2023-05-13 14:27:49 -05:00
app.get('/api/pleroma/frontend_configurations', frontendConfigController);
app.get('/api/v1/trends/tags', trendingTagsController);
app.get('/api/v1/trends', trendingTagsController);
// Not (yet) implemented.
2023-03-05 00:36:37 -06:00
app.get('/api/v1/notifications', emptyArrayController);
app.get('/api/v1/bookmarks', emptyArrayController);
2023-03-05 00:36:37 -06:00
app.get('/api/v1/custom_emojis', emptyArrayController);
app.get('/api/v1/accounts/search', emptyArrayController);
app.get('/api/v1/filters', emptyArrayController);
app.get('/api/v1/blocks', emptyArrayController);
app.get('/api/v1/mutes', emptyArrayController);
app.get('/api/v1/domain_blocks', emptyArrayController);
2023-04-29 21:14:00 -05:00
app.get('/api/v1/markers', emptyObjectController);
2023-05-13 14:27:49 -05:00
app.get('/api/v1/conversations', emptyArrayController);
app.get('/api/v1/favourites', emptyArrayController);
app.get('/api/v1/lists', emptyArrayController);
2023-04-30 14:51:56 -05:00
app.get('/', indexController);
2023-03-04 19:55:28 -06:00
export default app;
2023-04-29 15:22:10 -05:00
export type { AppContext, AppController, AppMiddleware };