fix(medusa,file-local,file-s3,core-flows): fix csv parsing special characters (#13649)
* fix(): fix csv parsing special characters * remove other tries * tweak * remove comments * Create rude-mirrors-hang.md
This commit is contained in:
1 parent
5c77b10fa6
commit
bb08edd41f
5 files changed
+38
-5
No files matched your search
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
"@medusajs/file-local": patch
|
||||||
|
"@medusajs/file-s3": patch
|
||||||
|
"@medusajs/core-flows": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(medusa,file-local,file-s3,core-flows): fix csv parsing special characters
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import { parse, Parser } from "csv-parse"
|
import { parse, Parser } from "csv-parse"
|
||||||
import type { HttpTypes, IFileModuleService } from "@medusajs/framework/types"
|
import type { HttpTypes, IFileModuleService } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
Modules,
|
|
||||||
CSVNormalizer,
|
CSVNormalizer,
|
||||||
|
Modules,
|
||||||
productValidators,
|
productValidators,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The CSV file content to parse.
|
* The CSV file content to parse.
|
||||||
@@ -203,6 +203,7 @@ export const normalizeCsvToChunksStep = createStep(
|
|||||||
try {
|
try {
|
||||||
const file = container.resolve(Modules.FILE)
|
const file = container.resolve(Modules.FILE)
|
||||||
const contents = await file.getDownloadStream(fileKey)
|
const contents = await file.getDownloadStream(fileKey)
|
||||||
|
|
||||||
const transformer = parse({
|
const transformer = parse({
|
||||||
columns: true,
|
columns: true,
|
||||||
skip_empty_lines: true,
|
skip_empty_lines: true,
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export const POST = async (
|
|||||||
files: input?.map((f) => ({
|
files: input?.map((f) => ({
|
||||||
filename: f.originalname,
|
filename: f.originalname,
|
||||||
mimeType: f.mimetype,
|
mimeType: f.mimetype,
|
||||||
content: f.buffer.toString("binary"),
|
content: f.buffer.toString("base64"),
|
||||||
access: "public",
|
access: "public",
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -57,7 +57,19 @@ export class LocalFileService extends AbstractFileProviderService {
|
|||||||
const filePath = this.getUploadFilePath(baseDir, fileKey)
|
const filePath = this.getUploadFilePath(baseDir, fileKey)
|
||||||
const fileUrl = this.getUploadFileUrl(fileKey)
|
const fileUrl = this.getUploadFileUrl(fileKey)
|
||||||
|
|
||||||
const content = Buffer.from(file.content as string, "binary")
|
let content: Buffer
|
||||||
|
try {
|
||||||
|
const decoded = Buffer.from(file.content, "base64")
|
||||||
|
if (decoded.toString("base64") === file.content) {
|
||||||
|
content = decoded
|
||||||
|
} else {
|
||||||
|
content = Buffer.from(file.content, "utf8")
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Last-resort fallback: binary
|
||||||
|
content = Buffer.from(file.content, "binary")
|
||||||
|
}
|
||||||
|
|
||||||
await fs.writeFile(filePath, content)
|
await fs.writeFile(filePath, content)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -120,7 +120,19 @@ export class S3FileService extends AbstractFileProviderService {
|
|||||||
parsedFilename.ext
|
parsedFilename.ext
|
||||||
}`
|
}`
|
||||||
|
|
||||||
const content = Buffer.from(file.content, "binary")
|
let content: Buffer
|
||||||
|
try {
|
||||||
|
const decoded = Buffer.from(file.content, "base64")
|
||||||
|
if (decoded.toString("base64") === file.content) {
|
||||||
|
content = decoded
|
||||||
|
} else {
|
||||||
|
content = Buffer.from(file.content, "utf8")
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Last-resort fallback: binary
|
||||||
|
content = Buffer.from(file.content, "binary")
|
||||||
|
}
|
||||||
|
|
||||||
const command = new PutObjectCommand({
|
const command = new PutObjectCommand({
|
||||||
// We probably also want to support a separate bucket altogether for private files
|
// We probably also want to support a separate bucket altogether for private files
|
||||||
// protected private_bucket_: string
|
// protected private_bucket_: string
|
||||||
|
|||||||
Reference in new issue
Block a user