a demonstration replicated social networking web app built with anproto wiredove.net/
social ed25519 protocols
at main 68 lines 2.0 kB view raw
1import { apds } from 'apds' 2import { h } from 'h' 3 4export const imgUpload = async (textarea) => { 5 const uploadButton = h('button', { 6 classList: 'material-symbols-outlined', 7 onclick: () => { uploader.click() } 8 }, ['image_arrow_up']) 9 10 const uploader = h('input', { type: 'file', style: 'display: none;'}) 11 12 uploader.addEventListener('change', (e) => { 13 const file = e.target.files[0] 14 const reader = new FileReader() 15 16 reader.onload = (e) => { 17 const canvas = document.createElement("canvas") 18 const ctx = canvas.getContext("2d") 19 const img = new Image() 20 21 img.onload = async () => { 22 //const size = 256 23 //if (img.width > size || img.height > size) { 24 // const width = img.width 25 // const height = img.height 26 // let cropWidth 27 // let cropHeight 28 // if (width > height) { 29 // cropWidth = size 30 // cropHeight = cropWidth * (height / width) 31 // } else { 32 // cropHeight = size 33 // cropWidth = cropHeight * (width / height) 34 // } 35 36 // canvas.width = cropWidth 37 // canvas.height = cropHeight 38 // ctx.drawImage(img, 0, 0, width, height, 0, 0, cropWidth, cropHeight) 39 // const croppedImage = canvas.toDataURL() 40 // avatarImg.src = croppedImage 41 // const hash = await apds.make(croppedImage) 42 // await apds.put('image', hash) 43 //} else { 44 const croppedImage = canvas.toDataURL() 45 const hash = await apds.make(img.src) 46 const mdimg = `![](${hash})` 47 console.log(await apds.get(hash)) 48 if (textarea.value) { 49 textarea.value = textarea.value + '\n' + mdimg 50 } else { 51 textarea.value = mdimg 52 } 53 // await apds.put('image', hash) 54 //} 55 } 56 img.src = e.target.result 57 } 58 reader.readAsDataURL(file) 59 }) 60 61 62 63 return h('div', [ 64 uploadButton, 65 uploader 66 ]) 67} 68