Use jetpack to serve heynote-file protocol responses

#build
This commit is contained in:
Jonatan Heyman 2026-01-29 13:43:47 +01:00
parent ba78d8a9e4
commit e951af3a52

View File

@ -1,6 +1,7 @@
import { net, protocol } from "electron"
import { protocol } from "electron"
import * as path from "node:path"
import { pathToFileURL } from "node:url"
import * as jetpack from "fs-jetpack"
import * as mimetypes from "mime-types"
export function registerProtocolBeforeAppReady() {
@ -22,7 +23,12 @@ export function registerProtocol(fileLibrary) {
const filename = decodeURIComponent(encodedPath)
const filePath = path.join(fileLibrary.imagesBasePath, filename);
// net.fetch + file URL is the modern recommended pattern
return net.fetch(pathToFileURL(filePath).toString())
const data = await jetpack.readAsync(filePath, "buffer")
if (!data) {
return new Response("Not found", { status: 404 })
}
const contentType = mimetypes.lookup(filePath) || "application/octet-stream"
return new Response(data, { headers: { "Content-Type": contentType } })
})
}