Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
71 lines
1.9 KiB
JavaScript
71 lines
1.9 KiB
JavaScript
/* global axios */
|
|
|
|
/**
|
|
* Constants and Configuration
|
|
*/
|
|
|
|
// Version for the API endpoint.
|
|
const API_VERSION = 'v1';
|
|
|
|
// Default headers to be used in the axios request.
|
|
const HEADERS = {
|
|
'Content-Type': 'multipart/form-data',
|
|
};
|
|
|
|
/**
|
|
* Uploads a file to the server.
|
|
*
|
|
* This function sends a POST request to a given API endpoint and uploads the specified file.
|
|
* The function uses FormData to wrap the file and axios to send the request.
|
|
*
|
|
* @param {File} file - The file to be uploaded. It should be a File object (typically coming from a file input element).
|
|
* @param {string} accountId - The account ID.
|
|
* @returns {Promise} A promise that resolves with the server's response when the upload is successful, or rejects if there's an error.
|
|
*/
|
|
export async function uploadFile(file, accountId) {
|
|
if (!accountId) {
|
|
accountId = window.location.pathname.split('/')[3];
|
|
}
|
|
|
|
// Append the file to the FormData instance under the key 'attachment'.
|
|
let formData = new FormData();
|
|
formData.append('attachment', file);
|
|
|
|
const { data } = await axios.post(
|
|
`/api/${API_VERSION}/accounts/${accountId}/upload`,
|
|
formData,
|
|
{ headers: HEADERS }
|
|
);
|
|
|
|
return {
|
|
fileUrl: data.file_url,
|
|
blobKey: data.blob_key,
|
|
blobId: data.blob_id,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Uploads an image from an external URL.
|
|
*
|
|
* @param {string} url - The external URL of the image.
|
|
* @param {string} accountId - The account ID.
|
|
* @returns {Promise} A promise that resolves with the server's response.
|
|
*/
|
|
export async function uploadExternalImage(url, accountId) {
|
|
if (!accountId) {
|
|
accountId = window.location.pathname.split('/')[3];
|
|
}
|
|
|
|
const { data } = await axios.post(
|
|
`/api/${API_VERSION}/accounts/${accountId}/upload`,
|
|
{ external_url: url },
|
|
{ headers: { 'Content-Type': 'application/json' } }
|
|
);
|
|
|
|
return {
|
|
fileUrl: data.file_url,
|
|
blobKey: data.blob_key,
|
|
blobId: data.blob_id,
|
|
};
|
|
}
|