Add updateMultipleObjects and sendObjectFunction methods to ApiServerContext
- Implemented updateMultipleObjects for batch updates of objects via PUT request. - Added sendObjectFunction to invoke specific functions on objects with POST requests. - Enhanced error handling for both methods to retry on failure.
This commit is contained in:
parent
a7cd374375
commit
f83069a7fb
@ -797,6 +797,28 @@ const ApiServerProvider = ({ children }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update multiple objects
|
||||||
|
const updateMultipleObjects = async (type, objects) => {
|
||||||
|
const updateUrl = `${config.backendUrl}/${type.toLowerCase()}s`
|
||||||
|
logger.debug('Updating multiple objects for ' + type)
|
||||||
|
try {
|
||||||
|
const response = await axios.put(updateUrl, objects, {
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
Authorization: `Bearer ${token}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
logger.debug('Objects updated successfully')
|
||||||
|
return response.data
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
showError(err, () => {
|
||||||
|
updateMultipleObjects(type, objects)
|
||||||
|
})
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update filament information
|
// Update filament information
|
||||||
const deleteObject = async (id, type) => {
|
const deleteObject = async (id, type) => {
|
||||||
const deleteUrl = `${config.backendUrl}/${type.toLowerCase()}s/${id}`
|
const deleteUrl = `${config.backendUrl}/${type.toLowerCase()}s/${id}`
|
||||||
@ -840,6 +862,27 @@ const ApiServerProvider = ({ children }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Call a function on an object
|
||||||
|
const sendObjectFunction = async (id, type, functionName, value = {}) => {
|
||||||
|
const url = `${config.backendUrl}/${type.toLowerCase()}s/${id}/${functionName}`
|
||||||
|
logger.debug(`Calling object function ${functionName} for ${id} at ${url}`)
|
||||||
|
try {
|
||||||
|
const response = await axios.post(url, value, {
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
Authorization: `Bearer ${token}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return response.data
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
showError(err, () => {
|
||||||
|
sendObjectFunction(id, type, functionName, value)
|
||||||
|
})
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Download GCode file content
|
// Download GCode file content
|
||||||
const fetchFileContent = async (file, download = false) => {
|
const fetchFileContent = async (file, download = false) => {
|
||||||
try {
|
try {
|
||||||
@ -1221,7 +1264,9 @@ const ApiServerProvider = ({ children }) => {
|
|||||||
unlockObject,
|
unlockObject,
|
||||||
fetchObjectLock,
|
fetchObjectLock,
|
||||||
updateObject,
|
updateObject,
|
||||||
|
updateMultipleObjects,
|
||||||
createObject,
|
createObject,
|
||||||
|
sendObjectFunction,
|
||||||
deleteObject,
|
deleteObject,
|
||||||
subscribeToObjectUpdates,
|
subscribeToObjectUpdates,
|
||||||
subscribeToObjectEvent,
|
subscribeToObjectEvent,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user