Repository navigation
Revamp UI ux #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revamp UI ux #18
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| ADMIN_USERNAME=admin | ||
| ADMIN_PASSWORD=admin123 | ||
| ADMIN_SESSION_SECRET=troque-este-segredo-longo-e-aleatorio | ||
| NEXT_PUBLIC_GA_MEASUREMENT_ID= | ||
| NEXT_PUBLIC_SITE_URL=localhost | ||
| NEXT_PUBLIC_SUPABASE_URL=https://agpvwjbymwruxkfkgkuh.supabase.co | ||
| NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=sb_publishable_mVyiCPd1hZ-rDlU_pNQqwg_sXg9ix0m | ||
| SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImFncHZ3amJ5bXdydXhrZmtna3VoIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc3MzkxNjUxOSwiZXhwIjoyMDg5NDkyNTE5fQ.2JR_xgKAKkTZjjWci1ddevh-IXv13rg0-EwuHI-YxSU | ||
| SUPABASE_STORAGE_BUCKET_PRODUCTS=product-images | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { adminJson, requireAdminRequest } from "@/lib/admin-route"; | ||
| import { | ||
| CatalogRepositoryConfigError, | ||
| CatalogRepositoryValidationError, | ||
| deleteProductsFromCatalog, | ||
| } from "@/lib/catalog-repository"; | ||
|
|
||
| export const runtime = "nodejs"; | ||
|
|
||
| export async function POST(request) { | ||
| const unauthorized = requireAdminRequest(request); | ||
| if (unauthorized) { | ||
| return unauthorized; | ||
| } | ||
|
|
||
| let payload; | ||
| try { | ||
| payload = await request.json(); | ||
| } catch { | ||
| return adminJson({ error: "Payload invalido. Envie uma lista de produtos para excluir." }, 400); | ||
| } | ||
|
|
||
| try { | ||
| const result = await deleteProductsFromCatalog(payload?.productIds); | ||
| return adminJson({ | ||
| catalog: result.catalog, | ||
| removedCount: result.removedCount, | ||
| }); | ||
| } catch (error) { | ||
| if (error instanceof CatalogRepositoryValidationError) { | ||
| return adminJson({ error: error.message }, 400); | ||
| } | ||
|
|
||
| if (error instanceof CatalogRepositoryConfigError) { | ||
| return adminJson({ error: error.message }, 503); | ||
| } | ||
|
|
||
| return adminJson({ error: "Erro interno ao excluir os produtos selecionados." }, 500); | ||
| } | ||
| } | ||
|
Comment on lines
+10
to
+40
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { adminJson, requireAdminRequest } from "@/lib/admin-route"; | ||
| import { parseProductsCsvImport } from "@/lib/products-csv-import"; | ||
| import { | ||
| CatalogRepositoryConfigError, | ||
| CatalogRepositoryValidationError, | ||
| importProductsCsvInCatalog, | ||
| } from "@/lib/catalog-repository"; | ||
|
|
||
| export const runtime = "nodejs"; | ||
|
|
||
| function getUploadedFile(formData) { | ||
| const file = formData.get("file"); | ||
| if (!file || typeof file.text !== "function") { | ||
| throw new CatalogRepositoryValidationError("Selecione um arquivo CSV valido para importar."); | ||
| } | ||
|
|
||
| return file; | ||
| } | ||
|
|
||
| export async function POST(request) { | ||
| const unauthorized = requireAdminRequest(request); | ||
| if (unauthorized) { | ||
| return unauthorized; | ||
| } | ||
|
|
||
| let formData; | ||
| try { | ||
| formData = await request.formData(); | ||
| } catch { | ||
| return adminJson({ error: "Nao foi possivel ler o formulario de importacao." }, 400); | ||
| } | ||
|
|
||
| try { | ||
| const file = getUploadedFile(formData); | ||
| const csvContent = await file.text(); | ||
| const parsedImport = parseProductsCsvImport(csvContent, { | ||
| imagesMode: "blank", | ||
| missingPriceMode: "skip", | ||
| }); | ||
|
Comment on lines
+33
to
+39
|
||
| const result = await importProductsCsvInCatalog(parsedImport); | ||
|
|
||
| return adminJson({ | ||
| catalog: result.catalog, | ||
| summary: result.summary, | ||
| }); | ||
| } catch (error) { | ||
| if (error instanceof CatalogRepositoryValidationError) { | ||
| return adminJson({ error: error.message }, 400); | ||
| } | ||
|
|
||
| if (error instanceof CatalogRepositoryConfigError) { | ||
| return adminJson({ error: error.message }, 503); | ||
| } | ||
|
|
||
| return adminJson({ error: "Erro interno ao importar o CSV." }, 500); | ||
| } | ||
| } | ||
|
Comment on lines
+20
to
+57
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arquivo
.env.localfoi incluído no repositório contendo credenciais reais (ADMIN_PASSWORD, ADMIN_SESSION_SECRET) e principalmenteSUPABASE_SERVICE_ROLE_KEY(chave privilegiada). Isso é um vazamento de segredo: remova o arquivo do PR (use.env.example/docs para valores fictícios) e faça rotação imediata dessas chaves no Supabase/ambiente de deploy.