2023-09-05 00:45:33 +00:00
|
|
|
import '@/cron.ts';
|
2023-08-17 02:53:51 +00:00
|
|
|
import {
|
|
|
|
type Context,
|
|
|
|
cors,
|
|
|
|
type Event,
|
|
|
|
type Handler,
|
|
|
|
Hono,
|
|
|
|
type HonoEnv,
|
|
|
|
logger,
|
|
|
|
type MiddlewareHandler,
|
2023-09-11 05:19:56 +00:00
|
|
|
serveStatic,
|
2023-08-17 02:53:51 +00:00
|
|
|
} from '@/deps.ts';
|
2023-08-14 16:02:09 +00:00
|
|
|
import '@/firehose.ts';
|
2023-03-05 01:55:28 +00:00
|
|
|
|
2023-07-27 15:36:19 +00:00
|
|
|
import { actorController } from './controllers/activitypub/actor.ts';
|
2023-04-29 21:35:44 +00:00
|
|
|
import {
|
|
|
|
accountController,
|
|
|
|
accountLookupController,
|
|
|
|
accountSearchController,
|
2023-05-03 20:22:24 +00:00
|
|
|
accountStatusesController,
|
2023-07-08 16:20:10 +00:00
|
|
|
createAccountController,
|
2023-09-01 18:14:27 +00:00
|
|
|
favouritesController,
|
2023-08-19 18:34:35 +00:00
|
|
|
followController,
|
2023-08-30 15:27:45 +00:00
|
|
|
followersController,
|
|
|
|
followingController,
|
2023-04-29 22:59:42 +00:00
|
|
|
relationshipsController,
|
2023-06-11 19:41:16 +00:00
|
|
|
updateCredentialsController,
|
2023-05-20 19:44:18 +00:00
|
|
|
verifyCredentialsController,
|
2023-04-30 19:45:30 +00:00
|
|
|
} from './controllers/api/accounts.ts';
|
|
|
|
import { appCredentialsController, createAppController } from './controllers/api/apps.ts';
|
2023-09-11 09:55:15 +00:00
|
|
|
import { emptyArrayController, emptyObjectController, notImplementedController } from './controllers/api/fallback.ts';
|
2023-08-28 19:23:27 +00:00
|
|
|
import { instanceController } from './controllers/api/instance.ts';
|
2023-09-08 22:00:07 +00:00
|
|
|
import { mediaController } from './controllers/api/media.ts';
|
2023-08-28 19:23:27 +00:00
|
|
|
import { notificationsController } from './controllers/api/notifications.ts';
|
2023-04-30 19:45:30 +00:00
|
|
|
import { createTokenController, oauthAuthorizeController, oauthController } from './controllers/api/oauth.ts';
|
2023-09-03 23:49:45 +00:00
|
|
|
import { frontendConfigController, updateConfigController } from './controllers/api/pleroma.ts';
|
2023-05-13 19:27:49 +00:00
|
|
|
import { preferencesController } from './controllers/api/preferences.ts';
|
2023-08-28 19:23:27 +00:00
|
|
|
import { relayController } from './controllers/nostr/relay.ts';
|
2023-05-13 22:41:21 +00:00
|
|
|
import { searchController } from './controllers/api/search.ts';
|
2023-05-07 17:32:24 +00:00
|
|
|
import {
|
|
|
|
contextController,
|
|
|
|
createStatusController,
|
|
|
|
favouriteController,
|
2023-08-29 23:08:00 +00:00
|
|
|
favouritedByController,
|
|
|
|
rebloggedByController,
|
2023-05-07 17:32:24 +00:00
|
|
|
statusController,
|
|
|
|
} from './controllers/api/statuses.ts';
|
2023-05-13 22:41:21 +00:00
|
|
|
import { streamingController } from './controllers/api/streaming.ts';
|
2023-08-29 17:41:14 +00:00
|
|
|
import {
|
|
|
|
hashtagTimelineController,
|
|
|
|
homeTimelineController,
|
|
|
|
publicTimelineController,
|
|
|
|
} from './controllers/api/timelines.ts';
|
2023-07-25 22:07:09 +00:00
|
|
|
import { trendingTagsController } from './controllers/api/trends.ts';
|
2023-04-30 19:51:56 +00:00
|
|
|
import { indexController } from './controllers/site.ts';
|
2023-07-09 23:50:47 +00:00
|
|
|
import { hostMetaController } from './controllers/well-known/host-meta.ts';
|
2023-07-10 01:32:45 +00:00
|
|
|
import { nodeInfoController, nodeInfoSchemaController } from './controllers/well-known/nodeinfo.ts';
|
2023-07-09 17:55:37 +00:00
|
|
|
import { nostrController } from './controllers/well-known/nostr.ts';
|
2023-07-09 23:50:47 +00:00
|
|
|
import { webfingerController } from './controllers/well-known/webfinger.ts';
|
2023-08-28 20:38:32 +00:00
|
|
|
import { auth19, requirePubkey } from './middleware/auth19.ts';
|
2023-09-10 20:07:31 +00:00
|
|
|
import { auth98, requireProof, requireRole } from './middleware/auth98.ts';
|
2023-09-11 09:04:55 +00:00
|
|
|
import { csp } from './middleware/csp.ts';
|
2023-03-05 02:19:57 +00:00
|
|
|
|
2023-04-29 20:22:10 +00:00
|
|
|
interface AppEnv extends HonoEnv {
|
|
|
|
Variables: {
|
2023-05-20 19:34:13 +00:00
|
|
|
/** Hex pubkey for the current user. If provided, the user is considered "logged in." */
|
2023-04-29 20:22:10 +00:00
|
|
|
pubkey?: string;
|
2023-05-20 19:34:13 +00:00
|
|
|
/** Hex secret key for the current user. Optional, but easiest way to use legacy Mastodon apps. */
|
2023-04-29 20:22:10 +00:00
|
|
|
seckey?: string;
|
2023-07-08 23:41:11 +00:00
|
|
|
/** NIP-98 signed event proving the pubkey is owned by the user. */
|
|
|
|
proof?: Event<27235>;
|
2023-04-29 20:22:10 +00:00
|
|
|
};
|
|
|
|
}
|
2023-03-05 01:55:28 +00:00
|
|
|
|
2023-04-29 20:22:10 +00:00
|
|
|
type AppContext = Context<AppEnv>;
|
|
|
|
type AppMiddleware = MiddlewareHandler<AppEnv>;
|
|
|
|
type AppController = Handler<AppEnv>;
|
|
|
|
|
|
|
|
const app = new Hono<AppEnv>();
|
|
|
|
|
2023-05-13 22:41:21 +00:00
|
|
|
app.use('*', logger());
|
|
|
|
|
|
|
|
app.get('/api/v1/streaming', streamingController);
|
|
|
|
app.get('/api/v1/streaming/', streamingController);
|
2023-08-12 18:40:21 +00:00
|
|
|
app.get('/relay', relayController);
|
2023-05-13 22:41:21 +00:00
|
|
|
|
2023-09-11 09:04:55 +00:00
|
|
|
app.use('*', csp(), cors({ origin: '*', exposeHeaders: ['link'] }), auth19, auth98());
|
2023-03-05 04:49:08 +00:00
|
|
|
|
2023-07-09 21:08:49 +00:00
|
|
|
app.get('/.well-known/webfinger', webfingerController);
|
|
|
|
app.get('/.well-known/host-meta', hostMetaController);
|
2023-07-10 01:32:45 +00:00
|
|
|
app.get('/.well-known/nodeinfo', nodeInfoController);
|
2023-07-09 17:55:37 +00:00
|
|
|
app.get('/.well-known/nostr.json', nostrController);
|
|
|
|
|
2023-07-27 15:36:19 +00:00
|
|
|
app.get('/users/:username', actorController);
|
|
|
|
|
2023-07-10 01:32:45 +00:00
|
|
|
app.get('/nodeinfo/:version', nodeInfoSchemaController);
|
|
|
|
|
2023-03-05 02:19:57 +00:00
|
|
|
app.get('/api/v1/instance', instanceController);
|
2023-03-05 01:55:28 +00:00
|
|
|
|
2023-03-05 03:49:33 +00:00
|
|
|
app.get('/api/v1/apps/verify_credentials', appCredentialsController);
|
2023-03-05 02:59:39 +00:00
|
|
|
app.post('/api/v1/apps', createAppController);
|
|
|
|
|
2023-03-05 03:36:53 +00:00
|
|
|
app.post('/oauth/token', createTokenController);
|
2023-03-05 06:36:37 +00:00
|
|
|
app.post('/oauth/revoke', emptyObjectController);
|
2023-04-30 18:28:49 +00:00
|
|
|
app.post('/oauth/authorize', oauthAuthorizeController);
|
|
|
|
app.get('/oauth/authorize', oauthController);
|
2023-03-05 03:36:53 +00:00
|
|
|
|
2023-09-11 10:57:50 +00:00
|
|
|
app.post('/api/v1/accounts', requireProof(), createAccountController);
|
2023-08-28 20:38:32 +00:00
|
|
|
app.get('/api/v1/accounts/verify_credentials', requirePubkey, verifyCredentialsController);
|
|
|
|
app.patch('/api/v1/accounts/update_credentials', requirePubkey, updateCredentialsController);
|
2023-04-29 21:28:53 +00:00
|
|
|
app.get('/api/v1/accounts/search', accountSearchController);
|
2023-04-29 21:23:23 +00:00
|
|
|
app.get('/api/v1/accounts/lookup', accountLookupController);
|
2023-04-29 22:59:42 +00:00
|
|
|
app.get('/api/v1/accounts/relationships', relationshipsController);
|
2023-08-19 18:34:35 +00:00
|
|
|
app.post('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/follow', followController);
|
2023-08-30 15:27:45 +00:00
|
|
|
app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/followers', followersController);
|
|
|
|
app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/following', followingController);
|
2023-05-03 20:22:24 +00:00
|
|
|
app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/statuses', accountStatusesController);
|
2023-04-29 21:35:44 +00:00
|
|
|
app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}', accountController);
|
2023-03-05 03:49:33 +00:00
|
|
|
|
2023-08-29 23:08:00 +00:00
|
|
|
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}/favourited_by', favouritedByController);
|
|
|
|
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}/reblogged_by', rebloggedByController);
|
2023-04-30 01:23:51 +00:00
|
|
|
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}/context', contextController);
|
2023-04-29 22:26:56 +00:00
|
|
|
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}', statusController);
|
2023-05-07 17:32:24 +00:00
|
|
|
app.post('/api/v1/statuses/:id{[0-9a-f]{64}}/favourite', favouriteController);
|
2023-08-28 20:38:32 +00:00
|
|
|
app.post('/api/v1/statuses', requirePubkey, createStatusController);
|
2023-03-05 05:26:25 +00:00
|
|
|
|
2023-09-08 23:22:38 +00:00
|
|
|
app.post('/api/v1/media', requireRole('user', { validatePayload: false }), mediaController);
|
|
|
|
app.post('/api/v2/media', requireRole('user', { validatePayload: false }), mediaController);
|
2023-09-08 22:00:07 +00:00
|
|
|
|
2023-08-29 17:41:14 +00:00
|
|
|
app.get('/api/v1/timelines/home', requirePubkey, homeTimelineController);
|
|
|
|
app.get('/api/v1/timelines/public', publicTimelineController);
|
2023-08-29 00:51:21 +00:00
|
|
|
app.get('/api/v1/timelines/tag/:hashtag', hashtagTimelineController);
|
2023-03-18 19:49:44 +00:00
|
|
|
|
2023-05-13 19:27:49 +00:00
|
|
|
app.get('/api/v1/preferences', preferencesController);
|
2023-05-13 19:45:13 +00:00
|
|
|
app.get('/api/v1/search', searchController);
|
|
|
|
app.get('/api/v2/search', searchController);
|
2023-05-13 19:27:49 +00:00
|
|
|
|
2023-06-11 04:10:27 +00:00
|
|
|
app.get('/api/pleroma/frontend_configurations', frontendConfigController);
|
|
|
|
|
2023-07-25 22:07:09 +00:00
|
|
|
app.get('/api/v1/trends/tags', trendingTagsController);
|
|
|
|
app.get('/api/v1/trends', trendingTagsController);
|
|
|
|
|
2023-08-28 20:38:32 +00:00
|
|
|
app.get('/api/v1/notifications', requirePubkey, notificationsController);
|
2023-09-01 18:14:27 +00:00
|
|
|
app.get('/api/v1/favourites', requirePubkey, favouritesController);
|
2023-08-28 19:23:27 +00:00
|
|
|
|
2023-09-08 22:00:07 +00:00
|
|
|
app.post('/api/v1/pleroma/admin/config', requireRole('admin'), updateConfigController);
|
2023-09-03 23:49:45 +00:00
|
|
|
|
2023-03-05 03:49:33 +00:00
|
|
|
// Not (yet) implemented.
|
|
|
|
app.get('/api/v1/bookmarks', emptyArrayController);
|
2023-03-05 06:36:37 +00:00
|
|
|
app.get('/api/v1/custom_emojis', 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-30 02:14:00 +00:00
|
|
|
app.get('/api/v1/markers', emptyObjectController);
|
2023-05-13 19:27:49 +00:00
|
|
|
app.get('/api/v1/conversations', emptyArrayController);
|
|
|
|
app.get('/api/v1/lists', emptyArrayController);
|
2023-03-05 03:49:33 +00:00
|
|
|
|
2023-09-11 09:55:15 +00:00
|
|
|
app.use('/api/*', notImplementedController);
|
|
|
|
|
2023-09-11 09:14:08 +00:00
|
|
|
app.get('*', serveStatic({ root: './public/' }));
|
2023-09-11 20:36:09 +00:00
|
|
|
app.get('*', serveStatic({ root: './static/' }));
|
2023-09-11 05:19:56 +00:00
|
|
|
app.get('*', serveStatic({ path: './public/index.html' }));
|
|
|
|
|
2023-04-30 19:51:56 +00:00
|
|
|
app.get('/', indexController);
|
|
|
|
|
2023-03-05 01:55:28 +00:00
|
|
|
export default app;
|
2023-04-29 20:22:10 +00:00
|
|
|
|
|
|
|
export type { AppContext, AppController, AppMiddleware };
|