refactor: remove S3 file storage, part of team mode (P1.2)

Nothing created an S3FileStore outside team workspaces; team storage is
postponed with team mode (ADR-0003), so such workspaces use virtual storage.
@aws-sdk/client-s3 leaves core's dependencies.
This commit is contained in:
shumeiko.it
2026-10-24 12:09:05 +02:00
parent cb51ed0d28
commit 0cbde468a9
7 changed files with 4 additions and 564 deletions

View File

@@ -1,13 +1,10 @@
import path from 'node:path';
import { FsStorageProvider } from './fs-provider.js';
import { S3StorageProvider } from './s3-provider.js';
import type { StorageProvider } from './types.js';
import type { S3Config } from '@waggle/core';
export type { StorageProvider, FileEntry } from './types.js';
export { STANDARD_DIRS, MAX_UPLOAD_SIZE } from './types.js';
export { FsStorageProvider } from './fs-provider.js';
export { S3StorageProvider } from './s3-provider.js';
export { safePath, toRelativePath } from './security.js';
interface WorkspaceLike {
@@ -22,7 +19,8 @@ interface WorkspaceLike {
*
* - virtual: files in ~/.waggle/workspaces/{id}/files/ (app-managed)
* - local: user-specified directory on their machine (like Claude Code)
* - team: MinIO/S3 bucket shared across team members
* - team: shared team storage is part of team mode, which the community
* edition does not ship (ADR-0003); such workspaces use virtual storage
*/
export function getStorageProvider(workspace: WorkspaceLike, dataDir: string): StorageProvider {
switch (workspace.storageType) {
@@ -33,37 +31,7 @@ export function getStorageProvider(workspace: WorkspaceLike, dataDir: string): S
return new FsStorageProvider(workspace.storagePath, { denySensitive: true });
}
case 'team': {
const cfg = workspace.storageConfig;
// If S3 config is provided (team server sets this), use S3
if (cfg?.endpoint && cfg?.bucket && cfg?.accessKey && cfg?.secretKey) {
const s3Config: S3Config = {
endpoint: cfg.endpoint as string,
bucket: cfg.bucket as string,
accessKey: cfg.accessKey as string,
secretKey: cfg.secretKey as string,
prefix: cfg.prefix as string ?? `teams/${workspace.id}/`,
region: cfg.region as string | undefined,
};
return new S3StorageProvider(s3Config);
}
// Fallback: env-based MinIO config (dev docker-compose)
const env = process.env;
if (env.MINIO_ENDPOINT && env.MINIO_BUCKET) {
const s3Config: S3Config = {
endpoint: env.MINIO_ENDPOINT,
bucket: env.MINIO_BUCKET,
accessKey: env.MINIO_ACCESS_KEY ?? 'waggle',
secretKey: env.MINIO_SECRET_KEY ?? 'waggle_s3_dev',
prefix: `teams/${workspace.id}/`,
};
return new S3StorageProvider(s3Config);
}
// No S3 config — fall back to virtual
const virtualRoot = path.join(dataDir, 'workspaces', workspace.id, 'files');
return new FsStorageProvider(virtualRoot);
}
case 'team':
case 'virtual':
default: {
const virtualRoot = path.join(dataDir, 'workspaces', workspace.id, 'files');

View File

@@ -1,70 +0,0 @@
/**
* S3StorageProvider — adapts the core S3FileStore to the StorageProvider interface.
* Used for team workspace files backed by MinIO/S3.
*/
import { S3FileStore, type S3Config, type FileEntry as CoreFileEntry } from '@waggle/core';
import type { StorageProvider, FileEntry } from './types.js';
function coreToProvider(f: CoreFileEntry): FileEntry {
return {
name: f.name,
path: f.path,
type: f.isDirectory ? 'directory' : 'file',
size: f.size,
modifiedAt: f.modified,
};
}
export class S3StorageProvider implements StorageProvider {
private store: S3FileStore;
constructor(config: S3Config) {
this.store = new S3FileStore(config);
}
async list(dirPath: string): Promise<FileEntry[]> {
const files = await this.store.listFiles(dirPath);
return files.map(coreToProvider);
}
async read(filePath: string): Promise<Buffer> {
return this.store.readFile(filePath);
}
async write(filePath: string, data: Buffer): Promise<FileEntry> {
await this.store.writeFile(filePath, data);
return { name: filePath.split('/').pop() ?? filePath, path: filePath, type: 'file', size: data.length };
}
async delete(targetPath: string): Promise<void> {
await this.store.deleteFile(targetPath);
}
async move(from: string, to: string): Promise<FileEntry> {
await this.store.moveFile(from, to);
return { name: to.split('/').pop() ?? to, path: to, type: 'file' };
}
async copy(from: string, to: string): Promise<FileEntry> {
// S3 copy: read + write (S3FileStore doesn't have native copy)
const data = await this.store.readFile(from);
await this.store.writeFile(to, data);
return { name: to.split('/').pop() ?? to, path: to, type: 'file', size: data.length };
}
async mkdir(dirPath: string): Promise<FileEntry> {
// S3 doesn't have real directories — write a zero-byte marker
await this.store.writeFile(dirPath + '/.keep', Buffer.alloc(0));
return { name: dirPath.split('/').pop() ?? dirPath, path: dirPath, type: 'directory' };
}
async exists(targetPath: string): Promise<boolean> {
try {
await this.store.readFile(targetPath);
return true;
} catch {
return false;
}
}
}