style: clean up code formatting and remove trailing whitespace
refactor: reorganize imports and fix type imports
This commit is contained in:
1 parent
d3704602fd
commit
47c04de6fe
232 files changed
+7140
-4798
No files matched your search
+17
-10
@@ -19,11 +19,14 @@ export const ptToEnCategoryMap: Record<string, string> = {
|
||||
|
||||
// Mapeamento inverso EN -> PT para resolver caminho das imagens
|
||||
export const enToPtCategoryMap: Record<string, string> = Object.entries(
|
||||
ptToEnCategoryMap
|
||||
).reduce((acc, [pt, en]) => {
|
||||
acc[en] = pt;
|
||||
return acc;
|
||||
}, {} as Record<string, string>);
|
||||
ptToEnCategoryMap,
|
||||
).reduce(
|
||||
(acc, [pt, en]) => {
|
||||
acc[en] = pt;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, string>,
|
||||
);
|
||||
|
||||
function normalizeFilenameSegment(value: string): string {
|
||||
// Normaliza para casar melhor com nomes de arquivo: remove acentos e espaços extras
|
||||
@@ -38,12 +41,15 @@ function normalizeFilenameSegment(value: string): string {
|
||||
* Constrói um caminho relativo para a imagem do item dentro de data/images.
|
||||
* Retorna um caminho relativo utilizável em fs ou para um handler que sirva arquivos estáticos.
|
||||
*/
|
||||
export function buildItemImagePath(categoryEn: string, fileName: string): string {
|
||||
export function buildItemImagePath(
|
||||
categoryEn: string,
|
||||
fileName: string,
|
||||
): string {
|
||||
const ptFolder = enToPtCategoryMap[categoryEn] ?? "outros";
|
||||
// Mantém o nome original caso já esteja correto; fallback para nome normalizado
|
||||
const safeFileName = fileName || "";
|
||||
const normalized = normalizeFilenameSegment(
|
||||
safeFileName.replace(/\.(gif|png|jpg|jpeg|webp)$/i, "")
|
||||
safeFileName.replace(/\.(gif|png|jpg|jpeg|webp)$/i, ""),
|
||||
);
|
||||
// Tenta .gif como padrão (ajuste se necessário)
|
||||
const finalFile = safeFileName || `${normalized}.gif`;
|
||||
@@ -54,10 +60,11 @@ export function buildItemImagePath(categoryEn: string, fileName: string): string
|
||||
* Resolve a URL pública para a imagem, caso exista um handler ou static serving configurado.
|
||||
* Por padrão, apontamos para um API proxy que servirá o arquivo do filesystem.
|
||||
*/
|
||||
export function buildPublicItemImageUrl(categoryEn: string, fileName: string): string {
|
||||
export function buildPublicItemImageUrl(
|
||||
categoryEn: string,
|
||||
fileName: string,
|
||||
): string {
|
||||
const relativePath = buildItemImagePath(categoryEn, fileName);
|
||||
// Ex.: /api/images?path=data/images/espadas/sword.gif
|
||||
return `/api/images?path=${encodeURIComponent(relativePath)}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user