api: provide one S3 client from a global S3Module 9ade0ad5 days ago 60 lines · 2.7 KB 1 import { Module } from ' @nestjs/common ' ; 2 import { ThrottlerModule } 3 import type { Request 4 import { 5 rateLimitPerMinute , 6 rateLimitTracker , 7 } from ' ../../lib/http/rate-limit.js ' ; 8 import { RepositoriesService } 9 import { RepositoriesController } 10 import { SearchController } 11 import { TransfersController } 12 import { UsersService } 13 import { RepositoryStorageService } 14 import { MaterializerModule } 15 import { RepositoryPathIndexService } 16 import { RepositoryLanguageService } 17 import { WalStoreService } 18 import { StorageModule } 19 import { RepositoryAccessService } 20 import { RepositoryContributionService } 21 import { CommitSigningService } 22 import { CommitVerificationService } 23 import { CodeSearchService } 24 import { LfsService } 25 26 @ Module ( { 27 imports : [ 28 StorageModule , 29 MaterializerModule , 30 // Only code search is guarded: it is the one endpoint whose cost a query string decides. Counters live in this process, so with N replicas a client gets N times the limit. 31 ThrottlerModule . forRoot ( { 32 throttlers : [ 33 { 34 ttl : 60_000 , 35 limit : ( context ) 36 rateLimitPerMinute ( context . switchToHttp 37 } , 38 ] , 39 getTracker : ( request ) 40 errorMessage : ' Too many searches. Try again in a minute. ' , 41 } ) , 42 ] , 43 controllers : [ RepositoriesController , 44 providers : [ 45 RepositoriesService , 46 UsersService , 47 RepositoryStorageService , 48 CodeSearchService , 49 RepositoryPathIndexService , 50 RepositoryLanguageService , 51 WalStoreService , 52 RepositoryAccessService , 53 RepositoryContributionService , 54 CommitSigningService , 55 CommitVerificationService , 56 LfsService , 57 ] , 58 exports : [ RepositoriesService ] , 59 } ) 60 export class RepositoriesModule
from
'
@nestjs/throttler
'
;
}
from
'
express
'
;
from
'
./repositories.service.js
'
;
from
'
./repositories.controller.js
'
;
from
'
./search.controller.js
'
;
from
'
./transfers.controller.js
'
;
from
'
../../services/users/users.service.js
'
;
from
'
../../services/git/repository-storage/repository-storage.service.js
'
;
from
'
../../materializer/materializer.module.js
'
;
from
'
../../services/git/path-index/repository-path-index.service.js
'
;
from
'
../../services/git/languages/repository-language.service.js
'
;
from
'
../../services/git/wal/wal-store.service.js
'
;
from
'
../storage/storage.module.js
'
;
from
'
../../services/git/repository-access/repository-access.service.js
'
;
from
'
../../services/git/contributions/repository-contribution.service.js
'
;
from
'
../../services/gpg/commit-signing.service.js
'
;
from
'
../../services/gpg/commit-verification.service.js
'
;
from
'
../../services/git/code-search/code-search.service.js
'
;
from
'
../../services/git/lfs/lfs.service.js
'
;
=>
()
.
getRequest
())
,
=>
rateLimitTracker
(
request
as
Request
)
,
SearchController
,
TransfersController
]
,
{}