Fix VK doc upload parsing for docs.save object response
This commit is contained in:
@@ -208,7 +208,15 @@ async function uploadDocForMessage(peerId, filePath) {
|
|||||||
const saveRes = await vkApi('docs.save', { file: uploadJson.file, title: p.split('/').pop() || 'booking.doc' });
|
const saveRes = await vkApi('docs.save', { file: uploadJson.file, title: p.split('/').pop() || 'booking.doc' });
|
||||||
if (saveRes.error) throw new Error(`docs.save: ${JSON.stringify(saveRes.error)}`);
|
if (saveRes.error) throw new Error(`docs.save: ${JSON.stringify(saveRes.error)}`);
|
||||||
|
|
||||||
const doc = Array.isArray(saveRes?.response) ? saveRes.response[0] : null;
|
let doc = null;
|
||||||
|
if (Array.isArray(saveRes?.response)) {
|
||||||
|
doc = saveRes.response[0] || null;
|
||||||
|
} else if (saveRes?.response?.doc) {
|
||||||
|
doc = saveRes.response.doc;
|
||||||
|
} else if (saveRes?.response && saveRes.response.id && saveRes.response.owner_id) {
|
||||||
|
doc = saveRes.response;
|
||||||
|
}
|
||||||
|
|
||||||
if (!doc?.owner_id || !doc?.id) throw new Error(`docs.save bad response: ${JSON.stringify(saveRes.response)}`);
|
if (!doc?.owner_id || !doc?.id) throw new Error(`docs.save bad response: ${JSON.stringify(saveRes.response)}`);
|
||||||
return `doc${doc.owner_id}_${doc.id}`;
|
return `doc${doc.owner_id}_${doc.id}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user