Add GET /api/v1/statuses/:id
This commit is contained in:
parent
f87a17e609
commit
d84e593e53
|
@ -1,6 +1,7 @@
|
||||||
import { type AppContext } from '@/app.ts';
|
import { type AppContext, AppController } from '@/app.ts';
|
||||||
import { validator, z } from '@/deps.ts';
|
import { validator, z } from '@/deps.ts';
|
||||||
import { type Event } from '@/event.ts';
|
import { type Event } from '@/event.ts';
|
||||||
|
import { getEvent } from '../client.ts';
|
||||||
|
|
||||||
import publish from '../publisher.ts';
|
import publish from '../publisher.ts';
|
||||||
import { toStatus } from '../transmute.ts';
|
import { toStatus } from '../transmute.ts';
|
||||||
|
@ -9,6 +10,18 @@ const createStatusSchema = z.object({
|
||||||
status: z.string(),
|
status: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const statusController: AppController = async (c) => {
|
||||||
|
const id = c.req.param('id');
|
||||||
|
|
||||||
|
const event = await getEvent(id);
|
||||||
|
|
||||||
|
if (event && event.kind === 1) {
|
||||||
|
return c.json(await toStatus(event as Event<1>));
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({ error: 'Event not found.' }, 404);
|
||||||
|
};
|
||||||
|
|
||||||
const createStatusController = validator('json', async (value, c: AppContext) => {
|
const createStatusController = validator('json', async (value, c: AppContext) => {
|
||||||
const pubkey = c.get('pubkey')!;
|
const pubkey = c.get('pubkey')!;
|
||||||
const seckey = c.get('seckey');
|
const seckey = c.get('seckey');
|
||||||
|
@ -33,4 +46,4 @@ const createStatusController = validator('json', async (value, c: AppContext) =>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export { createStatusController };
|
export { createStatusController, statusController };
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { emptyArrayController, emptyObjectController } from './api/fallback.ts';
|
||||||
import homeController from './api/home.ts';
|
import homeController from './api/home.ts';
|
||||||
import instanceController from './api/instance.ts';
|
import instanceController from './api/instance.ts';
|
||||||
import { createTokenController } from './api/oauth.ts';
|
import { createTokenController } from './api/oauth.ts';
|
||||||
import { createStatusController } from './api/statuses.ts';
|
import { createStatusController, statusController } from './api/statuses.ts';
|
||||||
import { requireAuth, setAuth } from './middleware/auth.ts';
|
import { requireAuth, setAuth } from './middleware/auth.ts';
|
||||||
|
|
||||||
interface AppEnv extends HonoEnv {
|
interface AppEnv extends HonoEnv {
|
||||||
|
@ -42,6 +42,7 @@ app.get('/api/v1/accounts/search', accountSearchController);
|
||||||
app.get('/api/v1/accounts/lookup', accountLookupController);
|
app.get('/api/v1/accounts/lookup', accountLookupController);
|
||||||
app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}', accountController);
|
app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}', accountController);
|
||||||
|
|
||||||
|
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}', statusController);
|
||||||
app.post('/api/v1/statuses', requireAuth, createStatusController);
|
app.post('/api/v1/statuses', requireAuth, createStatusController);
|
||||||
|
|
||||||
app.get('/api/v1/timelines/home', requireAuth, homeController);
|
app.get('/api/v1/timelines/home', requireAuth, homeController);
|
||||||
|
|
Loading…
Reference in New Issue