| 72 | export type Content = z.infer<typeof Content> |
| 73 | |
| 74 | async function shouldEncode(file: BunFile): Promise<boolean> { |
| 75 | const type = file.type?.toLowerCase() |
| 76 | if (!type) return false |
| 77 | |
| 78 | if (type.startsWith("text/")) return false |
| 79 | if (type.includes("charset=")) return false |
| 80 | |
| 81 | const parts = type.split("/", 2) |
| 82 | const top = parts[0] |
| 83 | const rest = parts[1] ?? "" |
| 84 | const sub = rest.split(";", 1)[0] |
| 85 | |
| 86 | const tops = ["image", "audio", "video", "font", "model", "multipart"] |
| 87 | if (tops.includes(top)) return true |
| 88 | |
| 89 | if (type === "application/octet-stream") return true |
| 90 | |
| 91 | const bins = [ |
| 92 | "zip", |
| 93 | "gzip", |
| 94 | "bzip", |
| 95 | "compressed", |
| 96 | "binary", |
| 97 | "stream", |
| 98 | "pdf", |
| 99 | "msword", |
| 100 | "powerpoint", |
| 101 | "excel", |
| 102 | "ogg", |
| 103 | "exe", |
| 104 | "dmg", |
| 105 | "iso", |
| 106 | "rar", |
| 107 | ] |
| 108 | if (bins.some((mark) => sub.includes(mark))) return true |
| 109 | |
| 110 | return false |
| 111 | } |
| 112 | |
| 113 | export const Event = { |
| 114 | Edited: BusEvent.define( |