2023-04-29 20:22:10 +00:00
|
|
|
import { type Context, cors, type Handler, Hono, type HonoEnv, type MiddlewareHandler } from '@/deps.ts';
|
2023-03-05 01:55:28 +00:00
|
|
|
|
2023-04-29 21:35:44 +00:00
|
|
|
import {
|
|
|
|
accountController,
|
|
|
|
accountLookupController,
|
|
|
|
accountSearchController,
|
|
|
|
credentialsController,
|
2023-04-29 22:59:42 +00:00
|
|
|
relationshipsController,
|
2023-04-29 21:35:44 +00:00
|
|
|
} from './api/accounts.ts';
|
2023-03-05 03:49:33 +00:00
|
|
|
import { appCredentialsController, createAppController } from './api/apps.ts';
|
2023-03-05 06:36:37 +00:00
|
|
|
import { emptyArrayController, emptyObjectController } from './api/fallback.ts';
|
2023-03-18 19:49:44 +00:00
|
|
|
import homeController from './api/home.ts';
|
2023-03-05 02:19:57 +00:00
|
|
|
import instanceController from './api/instance.ts';
|
2023-03-05 03:36:53 +00:00
|
|
|
import { createTokenController } from './api/oauth.ts';
|
2023-04-30 01:23:51 +00:00
|
|
|
import { contextController, createStatusController, statusController } from './api/statuses.ts';
|
2023-04-29 20:22:10 +00:00
|
|
|
import { requireAuth, setAuth } from './middleware/auth.ts';
|
2023-03-05 02:19:57 +00:00
|
|
|
|
2023-04-29 20:22:10 +00:00
|
|
|
interface AppEnv extends HonoEnv {
|
|
|
|
Variables: {
|
|
|
|
pubkey?: string;
|
|
|
|
seckey?: string;
|
|
|
|
};
|
|
|
|
}
|
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-04-30 02:07:59 +00:00
|
|
|
app.use('/*', cors({ origin: '*', exposeHeaders: ['link'] }), setAuth);
|
2023-03-05 04:49:08 +00:00
|
|
|
|
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-03-05 03:36:53 +00:00
|
|
|
|
2023-04-29 20:22:10 +00:00
|
|
|
app.get('/api/v1/accounts/verify_credentials', requireAuth, credentialsController);
|
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-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-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-04-29 20:22:10 +00:00
|
|
|
app.post('/api/v1/statuses', requireAuth, createStatusController);
|
2023-03-05 05:26:25 +00:00
|
|
|
|
2023-04-29 20:22:10 +00:00
|
|
|
app.get('/api/v1/timelines/home', requireAuth, homeController);
|
2023-03-18 19:49:44 +00:00
|
|
|
|
2023-03-05 03:49:33 +00:00
|
|
|
// Not (yet) implemented.
|
2023-03-05 06:36:37 +00:00
|
|
|
app.get('/api/v1/notifications', emptyArrayController);
|
2023-03-05 03:49:33 +00:00
|
|
|
app.get('/api/v1/accounts/:id/statuses', emptyArrayController);
|
|
|
|
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/accounts/search', emptyArrayController);
|
|
|
|
app.get('/api/v2/search', (c) => c.json({ accounts: [], statuses: [], hashtags: [] }));
|
|
|
|
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-03-05 03:49:33 +00:00
|
|
|
|
2023-03-05 01:55:28 +00:00
|
|
|
export default app;
|
2023-04-29 20:22:10 +00:00
|
|
|
|
|
|
|
export type { AppContext, AppController, AppMiddleware };
|