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 }; };