2022-01-20 10:40:53 +01:00
|
|
|
export const buildAttachmentEndpoints = API => ({
|
|
|
|
/**
|
|
|
|
* Uploads an attachment to the server.
|
2022-01-21 10:10:59 +01:00
|
|
|
* @param data the attachment to upload
|
|
|
|
* @param tableId the table ID to upload to
|
2022-01-20 10:40:53 +01:00
|
|
|
*/
|
|
|
|
uploadAttachment: async ({ data, tableId }) => {
|
|
|
|
return await API.post({
|
|
|
|
url: `/api/attachments/${tableId}/upload`,
|
|
|
|
body: data,
|
|
|
|
json: false,
|
|
|
|
})
|
|
|
|
},
|
2022-01-21 10:10:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
})
|
|
|
|
},
|
2022-01-24 16:46:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a signed URL to upload a file to an external datasource.
|
2022-01-25 17:54:55 +01:00
|
|
|
* @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
|
2022-01-24 16:46:54 +01:00
|
|
|
*/
|
2022-01-25 17:54:55 +01:00
|
|
|
getSignedDatasourceURL: async ({ datasourceId, bucket, key }) => {
|
2022-01-24 16:46:54 +01:00
|
|
|
return await API.post({
|
|
|
|
url: `/api/attachments/${datasourceId}/url`,
|
|
|
|
body: { bucket, key },
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uploads a file to an external datasource.
|
2022-01-25 17:54:55 +01:00
|
|
|
* @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
|
2022-01-24 16:46:54 +01:00
|
|
|
*/
|
2022-01-25 17:54:55 +01:00
|
|
|
externalUpload: async ({ datasourceId, bucket, key, data }) => {
|
|
|
|
const { signedUrl, publicUrl } = await API.getSignedDatasourceURL({
|
2022-01-24 16:46:54 +01:00
|
|
|
datasourceId,
|
|
|
|
bucket,
|
2022-01-25 17:54:55 +01:00
|
|
|
key,
|
|
|
|
})
|
2022-01-24 16:46:54 +01:00
|
|
|
await API.put({
|
|
|
|
url: signedUrl,
|
|
|
|
body: data,
|
|
|
|
json: false,
|
|
|
|
external: true,
|
|
|
|
})
|
|
|
|
return { publicUrl }
|
|
|
|
},
|
2022-01-20 10:40:53 +01:00
|
|
|
})
|