| 1 | const objects = args.base + 'v1/objects/'; |
| 2 | const auth = {Authorization: 'skype_token ' + skypeCache.token, 'x-ms-client-version': '1415/1.0.0.2018090100'}; |
| 3 | try { |
| 4 | const created = await fetch(objects, { |
| 5 | method: 'POST', |
| 6 | headers: {...auth, 'Content-Type': 'application/json', Accept: 'application/json'}, |
| 7 | body: JSON.stringify({ |
| 8 | type: 'pish/image', |
| 9 | permissions: {[args.conversationId]: ['read']}, |
| 10 | sharingMode: 'Inline', |
| 11 | filename: args.filename, |
| 12 | }), |
| 13 | }); |
| 14 | if (!created.ok) return {status: created.status, body: 'create_' + (await created.text()).slice(0, 300)}; |
| 15 | const id = (await created.json()).id; |
| 16 | const bytes = Uint8Array.from(atob(args.base64), (character) => character.charCodeAt(0)); |
| 17 | const stored = await fetch(objects + encodeURIComponent(id) + '/content/imgpsh', { |
| 18 | method: 'PUT', |
| 19 | headers: {...auth, 'Content-Type': 'application/octet-stream', 'Content-Range': `bytes 0-${bytes.length - 1}/${bytes.length}`}, |
| 20 | body: bytes, |
| 21 | }); |
| 22 | if (!stored.ok) return {status: stored.status, body: 'put_' + (await stored.text()).slice(0, 300)}; |
| 23 | return {status: stored.status, body: {id}}; |
| 24 | } catch (error) { |
| 25 | return {status: 0, body: String(error)}; |
| 26 | } |