forked from tsai/budibase
22 changed files with 2905 additions and 169 deletions
File diff suppressed because one or more lines are too long
@ -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 } |
|||
}, |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,17 @@ |
|||
module MySQLMock { |
|||
const mysql: any = {} |
|||
|
|||
const client = { |
|||
connect: jest.fn(), |
|||
end: jest.fn(), |
|||
query: jest.fn(async () => { |
|||
return [[]] |
|||
}), |
|||
} |
|||
|
|||
mysql.createConnection = jest.fn(async () => { |
|||
return client |
|||
}) |
|||
|
|||
module.exports = mysql |
|||
} |
|||
Loading…
Reference in new issue