Add bookmarkController
This commit is contained in:
parent
89bdc21caa
commit
69a44f9d2b
|
@ -47,6 +47,7 @@ import { preferencesController } from './controllers/api/preferences.ts';
|
||||||
import { relayController } from './controllers/nostr/relay.ts';
|
import { relayController } from './controllers/nostr/relay.ts';
|
||||||
import { searchController } from './controllers/api/search.ts';
|
import { searchController } from './controllers/api/search.ts';
|
||||||
import {
|
import {
|
||||||
|
bookmarkController,
|
||||||
contextController,
|
contextController,
|
||||||
createStatusController,
|
createStatusController,
|
||||||
favouriteController,
|
favouriteController,
|
||||||
|
@ -152,7 +153,8 @@ app.get('/api/v1/statuses/:id{[0-9a-f]{64}}/favourited_by', favouritedByControll
|
||||||
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}/reblogged_by', rebloggedByController);
|
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}/reblogged_by', rebloggedByController);
|
||||||
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}/context', contextController);
|
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}/context', contextController);
|
||||||
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}', statusController);
|
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}', statusController);
|
||||||
app.post('/api/v1/statuses/:id{[0-9a-f]{64}}/favourite', favouriteController);
|
app.post('/api/v1/statuses/:id{[0-9a-f]{64}}/favourite', requirePubkey, favouriteController);
|
||||||
|
app.post('/api/v1/statuses/:id{[0-9a-f]{64}}/bookmark', requirePubkey, bookmarkController);
|
||||||
app.post('/api/v1/statuses', requirePubkey, createStatusController);
|
app.post('/api/v1/statuses', requirePubkey, createStatusController);
|
||||||
|
|
||||||
app.post('/api/v1/media', requireRole('user', { validatePayload: false }), mediaController);
|
app.post('/api/v1/media', requireRole('user', { validatePayload: false }), mediaController);
|
||||||
|
|
|
@ -2,7 +2,8 @@ import { type AppController } from '@/app.ts';
|
||||||
import { getUnattachedMediaByIds } from '@/db/unattached-media.ts';
|
import { getUnattachedMediaByIds } from '@/db/unattached-media.ts';
|
||||||
import { type Event, ISO6391, z } from '@/deps.ts';
|
import { type Event, ISO6391, z } from '@/deps.ts';
|
||||||
import { getAncestors, getAuthor, getDescendants, getEvent } from '@/queries.ts';
|
import { getAncestors, getAuthor, getDescendants, getEvent } from '@/queries.ts';
|
||||||
import { createEvent, paginationSchema, parseBody } from '@/utils/web.ts';
|
import { addTag } from '@/tags.ts';
|
||||||
|
import { createEvent, paginationSchema, parseBody, updateListEvent } from '@/utils/web.ts';
|
||||||
import { renderEventAccounts } from '@/views.ts';
|
import { renderEventAccounts } from '@/views.ts';
|
||||||
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
import { renderStatus } from '@/views/mastodon/statuses.ts';
|
||||||
|
|
||||||
|
@ -152,7 +153,35 @@ const rebloggedByController: AppController = (c) => {
|
||||||
return renderEventAccounts(c, [{ kinds: [6], '#e': [id], ...params }]);
|
return renderEventAccounts(c, [{ kinds: [6], '#e': [id], ...params }]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** https://docs.joinmastodon.org/methods/statuses/#bookmark */
|
||||||
|
const bookmarkController: AppController = async (c) => {
|
||||||
|
const pubkey = c.get('pubkey')!;
|
||||||
|
const eventId = c.req.param('id');
|
||||||
|
|
||||||
|
const event = await getEvent(eventId, {
|
||||||
|
kind: 1,
|
||||||
|
relations: ['author', 'event_stats', 'author_stats'],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
await updateListEvent(
|
||||||
|
{ kinds: [10003], authors: [pubkey] },
|
||||||
|
(tags) => addTag(tags, ['e', eventId]),
|
||||||
|
c,
|
||||||
|
);
|
||||||
|
|
||||||
|
const status = await renderStatus(event, pubkey);
|
||||||
|
if (status) {
|
||||||
|
status.bookmarked = true;
|
||||||
|
}
|
||||||
|
return c.json(status);
|
||||||
|
} else {
|
||||||
|
return c.json({ error: 'Event not found.' }, 404);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
bookmarkController,
|
||||||
contextController,
|
contextController,
|
||||||
createStatusController,
|
createStatusController,
|
||||||
favouriteController,
|
favouriteController,
|
||||||
|
|
Loading…
Reference in New Issue