Bucket.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { useParams } from 'common'
  2. import { Badge } from 'ui'
  3. import { DOCS_RESOURCE_CONTENT } from '../ProjectAPIDocs.constants'
  4. import ResourceContent from '../ResourceContent'
  5. import type { ContentProps } from './Content.types'
  6. import { useBucketInfoQueryPreferCached } from '@/data/storage/buckets-query'
  7. import { formatBytes } from '@/lib/helpers'
  8. import { useAppStateSnapshot } from '@/state/app-state'
  9. export const Bucket = ({ language, apikey, endpoint }: ContentProps) => {
  10. const { ref } = useParams()
  11. const snap = useAppStateSnapshot()
  12. const resource = snap.activeDocsSection[1]
  13. const bucket = useBucketInfoQueryPreferCached(resource, ref)
  14. const allowedMimeTypes = bucket?.allowed_mime_types
  15. const maxFileSizeLimit = bucket?.file_size_limit
  16. if (bucket === undefined) return null
  17. return (
  18. <div className="divide-y">
  19. <div className="space-y-1 px-4 py-4">
  20. <div className="flex items-center space-x-2">
  21. <h2>{bucket.name}</h2>
  22. <Badge variant={bucket.public ? 'warning' : 'default'}>
  23. {bucket.public ? 'Public' : 'Private'}
  24. </Badge>
  25. </div>
  26. <p className="text-sm text-foreground-light">
  27. Allowed MIME types:{' '}
  28. {allowedMimeTypes === null
  29. ? 'All types are allowed'
  30. : (allowedMimeTypes ?? []).length === 0
  31. ? 'No types are allowed'
  32. : (allowedMimeTypes ?? []).length > 1
  33. ? (allowedMimeTypes ?? []).join(', ')
  34. : 'Unknown'}
  35. </p>
  36. <p className="text-sm text-foreground-light">
  37. Max file size limit:{' '}
  38. {maxFileSizeLimit === null ? 'No limit' : `${formatBytes(maxFileSizeLimit)}`}
  39. </p>
  40. </div>
  41. <ResourceContent
  42. selectedLanguage={language}
  43. snippet={DOCS_RESOURCE_CONTENT.uploadFile}
  44. codeSnippets={DOCS_RESOURCE_CONTENT.uploadFile.code({
  45. name: resource,
  46. apikey,
  47. endpoint,
  48. })}
  49. />
  50. <ResourceContent
  51. selectedLanguage={language}
  52. snippet={DOCS_RESOURCE_CONTENT.deleteFiles}
  53. codeSnippets={DOCS_RESOURCE_CONTENT.deleteFiles.code({
  54. name: resource,
  55. apikey,
  56. endpoint,
  57. })}
  58. />
  59. <ResourceContent
  60. selectedLanguage={language}
  61. snippet={DOCS_RESOURCE_CONTENT.listFiles}
  62. codeSnippets={DOCS_RESOURCE_CONTENT.listFiles.code({
  63. name: resource,
  64. apikey,
  65. endpoint,
  66. })}
  67. />
  68. <ResourceContent
  69. selectedLanguage={language}
  70. snippet={DOCS_RESOURCE_CONTENT.downloadFile}
  71. codeSnippets={DOCS_RESOURCE_CONTENT.downloadFile.code({
  72. name: resource,
  73. apikey,
  74. endpoint,
  75. })}
  76. />
  77. {bucket.public ? (
  78. <ResourceContent
  79. selectedLanguage={language}
  80. snippet={DOCS_RESOURCE_CONTENT.retrievePublicURL}
  81. codeSnippets={DOCS_RESOURCE_CONTENT.retrievePublicURL.code({
  82. name: resource,
  83. apikey,
  84. endpoint,
  85. })}
  86. />
  87. ) : (
  88. <ResourceContent
  89. selectedLanguage={language}
  90. snippet={DOCS_RESOURCE_CONTENT.createSignedURL}
  91. codeSnippets={DOCS_RESOURCE_CONTENT.createSignedURL.code({
  92. name: resource,
  93. apikey,
  94. endpoint,
  95. })}
  96. />
  97. )}
  98. </div>
  99. )
  100. }