diff --git a/packages/core/src/lib/disk.ts b/packages/core/src/lib/disk.ts index 90dc0a2a1..c45f74b65 100644 --- a/packages/core/src/lib/disk.ts +++ b/packages/core/src/lib/disk.ts @@ -1,11 +1,5 @@ -import { debuglog } from 'node:util' import { Readable } from 'stream' -import { - HeadBucketCommand, - PutObjectCommand, - 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' @@ -13,30 +7,9 @@ import { FSDriver } from 'flydrive/drivers/fs' import { S3Driver } from 'flydrive/drivers/s3' import { WriteOptions } from 'flydrive/types' -var debug_default = debuglog('latitude:debug') - const generateUrl = (publicPath: string) => async (key: string) => `/${publicPath}/${key}` -function logRequestMiddleware() { - // @ts-ignore - const logRequestMiddleware = (next, _context) => async (args) => { - debug_default('Request: %O', JSON.stringify(args.request.headers)) - - return next(args) - } - - // @ts-ignore - logRequestMiddleware.applyToStack = (clientStack) => { - clientStack.add(logRequestMiddleware, { - step: 'finalizeRequest', // use 'serialize' step for v3 of aws-sdk - name: 'logRequestMiddleware', - priority: 'high', // Ensure this middleware is run first - }) - } - - return logRequestMiddleware -} /** * These env variables are set in production. * If you want to test this locally, you need to set them in your machine. @@ -95,47 +68,9 @@ export class DiskWrapper { return this.putStream(key, contents) } - async rawS3ClientPutStream( - key: string, - contents: Readable, - options?: WriteOptions, - ) { - debugger - const awsConfig = getAwsConfig() - const client = new S3Client({ - credentials: awsConfig.credentials, - region: awsConfig.region, - }) - client.middlewareStack.use(logRequestMiddleware()) - return new Promise((resolve, reject) => { - debugger - contents.once('error', reject) - const commandOptions = { - Bucket: awsConfig.bucket, - Key: key, - ContentType: 'text/csv', - ContentLength: contents.readableLength, - Body: contents, - } - debug_default('commandOptions: %O', commandOptions) - const command = new PutObjectCommand(commandOptions) - return client - .send(command) - .then((data) => { - debugger - debug_default('file %s:%s written', awsConfig.bucket, key) - resolve(data) - }) - .catch((e) => { - debugger - debug_default('Error: ', e) - reject(e) - }) - }) - } - async putStream(key: string, contents: Readable, options?: WriteOptions) { try { + debugger await this.disk.putStream(key, contents, { ...options, contentLength: contents.readableLength,