feat(domain,application,infrastructure,backend,web-server,app-tauri,frontend): bibliothèque d'icônes projet personnalisées importées par l'utilisateur — #358 (QA verte)
domain: variante ProjectIconSet::Custom, métadonnées CustomProjectIconAsset (id opaque, media type png/jpeg/webp, byte_size, dimensions décodées, sha256, nom de fichier original sans chemin, created_at), CustomProjectIconContent et port CustomProjectIconAssetStore (list/read/exists/create/delete) avec CustomProjectIconStoreError dédiée. application: use case project_icon_assets — import validé png/jpeg/webp avec rejet du contenu SVG, dimensionnement et digest sha256, bibliothèque partagée à l'instance indépendante de tout projet, suppression refusée tant que l'asset est référencé par un projet. infrastructure: store fichier store/project_icon_asset.rs — index canonique + octets, création atomique sous extension validée. backend/web-server: contrat HTTP /api/project-icon-assets (GET liste, POST import, GET lecture, GET /usage, DELETE) avec prévol OPTIONS et tests contrat incluant le rejet SVG. app-tauri: commandes import/list/read/get_usage/delete_custom_project_icon_asset exposées au frontend. frontend: port ProjectIconAssetGateway (list/import/delete/getUrl sans exposer de chemin filesystem), gateways http+mock avec tests, DI, section Icônes personnalisées du ProjectIconPicker (import fichier accept png/jpeg/webp, sélection role=option, suppression avec retrait de sélection, erreurs lisibles i18n FR/EN), tests projectIcons étendus. QA verte: contrats HTTP et Tauri identiques, suites cargo et npm ciblées vertes.
This commit is contained in:
@ -138,6 +138,8 @@ import type {
|
||||
OpenTerminalOptions,
|
||||
ProfileGateway,
|
||||
ProjectGateway,
|
||||
ProjectIconAssetGateway,
|
||||
CustomProjectIconAsset,
|
||||
ProjectSettings,
|
||||
PermissionGateway,
|
||||
PluginConfigDocumentReadInput,
|
||||
@ -1287,6 +1289,59 @@ export class MockTerminalGateway implements TerminalGateway {
|
||||
}
|
||||
}
|
||||
|
||||
export class MockProjectIconAssetGateway implements ProjectIconAssetGateway {
|
||||
private readonly assets = new Map<string, CustomProjectIconAsset>();
|
||||
private readonly urls = new Map<string, string>();
|
||||
private sequence = 0;
|
||||
|
||||
async list(): Promise<CustomProjectIconAsset[]> {
|
||||
return [...this.assets.values()].map((asset) => ({ ...asset }));
|
||||
}
|
||||
|
||||
async import(file: File): Promise<CustomProjectIconAsset> {
|
||||
if (!["image/png", "image/jpeg", "image/webp"].includes(file.type)) {
|
||||
throw { code: "INVALID_ICON_MEDIA_TYPE", message: "PNG, JPEG or WebP required" } as GatewayError;
|
||||
}
|
||||
if (file.size > 2 * 1024 * 1024) {
|
||||
throw { code: "ICON_TOO_LARGE", message: "Icon exceeds 2 MiB" } as GatewayError;
|
||||
}
|
||||
const id = `mock-icon-${++this.sequence}`;
|
||||
const asset: CustomProjectIconAsset = {
|
||||
id,
|
||||
mediaType: file.type as CustomProjectIconAsset["mediaType"],
|
||||
byteSize: file.size,
|
||||
width: 0,
|
||||
height: 0,
|
||||
sha256: `mock-${id}`,
|
||||
originalFilename: file.name,
|
||||
createdAt: Date.now(),
|
||||
usedByProjectCount: 0,
|
||||
};
|
||||
this.assets.set(id, asset);
|
||||
const createObjectURL = URL.createObjectURL?.bind(URL);
|
||||
this.urls.set(id, createObjectURL ? createObjectURL(file) : `data:${file.type};base64,`);
|
||||
return { ...asset };
|
||||
}
|
||||
|
||||
async delete(assetId: string): Promise<void> {
|
||||
const asset = this.assets.get(assetId);
|
||||
if (!asset) throw { code: "NOT_FOUND", message: `icon ${assetId} not found` } as GatewayError;
|
||||
if (asset.usedByProjectCount > 0) {
|
||||
throw { code: "CUSTOM_ICON_IN_USE", message: `icon is used by ${asset.usedByProjectCount} projects` } as GatewayError;
|
||||
}
|
||||
const url = this.urls.get(assetId);
|
||||
if (url?.startsWith("blob:")) URL.revokeObjectURL?.(url);
|
||||
this.assets.delete(assetId);
|
||||
this.urls.delete(assetId);
|
||||
}
|
||||
|
||||
async getUrl(assetId: string): Promise<string> {
|
||||
const url = this.urls.get(assetId);
|
||||
if (!url) throw { code: "NOT_FOUND", message: `icon ${assetId} not found` } as GatewayError;
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
export class MockProjectGateway implements ProjectGateway {
|
||||
private projects: Project[] = [];
|
||||
private contexts = new Map<string, string>();
|
||||
@ -5002,6 +5057,7 @@ export function createMockGateways(): Gateways {
|
||||
input: new MockInputGateway(),
|
||||
terminal: new MockTerminalGateway(),
|
||||
project: new MockProjectGateway(),
|
||||
projectIconAsset: new MockProjectIconAssetGateway(),
|
||||
layout: new MockLayoutGateway(),
|
||||
git: new MockGitGateway(),
|
||||
remote: new MockRemoteGateway(),
|
||||
|
||||
Reference in New Issue
Block a user