Skip to content

Commit

Permalink
Merge pull request supabase#14252 from supabase/fix/storage-bucket-se…
Browse files Browse the repository at this point in the history
…ttings-self-hosted

fix: storage bucket settings in self-hosted
  • Loading branch information
alaister authored May 10, 2023
2 parents ece7143 + a22324f commit eecc0b3
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 60 deletions.
64 changes: 32 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 15 additions & 12 deletions studio/components/interfaces/Storage/CreateBucketModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from 'components/to-be-cleaned/Storage/StorageSettings/StorageSettings.utils'
import { useStore } from 'hooks'
import { useParams } from 'common'
import { IS_PLATFORM } from 'lib/constants'
import { useProjectStorageConfigQuery } from 'data/config/project-storage-config-query'
import { useRouter } from 'next/router'

Expand All @@ -36,7 +37,7 @@ const CreateBucketModal = ({ visible, onClose }: CreateBucketModalProps) => {
const storageExplorerStore = useStorageStore()
const { createBucket } = storageExplorerStore

const { data } = useProjectStorageConfigQuery({ projectRef: ref })
const { data } = useProjectStorageConfigQuery({ projectRef: ref }, { enabled: IS_PLATFORM })
const { value, unit } = convertFromBytes(data?.fileSizeLimit ?? 0)
const formattedGlobalUploadLimit = `${value} ${unit}`

Expand Down Expand Up @@ -203,17 +204,19 @@ const CreateBucketModal = ({ visible, onClose }: CreateBucketModalProps) => {
))}
</Listbox>
</div>
<div className="col-span-12">
<p className="text-scale-1000 text-sm">
Note: The{' '}
<Link href={`/project/${ref}/settings/storage`}>
<a className="text-brand-900 opacity-80 hover:opacity-100 transition">
global upload limit
</a>
</Link>{' '}
takes precedence over this value ({formattedGlobalUploadLimit})
</p>
</div>
{IS_PLATFORM && (
<div className="col-span-12">
<p className="text-scale-1000 text-sm">
Note: The{' '}
<Link href={`/project/${ref}/settings/storage`}>
<a className="text-brand-900 opacity-80 hover:opacity-100 transition">
global upload limit
</a>
</Link>{' '}
takes precedence over this value ({formattedGlobalUploadLimit})
</p>
</div>
)}
</div>
)}
</div>
Expand Down
27 changes: 15 additions & 12 deletions studio/components/interfaces/Storage/EditBucketModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import { useStore } from 'hooks'
import { useParams } from 'common'
import { useProjectStorageConfigQuery } from 'data/config/project-storage-config-query'
import { IS_PLATFORM } from 'lib/constants'

export interface EditBucketModalProps {
visible: boolean
Expand All @@ -35,7 +36,7 @@ const EditBucketModal = ({ visible, bucket, onClose }: EditBucketModalProps) =>
const storageExplorerStore = useStorageStore()
const { editBucket } = storageExplorerStore

const { data } = useProjectStorageConfigQuery({ projectRef: ref })
const { data } = useProjectStorageConfigQuery({ projectRef: ref }, { enabled: IS_PLATFORM })
const { value, unit } = convertFromBytes(data?.fileSizeLimit ?? 0)
const formattedGlobalUploadLimit = `${value} ${unit}`

Expand Down Expand Up @@ -226,17 +227,19 @@ const EditBucketModal = ({ visible, bucket, onClose }: EditBucketModalProps) =>
))}
</Listbox>
</div>
<div className="col-span-12">
<p className="text-scale-1000 text-sm">
Note: The{' '}
<Link href={`/project/${ref}/settings/storage`}>
<a className="text-brand-900 opacity-80 hover:opacity-100 transition">
global upload limit
</a>
</Link>{' '}
takes precedence over this value ({formattedGlobalUploadLimit})
</p>
</div>
{IS_PLATFORM && (
<div className="col-span-12">
<p className="text-scale-1000 text-sm">
Note: The{' '}
<Link href={`/project/${ref}/settings/storage`}>
<a className="text-brand-900 opacity-80 hover:opacity-100 transition">
global upload limit
</a>
</Link>{' '}
takes precedence over this value ({formattedGlobalUploadLimit})
</p>
</div>
)}
</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState } from 'react'
import * as Tooltip from '@radix-ui/react-tooltip'
import { Button, Form, IconClock, Input, Listbox } from 'ui'

import { checkPermissions, useStore } from 'hooks'
import { IS_PLATFORM } from 'lib/constants'
import { useProjectStorageConfigQuery } from 'data/config/project-storage-config-query'
import { useProjectStorageConfigUpdateUpdateMutation } from 'data/config/project-storage-config-update-mutation'
import UpgradeToPro from 'components/ui/UpgradeToPro'
Expand All @@ -15,7 +15,7 @@ export type StorageSettingsProps = {
}

const StorageSettings = ({ projectRef }: StorageSettingsProps) => {
const { data, error } = useProjectStorageConfigQuery({ projectRef })
const { data, error } = useProjectStorageConfigQuery({ projectRef }, { enabled: IS_PLATFORM })

if (error || data?.error) {
return (
Expand Down
2 changes: 1 addition & 1 deletion studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@supabase/auth-helpers-react": "^0.3.1",
"@supabase/react-data-grid": "^7.1.0-beta.7",
"@supabase/shared-types": "^0.1.40",
"@supabase/supabase-js": "^2.13.0",
"@supabase/supabase-js": "^2.21.0",
"@tanstack/react-query": "^4.22.0",
"@tanstack/react-query-devtools": "^4.22.0",
"@zip.js/zip.js": "^2.6.61",
Expand Down
8 changes: 7 additions & 1 deletion studio/pages/api/storage/[ref]/buckets/[id]/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {

const handlePatch = async (req: NextApiRequest, res: NextApiResponse) => {
const { id } = req.query
const { public: isPublicBucket } = req.body
const {
public: isPublicBucket,
allowed_mime_types: allowedMimeTypes,
file_size_limit: fileSizeLimit,
} = req.body

const { data, error } = await supabase.storage.updateBucket(id as string, {
public: isPublicBucket,
allowedMimeTypes,
fileSizeLimit,
})
if (error) {
return res.status(400).json({ error: { message: error.message } })
Expand Down

0 comments on commit eecc0b3

Please sign in to comment.