Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opencode-ai/app",
"version": "0.2.6",
"version": "0.2.7",
"description": "",
"type": "module",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-electron/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@opencode-ai/desktop-electron",
"private": true,
"version": "0.2.6",
"version": "0.2.7",
"type": "module",
"license": "Apache-2.0",
"homepage": "https://pawwork.ai",
Expand Down
40 changes: 40 additions & 0 deletions packages/desktop-electron/src/main/attachment-mime.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { describe, expect, test } from "bun:test"

import { IMAGE_EXTS } from "@opencode-ai/util/file-extensions"

import { attachmentPathMime, MIME_BY_EXTENSION } from "./attachment-mime"

describe("attachmentPathMime", () => {
test("returns MIME types for direct attachment files", () => {
expect(attachmentPathMime("/tmp/image.gif")).toBe("image/gif")
expect(attachmentPathMime("/tmp/image.jpeg")).toBe("image/jpeg")
expect(attachmentPathMime("/tmp/image.png")).toBe("image/png")
expect(attachmentPathMime("/tmp/image.JPG")).toBe("image/jpeg")
expect(attachmentPathMime("/tmp/image.webp")).toBe("image/webp")
expect(attachmentPathMime("/tmp/document.pdf")).toBe("application/pdf")
Comment thread
Astro-Han marked this conversation as resolved.
})

test("returns MIME types using an injected extension reader", () => {
const extname = (filepath: string) => filepath.slice(filepath.lastIndexOf("."))

expect(attachmentPathMime("C:\\tmp\\image.PNG", extname)).toBe("image/png")
})

test("keeps image MIME entries in sync with the renderer contract", () => {
const imageEntries = [...MIME_BY_EXTENSION.entries()]
.filter(([extension]) => extension !== "pdf")
.sort(([left], [right]) => left.localeCompare(right))

const rendererImageEntries = [...IMAGE_EXTS.entries()].sort(([left], [right]) => left.localeCompare(right))

expect(imageEntries).toEqual(rendererImageEntries)
})

test("returns undefined for unsupported extensions", () => {
expect(attachmentPathMime("/tmp/archive.zip")).toBeUndefined()
})

test("returns undefined for missing extensions", () => {
expect(attachmentPathMime("/tmp/no-extension")).toBeUndefined()
})
Comment thread
Astro-Han marked this conversation as resolved.
})
16 changes: 16 additions & 0 deletions packages/desktop-electron/src/main/attachment-mime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import path from "node:path"

// Keep image entries in sync with packages/util/src/file-extensions.ts::IMAGE_EXTS.
export const MIME_BY_EXTENSION = new Map([
["gif", "image/gif"],
["jpeg", "image/jpeg"],
["jpg", "image/jpeg"],
["pdf", "application/pdf"],
["png", "image/png"],
["webp", "image/webp"],
Comment thread
Astro-Han marked this conversation as resolved.
])

export function attachmentPathMime(filepath: string, extname = path.extname) {
const suffix = extname(filepath).slice(1).toLowerCase()
return MIME_BY_EXTENSION.get(suffix)
}
8 changes: 1 addition & 7 deletions packages/desktop-electron/src/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from "node:path"
import { execFile } from "node:child_process"
import { BrowserWindow, Notification, app, clipboard, dialog, ipcMain, shell } from "electron"
import type { IpcMainEvent, IpcMainInvokeEvent } from "electron"
import { IMAGE_EXTS } from "@opencode-ai/util/file-extensions"

import type {
DesktopContext,
Expand All @@ -14,6 +13,7 @@ import type {
UpdateInfo,
WslConfig,
} from "../preload/types"
import { attachmentPathMime } from "./attachment-mime"
import { getStore } from "./store"
import { setTitlebar } from "./windows"

Expand All @@ -34,12 +34,6 @@ function normalizeAttachmentPath(filepath: unknown) {
return path.resolve(filepath)
}

function attachmentPathMime(filepath: string) {
const suffix = path.extname(filepath).slice(1).toLowerCase()
if (suffix === "pdf") return "application/pdf"
return IMAGE_EXTS.get(suffix)
}

type Deps = {
killSidecar: () => void
awaitInitialization: (sendStep: (step: InitStep) => void) => Promise<ServerReadyData>
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json.schemastore.org/package.json",
"version": "0.2.6",
"version": "0.2.7",
"name": "opencode",
"type": "module",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/util/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opencode-ai/util",
"version": "0.2.6",
"version": "0.2.7",
"private": true,
"type": "module",
"license": "Apache-2.0",
Expand Down
Loading