feat(chat,board): file/image attachments on chat, board threads and comments

チャット・掲示板(スレッド/コメント)へファイル/画像添付を追加。

- lib/db/migrations/002_attachments.sql: attachments テーブル + file_assets.source 列
- repositories/AttachmentRepository + services/AttachmentService: 添付紐付け(プロジェクト/アップロード者チェック)
- FileStorageService.uploadForAttachment: 通知/SSE/アクティビティを行わない添付専用アップロード(source='attachment')
- ChatService/BoardService: fileIds 受理・添付紐付け・履歴/詳細表示・削除クリーンアップ(トランザクション)
- API: POST /attachments + chat/board の fileIds 受理
- UI: AttachmentList(画像サムネイル+Lightbox/ダウンロード) + AttachmentPicker(複数アップロード・送信中は送信不可) をチャット/スレッド/コメントに統合
- 添付ファイルは既存の /api/files/[fileId]/download(権限チェック済)で配信
This commit is contained in:
Ken Yasue
2026-06-25 10:07:02 +02:00
parent c747978f3d
commit 25d800a529
31 changed files with 1640 additions and 102 deletions

View File

@ -18,6 +18,8 @@ import { TodoService } from '@/services/TodoService';
import { TodoRepository } from '@/repositories/TodoRepository';
import { FileStorageService } from '@/services/FileStorageService';
import { FileRepository } from '@/repositories/FileRepository';
import { AttachmentService } from '@/services/AttachmentService';
import { AttachmentRepository } from '@/repositories/AttachmentRepository';
import { ScheduleService } from '@/services/ScheduleService';
import { CalendarRepository } from '@/repositories/CalendarRepository';
import { MilestoneRepository } from '@/repositories/MilestoneRepository';
@ -51,11 +53,18 @@ export function createActivityLogService(): ActivityLogService {
export function createBoardService(): BoardService {
const db = getDb();
const memberRepo = new ProjectMemberRepository(db);
return new BoardService(
new BoardRepository(db),
new ProjectMemberRepository(db),
memberRepo,
new NotificationService(new NotificationRepository(db)),
new ActivityLogService(new ActivityLogRepository(db))
new ActivityLogService(new ActivityLogRepository(db)),
new AttachmentService(
new AttachmentRepository(db),
new FileRepository(db),
memberRepo
),
db
);
}
@ -71,12 +80,19 @@ export function createNoteService(): NoteService {
export function createChatService(): ChatService {
const db = getDb();
const memberRepo = new ProjectMemberRepository(db);
return new ChatService(
new ChatRepository(db),
new ProjectMemberRepository(db),
memberRepo,
new UserRepository(db),
new NotificationService(new NotificationRepository(db)),
getSseHub()
getSseHub(),
new AttachmentService(
new AttachmentRepository(db),
new FileRepository(db),
memberRepo
),
db
);
}

View File

@ -0,0 +1,22 @@
-- 002_attachments.sql
-- チャット/掲示板への添付ファイル関連付けテーブルと、file_assets の来源区分。
-- 11. attachments: メッセージ/スレッド/コメント と file_assets の多対多関連
CREATE TABLE attachments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_id INTEGER NOT NULL,
file_id INTEGER NOT NULL,
target_type TEXT NOT NULL,
target_id INTEGER NOT NULL,
created_at TEXT NOT NULL,
deleted_at TEXT,
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
FOREIGN KEY (file_id) REFERENCES file_assets(id)
);
CREATE INDEX idx_attachments_target ON attachments(target_type, target_id);
CREATE INDEX idx_attachments_file ON attachments(file_id);
-- file_assets に source 列を追加(ライブラリ公開 vs 添付専用)。
-- 既存レコードは 'library' となり Files 一覧にそのまま表示される。
ALTER TABLE file_assets ADD COLUMN source TEXT NOT NULL DEFAULT 'library';

View File

@ -141,10 +141,47 @@ export interface FileAsset {
mimeType: string;
size: number;
path: string;
source: FileAssetSource;
createdAt: string;
deletedAt: string | null;
}
/** ファイルの来源。library=Files一覧公開、attachment=添付専用(一覧に出さない)。 */
export type FileAssetSource = 'library' | 'attachment';
/** 添付ファイルの関連付け対象。 */
export type AttachmentTargetType =
| 'chat_message'
| 'board_thread'
| 'board_comment';
/** attachments エンティティ。 */
export interface Attachment {
id: number;
projectId: number;
fileId: number;
targetType: AttachmentTargetType;
targetId: number;
createdAt: string;
deletedAt: string | null;
}
/** UI表示用の添付ファイルビュー(ダウンロードURLは fileId から組み立てる)。 */
export interface AttachmentView {
id: number;
fileId: number;
targetType: AttachmentTargetType;
targetId: number;
originalName: string;
mimeType: string;
size: number;
}
/** チャットメッセージ + 添付ファイル。 */
export interface ChatMessageWithAttachments extends ChatMessage {
attachments: AttachmentView[];
}
export interface ProjectNote {
id: number;
projectId: number;
@ -281,7 +318,10 @@ export type NotificationEvent =
export type SseEvent =
| {
type: 'chat.message.created';
data: { projectId: number; message: ChatMessage };
data: {
projectId: number;
message: ChatMessageWithAttachments;
};
}
| {
type: 'chat.message.updated';