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

supabase / storage / 22763435164

06 Mar 2026 12:27PM UTC coverage: 76.221% (+0.1%) from 76.093%
22763435164

push

github

web-flow
fix: improve biome lint configuration (#892)

Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>

3992 of 5697 branches covered (70.07%)

Branch coverage included in aggregate %.

46 of 69 new or added lines in 12 files covered. (66.67%)

76 existing lines in 8 files now uncovered.

26757 of 34645 relevant lines covered (77.23%)

187.37 hits per line

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

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

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

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

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

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

2✔
32
type GetObjectRequest = FastifyRequest<getObjectRequestInterface>
2✔
33

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

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

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

26✔
57
  // The request is authenticated
26✔
58
  if (!bucket) {
28✔
59
    throw ERRORS.NoSuchBucket(bucketName)
2✔
60
  }
2✔
61

24✔
62
  let obj: Obj | undefined
24✔
63

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

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

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

262✔
109
  fastify.get<getObjectRequestInterface>(
262✔
110
    '/:bucketName/*',
262✔
111
    {
262✔
112
      exposeHeadRoute: false,
262✔
113
      // @todo add success response schema here
262✔
114
      schema: {
262✔
115
        params: getObjectParamsSchema,
262✔
116
        summary: 'Get object',
262✔
117
        description: 'Serve objects',
262✔
118
        tags: ['object'],
262✔
119
        response: { '4xx': { $ref: 'errorSchema#' } },
262✔
120
      },
262✔
121
      config: {
262✔
122
        operation: { type: ROUTE_OPERATIONS.GET_AUTH_OBJECT },
262✔
123
        allowInvalidJwt: true,
262✔
124
      },
262✔
125
    },
262✔
126
    async (request, response) => {
262✔
127
      return requestHandler(request, response)
6✔
128
    }
6✔
129
  )
262✔
130
}
262✔
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