mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Add local suggestions controller
This commit is contained in:
parent
c3403ba724
commit
99d52f8640
3 changed files with 30 additions and 3 deletions
|
|
@ -109,7 +109,11 @@ import {
|
|||
zappedByController,
|
||||
} from '@/controllers/api/statuses.ts';
|
||||
import { streamingController } from '@/controllers/api/streaming.ts';
|
||||
import { suggestionsV1Controller, suggestionsV2Controller } from '@/controllers/api/suggestions.ts';
|
||||
import {
|
||||
localSuggestionsController,
|
||||
suggestionsV1Controller,
|
||||
suggestionsV2Controller,
|
||||
} from '@/controllers/api/suggestions.ts';
|
||||
import {
|
||||
hashtagTimelineController,
|
||||
homeTimelineController,
|
||||
|
|
@ -348,6 +352,7 @@ app.get(
|
|||
|
||||
app.get('/api/v1/suggestions', suggestionsV1Controller);
|
||||
app.get('/api/v2/suggestions', suggestionsV2Controller);
|
||||
app.get('/api/v2/ditto/suggestions/local', localSuggestionsController);
|
||||
|
||||
app.get('/api/v1/notifications', rateLimitMiddleware(8, Time.seconds(30)), requireSigner, notificationsController);
|
||||
app.get('/api/v1/notifications/:id', requireSigner, notificationController);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { matchFilter } from 'nostr-tools';
|
|||
import { AppContext, AppController } from '@/app.ts';
|
||||
import { Conf } from '@/config.ts';
|
||||
import { hydrateEvents } from '@/storages/hydrate.ts';
|
||||
import { paginatedList } from '@/utils/api.ts';
|
||||
import { paginated, paginatedList } from '@/utils/api.ts';
|
||||
import { getTagSet } from '@/utils/tags.ts';
|
||||
import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts';
|
||||
|
||||
|
|
@ -87,3 +87,24 @@ async function renderV2Suggestions(c: AppContext, params: { offset: number; limi
|
|||
};
|
||||
}));
|
||||
}
|
||||
|
||||
export const localSuggestionsController: AppController = async (c) => {
|
||||
const signal = c.req.raw.signal;
|
||||
const params = c.get('pagination');
|
||||
const store = c.get('store');
|
||||
|
||||
const events = await store.query(
|
||||
[{ kinds: [0], search: `domain:${Conf.url.host}`, ...params }],
|
||||
{ signal },
|
||||
)
|
||||
.then((events) => hydrateEvents({ store, events, signal }));
|
||||
|
||||
const suggestions = await Promise.all(events.map(async (event) => {
|
||||
return {
|
||||
source: 'global',
|
||||
account: await renderAccount(event),
|
||||
};
|
||||
}));
|
||||
|
||||
return paginated(c, events, suggestions);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -207,7 +207,8 @@ function buildLinkHeader(url: string, events: NostrEvent[]): string | undefined
|
|||
return `<${next}>; rel="next", <${prev}>; rel="prev"`;
|
||||
}
|
||||
|
||||
type Entity = { id: string };
|
||||
// deno-lint-ignore ban-types
|
||||
type Entity = {};
|
||||
type HeaderRecord = Record<string, string | string[]>;
|
||||
|
||||
/** Return results with pagination headers. Assumes chronological sorting of events. */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue