Skip to content

Commit

Permalink
Make Upload to S3 bucket work
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutgon committed Sep 10, 2024
1 parent 2c684ed commit 615b35e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 31 deletions.
4 changes: 2 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"private": true,
"scripts": {
"build": "next build",
"dev": "next dev",
"dev:debug": "NODE_DEBUG=flydrive:s3 NODE_OPTIONS='--inspect=0.0.0.0:9229' ./node_modules/.bin/next dev",
"dev": "NODE_DEBUG=latitude:debug next dev",
"dev:debug": "NODE_DEBUG=latitude:debug NODE_OPTIONS='--inspect=0.0.0.0:9229' ./node_modules/.bin/next dev",
"dev:local": "USE_LOCALHOST=true pnpm run dev",
"lint": "next lint",
"prettier": "prettier --write \"**/*.{ts,tsx,md}\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import useDatasetPreview from '$/stores/datasetPreviews'

const VISIBLE_ROWS = 20
const TABLE_MAX_HEIGHT = 450
function PreviewModal({
dataset,
setPreview,
Expand Down Expand Up @@ -46,11 +47,12 @@ function PreviewModal({
>
{isLoading ? (
<TableSkeleton
maxHeight={TABLE_MAX_HEIGHT}
rows={rowCount}
cols={dataset.fileMetadata.headers.length}
/>
) : (
<Table maxHeight={450}>
<Table maxHeight={TABLE_MAX_HEIGHT}>
<TableHeader>
<TableRow verticalPadding>
<TableHead>
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/lib/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { debuglog } from 'node:util'

export default debuglog('latitude:debug')
31 changes: 5 additions & 26 deletions packages/core/src/lib/disk.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { debuglog } from 'node:util'
import { Readable } from 'stream'

import { HeadBucketCommand, S3Client } from '@aws-sdk/client-s3'
import { Result } from '@latitude-data/core/lib/Result'
import { env } from '@latitude-data/env'
import { Disk, errors } from 'flydrive'
import { FSDriver } from 'flydrive/drivers/fs'
import { S3Driver } from 'flydrive/drivers/s3'
import { WriteOptions } from 'flydrive/types'

var debug_default = debuglog('flydrive:s3')

const generateUrl = (publicPath: string) => async (key: string) =>
`/${publicPath}/${key}`

Expand Down Expand Up @@ -57,27 +53,6 @@ export class DiskWrapper {
this.disk = new Disk(this.buildDisk(args))
}

async pingBucket() {
const bucket = env.S3_BUCKET
debug_default('pinging bucket %s', bucket)
const awsConfig = getAwsConfig()
const client = new S3Client({
credentials: awsConfig.credentials,
region: awsConfig.region,
})
const input = {
Bucket: env.S3_BUCKET,
ExpectedBucketOwner: 'TODO_FIND_ID',
}
const command = new HeadBucketCommand(input)
try {
await client.send(command)
} catch (error) {
debug_default('error pinging bucket %s', bucket)
debug_default('error pinging bucket %s', error)
}
}

file(key: string) {
return this.disk.file(key)
}
Expand All @@ -95,7 +70,10 @@ export class DiskWrapper {

async putStream(key: string, contents: Readable, options?: WriteOptions) {
try {
await this.disk.putStream(key, contents, options)
await this.disk.putStream(key, contents, {
...options,
contentLength: contents.readableLength,
})
return Result.nil()
} catch (e) {
if (e instanceof errors.E_CANNOT_WRITE_FILE) {
Expand Down Expand Up @@ -143,6 +121,7 @@ export class DiskWrapper {
credentials: awsConfig.credentials,
region: awsConfig.region,
bucket: awsConfig.bucket,
supportsACL: false,
visibility: 'private',
})
}
Expand Down
12 changes: 10 additions & 2 deletions packages/web-ui/src/ds/molecules/TableSkeleton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ import {
} from '../../atoms/Table'
import Text from '../../atoms/Text'

export function TableSkeleton({ rows, cols }: { rows: number; cols: number }) {
export function TableSkeleton({
rows,
cols,
maxHeight,
}: {
rows: number
cols: number
maxHeight?: number
}) {
const { data, headers } = useMemo(() => {
const rowList = Array.from(Array(rows).keys())
const headers = Array.from(Array(cols).keys())
const data = rowList.map((_) => headers)
return { data, headers }
}, [rows, cols])
return (
<Table>
<Table maxHeight={maxHeight}>
<TableHeader>
<TableRow>
{headers.map((header) => (
Expand Down

0 comments on commit 615b35e

Please sign in to comment.