bde148f286
* wip * some extra fixes * stuff kinda works? * need to figure out mocks * need to figure out mocks * fix db listener * gqlgen fix * minor gqlgen watch adjustment * lint fixes * delete old codegen file * converting migrations to ESM * getModuleDIrectory * vitest sort of works * added back ts-vitest * resolve gql double load * fixing test timeout configs * TSC lint fix * fix automate tests * moar debugging * debugging * more debugging * codegen update * server works * yargs migrated * chore(server): getting rid of global mocks for Server ESM (#5046) * got rid of email mock * got rid of comment mocks * got rid of multi region mocks * got rid of stripe mock * admin override mock updated * removed final mock * fixing import.meta.resolve calls * another import.meta.resolve fix * added requested test * nyc ESM fix * removed unneeded deps + linting * yarn lock forgot to commit * tryna fix flakyness * email capture util fix * sendEmail fix * fix TSX check * sender transporter fix + CR comments * merge main fix * test fixx * circleci fix * gqlgen bigint fix * error formatter fix * more error formatting improvements * esmloader added to Dockerfile * more dockerfile fixes * bg jobs fix
87 lines
2.2 KiB
TypeScript
87 lines
2.2 KiB
TypeScript
import {
|
|
blobCollectionSummaryFactory,
|
|
getBlobMetadataCollectionFactory,
|
|
getBlobMetadataFactory
|
|
} from '@/modules/blobstorage/repositories'
|
|
import { getFileSizeLimit } from '@/modules/blobstorage/services/management'
|
|
import {
|
|
ProjectBlobArgs,
|
|
ProjectBlobsArgs,
|
|
Resolvers,
|
|
StreamBlobArgs,
|
|
StreamBlobsArgs
|
|
} from '@/modules/core/graph/generated/graphql'
|
|
import { StreamGraphQLReturn } from '@/modules/core/helpers/graphTypes'
|
|
import { getProjectDbClient } from '@/modules/multiregion/utils/dbSelector'
|
|
import {
|
|
BadRequestError,
|
|
NotFoundError,
|
|
ResourceMismatch
|
|
} from '@/modules/shared/errors'
|
|
|
|
const streamBlobResolvers = {
|
|
async blobs(parent: StreamGraphQLReturn, args: StreamBlobsArgs | ProjectBlobsArgs) {
|
|
const streamId = parent.id
|
|
|
|
const projectDb = await getProjectDbClient({ projectId: parent.id })
|
|
|
|
const blobCollectionSummary = blobCollectionSummaryFactory({ db: projectDb })
|
|
const getBlobMetadataCollection = getBlobMetadataCollectionFactory({
|
|
db: projectDb
|
|
})
|
|
|
|
const [summary, blobs] = await Promise.all([
|
|
blobCollectionSummary({
|
|
streamId,
|
|
query: args.query
|
|
}),
|
|
getBlobMetadataCollection({
|
|
streamId,
|
|
query: args.query,
|
|
limit: args.limit,
|
|
cursor: args.cursor
|
|
})
|
|
])
|
|
return {
|
|
totalCount: summary.totalCount,
|
|
totalSize: summary.totalSize,
|
|
cursor: blobs.cursor,
|
|
items: blobs.blobs
|
|
}
|
|
},
|
|
async blob(parent: StreamGraphQLReturn, args: StreamBlobArgs | ProjectBlobArgs) {
|
|
const projectDb = await getProjectDbClient({ projectId: parent.id })
|
|
const getBlobMetadata = getBlobMetadataFactory({ db: projectDb })
|
|
try {
|
|
return await getBlobMetadata({
|
|
streamId: parent.id,
|
|
blobId: args.id
|
|
})
|
|
} catch (err: unknown) {
|
|
if (err instanceof NotFoundError) return null
|
|
if (err instanceof ResourceMismatch) throw new BadRequestError(err.message)
|
|
throw err
|
|
}
|
|
}
|
|
}
|
|
|
|
export default {
|
|
ServerInfo: {
|
|
//deprecated
|
|
blobSizeLimitBytes() {
|
|
return getFileSizeLimit()
|
|
}
|
|
},
|
|
ServerConfiguration: {
|
|
blobSizeLimitBytes() {
|
|
return getFileSizeLimit()
|
|
}
|
|
},
|
|
Stream: {
|
|
...streamBlobResolvers
|
|
},
|
|
Project: {
|
|
...streamBlobResolvers
|
|
}
|
|
} as Resolvers
|