From 615b35ed0e0b0fd3bee909b42d71c31376218399 Mon Sep 17 00:00:00 2001 From: andresgutgon Date: Mon, 9 Sep 2024 18:37:39 +0200 Subject: [PATCH] Make Upload to S3 bucket work --- apps/web/package.json | 4 +-- .../_components/PreviewDatasetModal/index.tsx | 4 ++- packages/core/src/lib/debug.ts | 3 ++ packages/core/src/lib/disk.ts | 31 +++---------------- .../src/ds/molecules/TableSkeleton/index.tsx | 12 +++++-- 5 files changed, 23 insertions(+), 31 deletions(-) create mode 100644 packages/core/src/lib/debug.ts diff --git a/apps/web/package.json b/apps/web/package.json index cd91c57ca..656fff93f 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -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}\"", diff --git a/apps/web/src/app/(private)/datasets/_components/PreviewDatasetModal/index.tsx b/apps/web/src/app/(private)/datasets/_components/PreviewDatasetModal/index.tsx index 11b3d476a..e1b59e8b0 100644 --- a/apps/web/src/app/(private)/datasets/_components/PreviewDatasetModal/index.tsx +++ b/apps/web/src/app/(private)/datasets/_components/PreviewDatasetModal/index.tsx @@ -19,6 +19,7 @@ import { import useDatasetPreview from '$/stores/datasetPreviews' const VISIBLE_ROWS = 20 +const TABLE_MAX_HEIGHT = 450 function PreviewModal({ dataset, setPreview, @@ -46,11 +47,12 @@ function PreviewModal({ > {isLoading ? ( ) : ( - +
diff --git a/packages/core/src/lib/debug.ts b/packages/core/src/lib/debug.ts new file mode 100644 index 000000000..5e2be8240 --- /dev/null +++ b/packages/core/src/lib/debug.ts @@ -0,0 +1,3 @@ +import { debuglog } from 'node:util' + +export default debuglog('latitude:debug') diff --git a/packages/core/src/lib/disk.ts b/packages/core/src/lib/disk.ts index 2dc78b257..f4140686d 100644 --- a/packages/core/src/lib/disk.ts +++ b/packages/core/src/lib/disk.ts @@ -1,7 +1,5 @@ -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' @@ -9,8 +7,6 @@ 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}` @@ -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) } @@ -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) { @@ -143,6 +121,7 @@ export class DiskWrapper { credentials: awsConfig.credentials, region: awsConfig.region, bucket: awsConfig.bucket, + supportsACL: false, visibility: 'private', }) } diff --git a/packages/web-ui/src/ds/molecules/TableSkeleton/index.tsx b/packages/web-ui/src/ds/molecules/TableSkeleton/index.tsx index 95c59cf3b..9df88e4ff 100644 --- a/packages/web-ui/src/ds/molecules/TableSkeleton/index.tsx +++ b/packages/web-ui/src/ds/molecules/TableSkeleton/index.tsx @@ -11,7 +11,15 @@ 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()) @@ -19,7 +27,7 @@ export function TableSkeleton({ rows, cols }: { rows: number; cols: number }) { return { data, headers } }, [rows, cols]) return ( -
+
{headers.map((header) => (