mirror of
https://gitlab.com/bramw/baserow.git
synced 2024-11-22 07:42:36 +00:00
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
import addPublicAuthTokenHeader from '@baserow/modules/database/utils/publicView'
|
|
|
|
export default (client) => {
|
|
const prepareRequestConfig = ({ publicAuthToken = null }) => {
|
|
const config = { headers: {} }
|
|
if (publicAuthToken) {
|
|
addPublicAuthTokenHeader(config, publicAuthToken)
|
|
}
|
|
return config
|
|
}
|
|
|
|
return {
|
|
getMetaInformation(slug, publicAuthToken = null) {
|
|
const config = prepareRequestConfig({ publicAuthToken })
|
|
return client.get(`/database/views/form/${slug}/submit/`, config)
|
|
},
|
|
submit(slug, values, publicAuthToken = null) {
|
|
const config = prepareRequestConfig({ publicAuthToken })
|
|
return client.post(`/database/views/form/${slug}/submit/`, values, config)
|
|
},
|
|
uploadFile(
|
|
file,
|
|
onUploadProgress = function () {},
|
|
slug,
|
|
publicAuthToken = null
|
|
) {
|
|
const formData = new FormData()
|
|
formData.append('file', file)
|
|
|
|
const config = {
|
|
onUploadProgress,
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data',
|
|
},
|
|
}
|
|
|
|
if (publicAuthToken) {
|
|
addPublicAuthTokenHeader(config, publicAuthToken)
|
|
}
|
|
|
|
return client.post(
|
|
`/database/views/form/${slug}/upload-file/`,
|
|
formData,
|
|
config
|
|
)
|
|
},
|
|
}
|
|
}
|