Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/take-screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ async function makeScreenshotDir (ipfs) {
}
}

async function onSucess (ipfs, launchWebUI, path, img) {
const stats = await ipfs.files.stat(path)
const url = `https://share.ipfs.io/#/${stats.hash}`
async function onSuccess (ipfs, launchWebUI, path, img) {
// preserve filename if single file is shared
const filename = path.endsWith('.png') ? `?filename=${encodeURIComponent(path.split('/').pop())}` : ''
const { cid } = await ipfs.files.stat(path)
const url = `https://dweb.link/ipfs/${cid}${filename}`
clipboard.writeText(url)

notify({
Expand Down Expand Up @@ -72,7 +74,7 @@ function handleScreenshot (ctx) {

if (isDir) {
baseName += '/'
await ipfs.files.mkdir(baseName)
await ipfs.files.mkdir(baseName, { parents: true })
} else {
baseName += '.png'
}
Expand All @@ -83,12 +85,13 @@ function handleScreenshot (ctx) {
for (const { name, image } of output) {
const img = nativeImage.createFromDataURL(image)
const path = isDir ? `${baseName}${name}.png` : baseName
await ipfs.files.write(path, img.toPNG(), { create: true })
const { cid } = await ipfs.add(img.toPNG(), { pin: false }) // no low level pin, presence in MFS will be enough to keep it around
await ipfs.files.cp(cid, path)
lastImage = img
}

logger.info(`[screenshot] completed: writing screenshots to ${baseName}`)
onSucess(ipfs, launchWebUI, baseName, lastImage)
onSuccess(ipfs, launchWebUI, baseName, lastImage)
} catch (e) {
onError(e)
}
Expand Down