mirror of
https://github.com/heyman/heynote.git
synced 2026-02-06 03:17:03 +00:00
Use jetpack to serve heynote-file protocol responses
#build
This commit is contained in:
parent
ba78d8a9e4
commit
e951af3a52
@ -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 } })
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user