mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add file/image attachment support to chat input (#22604)
This change adds support for image attachments to chat via add button and clipboard paste. Files are stored in a new `chat_files` table and referenced by ID in message content. File data is resolved from storage at LLM dispatch time, keeping the message content column small. Upload validates MIME types via content type or content sniffing against an allowlist (png, jpeg, gif, webp). The retrieval endpoint serves files with immutable caching headers. On the frontend, uploads start eagerly on attach with a background fetch to pre-warm the browser HTTP cache so the timeline renders instantly after send.
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
DROP INDEX IF EXISTS idx_chat_files_org;
|
||||
DROP TABLE IF EXISTS chat_files;
|
||||
@@ -0,0 +1,12 @@
|
||||
CREATE TABLE chat_files (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
owner_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
organization_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
name TEXT NOT NULL DEFAULT '',
|
||||
mimetype TEXT NOT NULL,
|
||||
data BYTEA NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX idx_chat_files_owner ON chat_files(owner_id);
|
||||
CREATE INDEX idx_chat_files_org ON chat_files(organization_id);
|
||||
@@ -0,0 +1,13 @@
|
||||
INSERT INTO chat_files (id, owner_id, organization_id, created_at, name, mimetype, data)
|
||||
SELECT
|
||||
'00000000-0000-0000-0000-000000000099',
|
||||
u.id,
|
||||
om.organization_id,
|
||||
'2024-01-01 00:00:00+00',
|
||||
'test.png',
|
||||
'image/png',
|
||||
E'\\x89504E47'
|
||||
FROM users u
|
||||
JOIN organization_members om ON om.user_id = u.id
|
||||
ORDER BY u.created_at, u.id
|
||||
LIMIT 1;
|
||||
Reference in New Issue
Block a user