better calculate_all error handling

main
qwertyforce 2023-07-05 21:29:56 +03:00
parent 0329cd8c5c
commit e9ce355706
3 changed files with 41 additions and 19 deletions

View File

@ -14,7 +14,7 @@ async function calculate_phash_features(image_id: number, image: Buffer) {
...form.getHeaders()
}
})
return status.data
return status
}
async function calculate_local_features(image_id: number, image: Buffer) {
@ -28,7 +28,7 @@ async function calculate_local_features(image_id: number, image: Buffer) {
...form.getHeaders()
}
})
return status.data
return status
}
async function calculate_global_features(image_id: number, image: Buffer) {
@ -42,7 +42,7 @@ async function calculate_global_features(image_id: number, image: Buffer) {
...form.getHeaders()
}
})
return status.data
return status
}
async function calculate_image_text_features(image_id: number, image: Buffer) {
@ -56,7 +56,7 @@ async function calculate_image_text_features(image_id: number, image: Buffer) {
...form.getHeaders()
}
})
return status.data
return status
}
async function calculate_color_features(image_id: number, image: Buffer) {
const form = new FormData()
@ -69,7 +69,7 @@ async function calculate_color_features(image_id: number, image: Buffer) {
...form.getHeaders()
}
})
return status.data
return status
}
// async function calculate_text_features(image_id: number, image: Buffer) {
@ -390,27 +390,27 @@ async function get_similar_images(image: Buffer, find_duplicate:boolean) {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
async function delete_local_features_by_id(image_id: number) {
const status = await axios.post(`${config.local_features_microservice_url}/delete_local_features`, { image_id: image_id })
return status.data
return status
}
async function delete_global_features_by_id(image_id: number) {
const status = await axios.post(`${config.global_features_microservice_url}/delete_global_features`, { image_id: image_id })
return status.data
return status
}
async function delete_image_text_features_by_id(image_id: number) {
const status = await axios.post(`${config.image_text_features_microservice_url}/delete_image_text_features`, { image_id: image_id })
return status.data
return status
}
async function delete_color_features_by_id(image_id: number) {
const status = await axios.post(`${config.color_microservice_url}/delete_color_features`, { image_id: image_id })
return status.data
return status
}
async function delete_phash_features_by_id(image_id: number) {
const status = await axios.post(`${config.phash_microservice_url}/delete_phash_features`, { image_id: image_id })
return status.data
return status
}
// async function delete_text_features_by_id(image_id: number) {
@ -423,8 +423,8 @@ async function delete_phash_features_by_id(image_id: number) {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
async function calculate_all_image_features(image_id: number, image_buffer: Buffer) {
return Promise.allSettled([
calculate_global_features(image_id, image_buffer),
calculate_local_features(image_id, image_buffer),
// calculate_global_features(image_id, image_buffer),
// calculate_local_features(image_id, image_buffer),
calculate_color_features(image_id, image_buffer),
calculate_phash_features(image_id, image_buffer),
calculate_image_text_features(image_id, image_buffer),
@ -434,8 +434,8 @@ async function calculate_all_image_features(image_id: number, image_buffer: Buff
async function delete_all_image_features(image_id: number) {
return Promise.allSettled([
delete_global_features_by_id(image_id),
delete_local_features_by_id(image_id),
// delete_global_features_by_id(image_id),
// delete_local_features_by_id(image_id),
delete_color_features_by_id(image_id),
delete_phash_features_by_id(image_id),
delete_image_text_features_by_id(image_id)

View File

@ -34,18 +34,23 @@ async function calculate_all_image_features(req: FastifyRequest<{ Body: FromSche
if (req.body.image_id.value) {
const image_id = parseInt(req.body.image_id.value)
const results:any = await image_ops.calculate_all_image_features(image_id, image_buffer)
console.log(results[3])
for(let i=0;i<results.length;i++){
const new_obj:any = {status:results[i].status}
if(results[i]?.reason?.message){
new_obj.reason = results[i].reason.message
}
if(results[i]?.value!==undefined){
new_obj.value=results[i].value
}
if(results[i]?.reason?.response?.data){
new_obj.data=results[i]?.reason?.response?.data
}
if(results[i]?.reason?.config?.url){
new_obj.url=results[i]?.reason?.config?.url
}
if(results[i]?.value){
new_obj.value=results[i].value.data
new_obj.url=results[i].value.config.url
}
results[i] = new_obj
}
console.log(results)

View File

@ -10,7 +10,24 @@ const body_schema_delete_all_image_features = {
} as const;
async function delete_all_image_features(req: FastifyRequest<{ Body: FromSchema<typeof body_schema_delete_all_image_features> }>, res: FastifyReply) {
const results = await image_ops.delete_all_image_features(req.body.image_id)
const results:any = await image_ops.delete_all_image_features(req.body.image_id)
for(let i=0;i<results.length;i++){
const new_obj:any = {status:results[i].status}
if(results[i]?.reason?.message){
new_obj.reason = results[i].reason.message
}
if(results[i]?.reason?.response?.data){
new_obj.data=results[i]?.reason?.response?.data
}
if(results[i]?.reason?.config?.url){
new_obj.url=results[i]?.reason?.config?.url
}
if(results[i]?.value){
new_obj.value=results[i].value.data
new_obj.url=results[i].value.config.url
}
results[i] = new_obj
}
console.log(results)
res.send(results)
}