• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / storage / 26213785588

21 May 2026 08:08AM UTC coverage: 40.286% (-34.7%) from 74.992%
26213785588

Pull #1118

github

web-flow
Merge fcbe53820 into 322ab2ebb
Pull Request #1118: fix: single callback for memory collector

2182 of 5969 branches covered (36.56%)

Branch coverage included in aggregate %.

15 of 15 new or added lines in 2 files covered. (100.0%)

3727 existing lines in 166 files now uncovered.

4335 of 10208 relevant lines covered (42.47%)

35.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

10.0
/src/http/routes/object/getObject.ts
1
import { ERRORS } from '@internal/errors'
2
import { Obj } from '@storage/schemas'
3
import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'
4
import { FromSchema } from 'json-schema-to-ts'
5
import { getConfig } from '../../../config'
6
import { AuthenticatedRangeRequest } from '../../types'
7
import { ROUTE_OPERATIONS } from '../operations'
8

9
const { storageS3Bucket } = getConfig()
2✔
10

11
const getObjectParamsSchema = {
2✔
12
  type: 'object',
13
  properties: {
14
    bucketName: { type: 'string', examples: ['avatars'] },
15
    '*': { type: 'string', examples: ['folder/cat.png'] },
16
  },
17
  required: ['bucketName', '*'],
18
} as const
19

20
const getObjectQuerySchema = {
2✔
21
  type: 'object',
22
  properties: {
23
    download: { type: 'string', examples: ['filename.jpg', null] },
24
  },
25
} as const
26

27
interface getObjectRequestInterface extends AuthenticatedRangeRequest {
28
  Params: FromSchema<typeof getObjectParamsSchema>
29
  Querystring: FromSchema<typeof getObjectQuerySchema>
30
}
31

32
type GetObjectRequest = FastifyRequest<getObjectRequestInterface>
33

34
async function requestHandler(request: GetObjectRequest, response: FastifyReply) {
UNCOV
35
  const { bucketName } = request.params
×
UNCOV
36
  const { download } = request.query
×
UNCOV
37
  const objectName = request.params['*']
×
38

39
  // send the object from s3
UNCOV
40
  const s3Key = request.storage.location.getKeyLocation({
×
41
    tenantId: request.tenantId,
42
    bucketId: bucketName,
43
    objectName,
44
  })
UNCOV
45
  const bucket = await request.storage.asSuperUser().findBucket(bucketName, 'id,public', {
×
46
    dontErrorOnEmpty: true,
47
  })
48

49
  // The request is not authenticated
UNCOV
50
  if (!request.isAuthenticated) {
×
51
    // The bucket must be public to access its content
UNCOV
52
    if (!bucket?.public) {
×
UNCOV
53
      throw ERRORS.NoSuchBucket(bucketName)
×
54
    }
55
  }
56

57
  // The request is authenticated
UNCOV
58
  if (!bucket) {
×
UNCOV
59
    throw ERRORS.NoSuchBucket(bucketName)
×
60
  }
61

62
  let obj: Obj | undefined
63

UNCOV
64
  if (bucket.public) {
×
65
    // request is authenticated but we still use the superUser as we don't need to check RLS
66
    obj = await request.storage
×
67
      .asSuperUser()
68
      .from(bucketName)
69
      .findObject(objectName, 'id, version, metadata')
70
  } else {
71
    // request is authenticated use RLS
UNCOV
72
    obj = await request.storage.from(bucketName).findObject(objectName, 'id, version, metadata')
×
73
  }
74

UNCOV
75
  return request.storage.renderer('asset').render(request, response, {
×
76
    bucket: storageS3Bucket,
77
    key: s3Key,
78
    version: obj.version,
79
    download,
80
    xRobotsTag: obj.metadata?.['xRobotsTag'] as string | undefined,
81
    signal: request.signals.disconnect.signal,
82
  })
83
}
84

85
export default async function routes(fastify: FastifyInstance) {
UNCOV
86
  const summary = 'Retrieve an object'
×
UNCOV
87
  fastify.get<getObjectRequestInterface>(
×
88
    '/authenticated/:bucketName/*',
89
    {
90
      exposeHeadRoute: false,
91
      // @todo add success response schema here
92
      schema: {
93
        params: getObjectParamsSchema,
94
        querystring: getObjectQuerySchema,
95
        headers: { $ref: 'authSchema#' },
96
        summary,
97
        response: { '4xx': { $ref: 'errorSchema#', description: 'Error response' } },
98
        tags: ['object'],
99
      },
100
      config: {
101
        operation: { type: ROUTE_OPERATIONS.GET_AUTH_OBJECT },
102
      },
103
    },
104
    async (request, response) => {
UNCOV
105
      return requestHandler(request, response)
×
106
    }
107
  )
108

UNCOV
109
  fastify.get<getObjectRequestInterface>(
×
110
    '/:bucketName/*',
111
    {
112
      exposeHeadRoute: false,
113
      // @todo add success response schema here
114
      schema: {
115
        params: getObjectParamsSchema,
116
        summary: 'Get object',
117
        description: 'Serve objects',
118
        tags: ['object'],
119
        response: { '4xx': { $ref: 'errorSchema#' } },
120
      },
121
      config: {
122
        operation: { type: ROUTE_OPERATIONS.GET_AUTH_OBJECT },
123
        allowInvalidJwt: true,
124
      },
125
    },
126
    async (request, response) => {
UNCOV
127
      return requestHandler(request, response)
×
128
    }
129
  )
130
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc