mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge branch 'local-suggested' into 'main'
Add local suggestions controller See merge request soapbox-pub/ditto!631
This commit is contained in:
commit
7f71f6f50c
4 changed files with 34 additions and 7 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,
|
||||
|
|
@ -166,7 +170,7 @@ export interface AppEnv extends HonoEnv {
|
|||
|
||||
type AppContext = Context<AppEnv>;
|
||||
type AppMiddleware = MiddlewareHandler<AppEnv>;
|
||||
type AppController = Handler<AppEnv, any, HonoInput, Response | Promise<Response>>;
|
||||
type AppController<P extends string = any> = Handler<AppEnv, P, HonoInput, Response | Promise<Response>>;
|
||||
|
||||
const app = new Hono<AppEnv>({ strict: false });
|
||||
|
||||
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { MiddlewareHandler } from '@hono/hono';
|
||||
import { HTTPException } from '@hono/hono/http-exception';
|
||||
|
||||
import { AppMiddleware } from '@/app.ts';
|
||||
import { NostrSigner } from '@nostrify/nostrify';
|
||||
|
||||
/** Throw a 401 if a signer isn't set. */
|
||||
export const requireSigner: AppMiddleware = async (c, next) => {
|
||||
export const requireSigner: MiddlewareHandler<{ Variables: { signer: NostrSigner } }> = async (c, next) => {
|
||||
if (!c.get('signer')) {
|
||||
throw new HTTPException(401, { message: 'No pubkey provided' });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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