From 1e2d745001e3919a169b8cdf0758d890e04558f4 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 7 Mar 2022 09:57:03 +0000 Subject: [PATCH 1/2] Fix relative usage of S3 upload API calls --- packages/frontend-core/src/api/attachments.js | 105 +++++++++--------- 1 file changed, 55 insertions(+), 50 deletions(-) diff --git a/packages/frontend-core/src/api/attachments.js b/packages/frontend-core/src/api/attachments.js index 2077c4f7ef..e2eb348f9d 100644 --- a/packages/frontend-core/src/api/attachments.js +++ b/packages/frontend-core/src/api/attachments.js @@ -1,61 +1,66 @@ -export const buildAttachmentEndpoints = API => ({ - /** - * Uploads an attachment to the server. - * @param data the attachment to upload - * @param tableId the table ID to upload to - */ - uploadAttachment: async ({ data, tableId }) => { - return await API.post({ - url: `/api/attachments/${tableId}/upload`, - body: data, - json: false, - }) - }, - - /** - * Uploads an attachment to the server as a builder user from the builder. - * @param data the data to upload - */ - uploadBuilderAttachment: async data => { - return await API.post({ - url: "/api/attachments/process", - body: data, - json: false, - }) - }, - +export const buildAttachmentEndpoints = API => { /** * Generates a signed URL to upload a file to an external datasource. * @param datasourceId the ID of the datasource to upload to * @param bucket the name of the bucket to upload to * @param key the name of the file to upload to */ - getSignedDatasourceURL: async ({ datasourceId, bucket, key }) => { + const getSignedDatasourceURL = async ({ datasourceId, bucket, key }) => { return await API.post({ url: `/api/attachments/${datasourceId}/url`, body: { bucket, key }, }) - }, + } - /** - * Uploads a file to an external datasource. - * @param datasourceId the ID of the datasource to upload to - * @param bucket the name of the bucket to upload to - * @param key the name of the file to upload to - * @param data the file to upload - */ - externalUpload: async ({ datasourceId, bucket, key, data }) => { - const { signedUrl, publicUrl } = await API.getSignedDatasourceURL({ - datasourceId, - bucket, - key, - }) - await API.put({ - url: signedUrl, - body: data, - json: false, - external: true, - }) - return { publicUrl } - }, -}) + return { + getSignedDatasourceURL, + + /** + * Uploads an attachment to the server. + * @param data the attachment to upload + * @param tableId the table ID to upload to + */ + uploadAttachment: async ({ data, tableId }) => { + return await API.post({ + url: `/api/attachments/${tableId}/upload`, + body: data, + json: false, + }) + }, + + /** + * Uploads an attachment to the server as a builder user from the builder. + * @param data the data to upload + */ + uploadBuilderAttachment: async data => { + return await API.post({ + url: "/api/attachments/process", + body: data, + json: false, + }) + }, + + /** + * Uploads a file to an external datasource. + * @param datasourceId the ID of the datasource to upload to + * @param bucket the name of the bucket to upload to + * @param key the name of the file to upload to + * @param data the file to upload + */ + externalUpload: async ({ datasourceId, bucket, key, data }) => { + console.log(API) + const { signedUrl, publicUrl } = await getSignedDatasourceURL({ + datasourceId, + bucket, + key, + }) + await API.put({ + url: signedUrl, + body: data, + json: false, + external: true, + }) + return { publicUrl } + }, + } +} From d011e2e63ebf1888ec2f6ad8b333044a43af322f Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 7 Mar 2022 09:57:15 +0000 Subject: [PATCH 2/2] Fix loading state in S3 upload component and show error if possible --- .../src/components/app/forms/S3Upload.svelte | 5 +- packages/client/stats.html | 2689 +++++++++++++++++ 2 files changed, 2693 insertions(+), 1 deletion(-) create mode 100644 packages/client/stats.html diff --git a/packages/client/src/components/app/forms/S3Upload.svelte b/packages/client/src/components/app/forms/S3Upload.svelte index ab66755b6e..031c49f4b4 100644 --- a/packages/client/src/components/app/forms/S3Upload.svelte +++ b/packages/client/src/components/app/forms/S3Upload.svelte @@ -81,7 +81,10 @@ loading = false return res } catch (error) { - notificationStore.actions.error(`Error uploading file: ${error}`) + notificationStore.actions.error( + `Error uploading file: ${error?.message || error}` + ) + loading = false } } diff --git a/packages/client/stats.html b/packages/client/stats.html new file mode 100644 index 0000000000..4cab61a146 --- /dev/null +++ b/packages/client/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + +