(event: unknown)
| 79 | } |
| 80 | |
| 81 | function interceptUploadAddFiles(event: unknown): void { |
| 82 | if (!event || typeof event !== "object" || !("type" in event)) return; |
| 83 | |
| 84 | const payload = event as UploadAddFilesEvent; |
| 85 | if (payload.type !== "UPLOAD_ATTACHMENT_ADD_FILES") return; |
| 86 | |
| 87 | if (payload.draftType !== DraftType.ChannelMessage) return; |
| 88 | |
| 89 | if (!settings.store.bypassDiscordUpload || !isConfigured()) return; |
| 90 | |
| 91 | const files = [ |
| 92 | ...extractFilesFromValue(payload.files), |
| 93 | ...extractFilesFromValue(payload.uploads), |
| 94 | ...extractFilesFromValue(payload.items) |
| 95 | ]; |
| 96 | const uniqueFiles = Array.from(new Set(files)).filter(f => isFileTypeAllowed(f) && !handledDropFiles.has(f)); |
| 97 | |
| 98 | if (!uniqueFiles.length) return; |
| 99 | if (!shouldInterceptUploadFiles(uniqueFiles, getGuildIdForChannel(payload.channelId))) return; |
| 100 | |
| 101 | payload.files = []; |
| 102 | payload.uploads = []; |
| 103 | payload.items = []; |
| 104 | void uploadProvidedFiles(uniqueFiles); |
| 105 | } |
| 106 | |
| 107 | function handlePaste(event: ClipboardEvent) { |
| 108 | const files = Array.from(event.clipboardData?.files || []); |
no test coverage detected