cloudflare-image-mcp
Version:
Cloudflare Workers AI Image Generator MCP Server
30 lines • 1.21 kB
JavaScript
export class BaseStorageProvider {
config;
constructor(config) {
this.config = config;
}
generateFilename(size) {
const shortUuid = Math.random().toString(36).substring(2, 8);
const sizePart = size ? `_${size}` : '';
return `${shortUuid}${sizePart}.jpg`;
}
generateModelPath(model, filename) {
// Extract model name from full model path (e.g., "@cf/black-forest-labs/flux-1-schnell" -> "flux-schnell")
const modelName = model.split('/').pop() || 'unknown';
return `${modelName}/${filename}`;
}
formatFileSize(bytes) {
if (bytes === 0)
return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
extractModelFromFilename(key) {
// Extract model from path: "outputs/images/generations/2024-09-29/flux-schnell/abc123.jpg"
const match = key.match(/outputs\/images\/generations\/\d{4}-\d{2}-\d{2}\/([^/]+)\/[^/]+\.jpg$/);
return match ? match[1] : null;
}
}
//# sourceMappingURL=base-provider.js.map