Rename all middleware to thingMiddleware

This commit is contained in:
Alex Gleason 2024-05-14 12:07:54 -05:00
parent 1accae2222
commit 084143c5c8
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
5 changed files with 18 additions and 18 deletions

View File

@ -81,12 +81,12 @@ import { hostMetaController } from '@/controllers/well-known/host-meta.ts';
import { nodeInfoController, nodeInfoSchemaController } from '@/controllers/well-known/nodeinfo.ts'; import { nodeInfoController, nodeInfoSchemaController } from '@/controllers/well-known/nodeinfo.ts';
import { nostrController } from '@/controllers/well-known/nostr.ts'; import { nostrController } from '@/controllers/well-known/nostr.ts';
import { webfingerController } from '@/controllers/well-known/webfinger.ts'; import { webfingerController } from '@/controllers/well-known/webfinger.ts';
import { auth98, requireProof, requireRole } from '@/middleware/auth98.ts'; import { auth98Middleware, requireProof, requireRole } from '@/middleware/auth98Middleware.ts';
import { cache } from '@/middleware/cache.ts'; import { cacheMiddleware } from '@/middleware/cacheMiddleware.ts';
import { csp } from '@/middleware/csp.ts'; import { cspMiddleware } from '@/middleware/cspMiddleware.ts';
import { requireSigner } from '@/middleware/requireSigner.ts'; import { requireSigner } from '@/middleware/requireSigner.ts';
import { signerMiddleware } from '@/middleware/signerMiddleware.ts'; import { signerMiddleware } from '@/middleware/signerMiddleware.ts';
import { storeMiddleware } from '@/middleware/store.ts'; import { storeMiddleware } from '@/middleware/storeMiddleware.ts';
import { blockController } from '@/controllers/api/accounts.ts'; import { blockController } from '@/controllers/api/accounts.ts';
import { unblockController } from '@/controllers/api/accounts.ts'; import { unblockController } from '@/controllers/api/accounts.ts';
@ -124,10 +124,10 @@ app.get('/relay', relayController);
app.use( app.use(
'*', '*',
csp(), cspMiddleware(),
cors({ origin: '*', exposeHeaders: ['link'] }), cors({ origin: '*', exposeHeaders: ['link'] }),
signerMiddleware, signerMiddleware,
auth98(), auth98Middleware(),
storeMiddleware, storeMiddleware,
); );
@ -140,7 +140,7 @@ app.get('/users/:username', actorController);
app.get('/nodeinfo/:version', nodeInfoSchemaController); app.get('/nodeinfo/:version', nodeInfoSchemaController);
app.get('/api/v1/instance', cache({ cacheName: 'web', expires: Time.minutes(5) }), instanceController); app.get('/api/v1/instance', cacheMiddleware({ cacheName: 'web', expires: Time.minutes(5) }), instanceController);
app.get('/api/v1/apps/verify_credentials', appCredentialsController); app.get('/api/v1/apps/verify_credentials', appCredentialsController);
app.post('/api/v1/apps', createAppController); app.post('/api/v1/apps', createAppController);
@ -195,8 +195,12 @@ app.get('/api/v2/search', searchController);
app.get('/api/pleroma/frontend_configurations', frontendConfigController); app.get('/api/pleroma/frontend_configurations', frontendConfigController);
app.get('/api/v1/trends/tags', cache({ cacheName: 'web', expires: Time.minutes(15) }), trendingTagsController); app.get(
app.get('/api/v1/trends', cache({ cacheName: 'web', expires: Time.minutes(15) }), trendingTagsController); '/api/v1/trends/tags',
cacheMiddleware({ cacheName: 'web', expires: Time.minutes(15) }),
trendingTagsController,
);
app.get('/api/v1/trends', cacheMiddleware({ cacheName: 'web', expires: Time.minutes(15) }), trendingTagsController);
app.get('/api/v1/suggestions', suggestionsV1Controller); app.get('/api/v1/suggestions', suggestionsV1Controller);
app.get('/api/v2/suggestions', suggestionsV2Controller); app.get('/api/v2/suggestions', suggestionsV2Controller);

View File

@ -16,7 +16,7 @@ import {
* NIP-98 auth. * NIP-98 auth.
* https://github.com/nostr-protocol/nips/blob/master/98.md * https://github.com/nostr-protocol/nips/blob/master/98.md
*/ */
function auth98(opts: ParseAuthRequestOpts = {}): AppMiddleware { function auth98Middleware(opts: ParseAuthRequestOpts = {}): AppMiddleware {
return async (c, next) => { return async (c, next) => {
const req = localRequest(c); const req = localRequest(c);
const result = await parseAuthRequest(req, opts); const result = await parseAuthRequest(req, opts);
@ -108,4 +108,4 @@ async function obtainProof(c: AppContext, opts?: ParseAuthRequestOpts) {
} }
} }
export { auth98, requireProof, requireRole }; export { auth98Middleware, requireProof, requireRole };

View File

@ -5,7 +5,7 @@ import ExpiringCache from '@/utils/expiring-cache.ts';
const debug = Debug('ditto:middleware:cache'); const debug = Debug('ditto:middleware:cache');
export const cache = (options: { export const cacheMiddleware = (options: {
cacheName: string; cacheName: string;
expires?: number; expires?: number;
}): MiddlewareHandler => { }): MiddlewareHandler => {

View File

@ -1,7 +1,7 @@
import { AppMiddleware } from '@/app.ts'; import { AppMiddleware } from '@/app.ts';
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
const csp = (): AppMiddleware => { export const cspMiddleware = (): AppMiddleware => {
return async (c, next) => { return async (c, next) => {
const { host, protocol, origin } = Conf.url; const { host, protocol, origin } = Conf.url;
const wsProtocol = protocol === 'http:' ? 'ws:' : 'wss:'; const wsProtocol = protocol === 'http:' ? 'ws:' : 'wss:';
@ -26,5 +26,3 @@ const csp = (): AppMiddleware => {
await next(); await next();
}; };
}; };
export { csp };

View File

@ -3,7 +3,7 @@ import { UserStore } from '@/storages/UserStore.ts';
import { Storages } from '@/storages.ts'; import { Storages } from '@/storages.ts';
/** Store middleware. */ /** Store middleware. */
const storeMiddleware: AppMiddleware = async (c, next) => { export const storeMiddleware: AppMiddleware = async (c, next) => {
const pubkey = await c.get('signer')?.getPublicKey(); const pubkey = await c.get('signer')?.getPublicKey();
if (pubkey) { if (pubkey) {
@ -14,5 +14,3 @@ const storeMiddleware: AppMiddleware = async (c, next) => {
} }
await next(); await next();
}; };
export { storeMiddleware };