chore: generate
This commit is contained in:
@@ -17,9 +17,7 @@ export function useDirectoryPicker() {
|
|||||||
|
|
||||||
return (input: DirectoryPickerInput) => {
|
return (input: DirectoryPickerInput) => {
|
||||||
if (directoryPickerKind(platform.platform, input.server) === "native" && platform.platform === "desktop") {
|
if (directoryPickerKind(platform.platform, input.server) === "native" && platform.platform === "desktop") {
|
||||||
void platform
|
void platform.openDirectoryPickerDialog({ title: input.title, multiple: input.multiple }).then(input.onSelect)
|
||||||
.openDirectoryPickerDialog({ title: input.title, multiple: input.multiple })
|
|
||||||
.then(input.onSelect)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,14 @@ import { ACCEPTED_FILE_TYPES, ACCEPTED_IMAGE_TYPES } from "@/constants/file-pick
|
|||||||
|
|
||||||
export { ACCEPTED_FILE_TYPES }
|
export { ACCEPTED_FILE_TYPES }
|
||||||
|
|
||||||
type AttachmentPicker = (options: {
|
type AttachmentPicker = (
|
||||||
defaultPath?: string
|
options: {
|
||||||
multiple?: boolean
|
defaultPath?: string
|
||||||
accept?: string[]
|
multiple?: boolean
|
||||||
}, onFile: (file: File) => Promise<unknown>) => Promise<void>
|
accept?: string[]
|
||||||
|
},
|
||||||
|
onFile: (file: File) => Promise<unknown>,
|
||||||
|
) => Promise<void>
|
||||||
|
|
||||||
export function pickAttachmentFiles(input: {
|
export function pickAttachmentFiles(input: {
|
||||||
picker?: AttachmentPicker
|
picker?: AttachmentPicker
|
||||||
|
|||||||
@@ -50,7 +50,10 @@ type PlatformBase = {
|
|||||||
notify(title: string, description?: string, href?: string): Promise<void>
|
notify(title: string, description?: string, href?: string): Promise<void>
|
||||||
|
|
||||||
/** Open a native attachment picker and read selected files sequentially (desktop only) */
|
/** Open a native attachment picker and read selected files sequentially (desktop only) */
|
||||||
openAttachmentPickerDialog?(opts: OpenAttachmentPickerOptions, onFile: (file: File) => Promise<unknown>): Promise<void>
|
openAttachmentPickerDialog?(
|
||||||
|
opts: OpenAttachmentPickerOptions,
|
||||||
|
onFile: (file: File) => Promise<unknown>,
|
||||||
|
): Promise<void>
|
||||||
|
|
||||||
/** Open a native save file picker dialog (desktop only) */
|
/** Open a native save file picker dialog (desktop only) */
|
||||||
saveFilePickerDialog?(opts?: SaveFilePickerOptions): Promise<string | null>
|
saveFilePickerDialog?(opts?: SaveFilePickerOptions): Promise<string | null>
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ import {
|
|||||||
|
|
||||||
describe("assertAttachmentBudget", () => {
|
describe("assertAttachmentBudget", () => {
|
||||||
test("accepts selections within the media ingest limit", () => {
|
test("accepts selections within the media ingest limit", () => {
|
||||||
expect(() => assertAttachmentBudget([{ size: MAX_ATTACHMENT_BYTES / 2 }, { size: MAX_ATTACHMENT_BYTES / 2 }])).not.toThrow()
|
expect(() =>
|
||||||
|
assertAttachmentBudget([{ size: MAX_ATTACHMENT_BYTES / 2 }, { size: MAX_ATTACHMENT_BYTES / 2 }]),
|
||||||
|
).not.toThrow()
|
||||||
})
|
})
|
||||||
|
|
||||||
test("rejects the selection before files are read when its total exceeds the limit", () => {
|
test("rejects the selection before files are read when its total exceeds the limit", () => {
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ export function createPickedFileAuthorizations(
|
|||||||
},
|
},
|
||||||
async read(sender: number, token: string, path: string) {
|
async read(sender: number, token: string, path: string) {
|
||||||
const selection = selections.get(token)
|
const selection = selections.get(token)
|
||||||
if (selection?.sender !== sender || !selection.paths.delete(path)) throw new Error("File was not selected by the picker")
|
if (selection?.sender !== sender || !selection.paths.delete(path))
|
||||||
|
throw new Error("File was not selected by the picker")
|
||||||
const bytes = await read(path, selection.remaining)
|
const bytes = await read(path, selection.remaining)
|
||||||
selection.remaining -= bytes.byteLength
|
selection.remaining -= bytes.byteLength
|
||||||
if (selection.paths.size === 0) selections.delete(token)
|
if (selection.paths.size === 0) selections.delete(token)
|
||||||
@@ -39,7 +40,8 @@ export async function readAttachment(filePath: string, maxBytes = MAX_ATTACHMENT
|
|||||||
const file = await open(filePath, "r")
|
const file = await open(filePath, "r")
|
||||||
try {
|
try {
|
||||||
const info = await file.stat()
|
const info = await file.stat()
|
||||||
if (info.size > maxBytes) throw new Error(`Selected attachments exceed the ${MAX_ATTACHMENT_BYTES / 1024 / 1024} MB limit`)
|
if (info.size > maxBytes)
|
||||||
|
throw new Error(`Selected attachments exceed the ${MAX_ATTACHMENT_BYTES / 1024 / 1024} MB limit`)
|
||||||
const bytes = Buffer.allocUnsafe(info.size)
|
const bytes = Buffer.allocUnsafe(info.size)
|
||||||
let offset = 0
|
let offset = 0
|
||||||
while (offset < info.size) {
|
while (offset < info.size) {
|
||||||
|
|||||||
@@ -131,7 +131,11 @@ export function registerIpcHandlers(deps: Deps) {
|
|||||||
})
|
})
|
||||||
if (result.canceled) return null
|
if (result.canceled) return null
|
||||||
const files = await Promise.all(
|
const files = await Promise.all(
|
||||||
result.filePaths.map(async (filePath) => ({ path: filePath, name: basename(filePath), size: (await stat(filePath)).size })),
|
result.filePaths.map(async (filePath) => ({
|
||||||
|
path: filePath,
|
||||||
|
name: basename(filePath),
|
||||||
|
size: (await stat(filePath)).size,
|
||||||
|
})),
|
||||||
)
|
)
|
||||||
assertAttachmentBudget(files)
|
assertAttachmentBudget(files)
|
||||||
const token = pickedFiles.add(event.sender.id, result.filePaths)
|
const token = pickedFiles.add(event.sender.id, result.filePaths)
|
||||||
|
|||||||
Reference in New Issue
Block a user