Files
red-valley/resources/[framework]/[addons]/[housing]/qs-housing/web/build/custom-upload.js

22 lines
855 B
JavaScript
Raw Normal View History

2026-03-29 21:41:17 +03:00
window.customUploadImage = async function (webpBlob, fileName, token) {
if (!token) throw new Error('FiveManage token is missing');
const form = new FormData();
form.append('file', webpBlob, fileName + '.webp');
const response = await fetch('https://fmapi.net/api/v2/image', {
method: 'POST',
body: form,
headers: { Authorization: token },
});
if (!response.ok) {
throw new Error('Upload API Error: ' + response.status + ' ' + response.statusText);
}
const result = await response.json();
if (result && result.error) {
throw new Error('Upload Error: ' + result.error);
}
if (!result || !result.data || !result.data.id || !result.data.url) {
throw new Error('Invalid response: missing id or url');
}
return { id: result.data.id, url: result.data.url };
};