(opts)
| 75 | }; |
| 76 | |
| 77 | const upload = async (opts) => { |
| 78 | const { path, session, url = 'https://asset.cml.dev' } = opts; |
| 79 | |
| 80 | const { mime, size, data: body } = await fetchUploadData(opts); |
| 81 | const filename = path ? PATH.basename(path) : `file.${mime.split('/')[1]}`; |
| 82 | |
| 83 | const headers = { |
| 84 | 'Content-Length': size, |
| 85 | 'Content-Type': mime, |
| 86 | 'Content-Disposition': `inline; filename="${filename}"` |
| 87 | }; |
| 88 | |
| 89 | if (session) headers['Content-Address-Seed'] = `${session}:${path}`; |
| 90 | const response = await fetch(url, { method: 'POST', headers, body }); |
| 91 | const uri = await response.text(); |
| 92 | |
| 93 | if (!uri) |
| 94 | throw new Error( |
| 95 | `Empty response from asset backend with status code ${response.status}` |
| 96 | ); |
| 97 | |
| 98 | return { uri, mime, size }; |
| 99 | }; |
| 100 | |
| 101 | const randid = () => { |
| 102 | return ( |
no test coverage detected