-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
docs: updates to digital product recipe #9165
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
|
www/apps/resources/app/recipes/digital-products/examples/standard/page.mdx
Outdated
Show resolved
Hide resolved
Was the recipe changed otherwise? Was having an issue when uploading, had to add multer on the api path for upload. Now i'm having an issue with type CreateRequestBody = z.infer<typeof createDigitalProductsSchema>;
export const POST = async (
req: AuthenticatedMedusaRequest<CreateRequestBody>,
res: MedusaResponse
) => {
const { result } = await createDigitalProductWorkflow(req.scope).run({
input: {
digital_product: {
name: req.validatedBody.name,
medias: req.validatedBody.medias.map((media) => ({
fileId: media.file_id,
mimeType: media.mime_type,
...media,
})) as Omit<CreateDigitalProductMediaInput, "digital_product_id">[],
},
product: req.validatedBody.product,
},
});
res.json({
digital_product: result.digital_product,
});
}; Not sure why middleware.ts wasn't applying the multer, but Modified api to use multer, now uploads work, but it dies on verificationBody as mentioned above import multer from "multer";
import { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/medusa";
import { uploadFilesWorkflow } from "@medusajs/core-flows";
import { MedusaError } from "@medusajs/utils";
const upload = multer({ storage: multer.memoryStorage() });
export const uploadMiddleware = upload.array("files");
export const POST = async (
req: AuthenticatedMedusaRequest,
res: MedusaResponse
) => {
uploadMiddleware(req as any, res as any, async (err: any) => {
if (err) {
console.error("Error handling file upload:", err);
return res.status(500).json({ error: "File upload failed" });
}
const access = req.params.type === "main" ? "private" : "public";
const input = req.files as Express.Multer.File[];
if (!input?.length) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"No files were uploaded"
);
}
const { result } = await uploadFilesWorkflow(req.scope).run({
input: {
files: input?.map((f) => ({
filename: f.originalname,
mimeType: f.mimetype,
content: f.buffer.toString("binary"),
access,
})),
},
});
res.status(200).json({ files: result });
});
}; |
@420coupe This is already part of the recipe.
there was an issue with middlewares in a preview version we released yesterday. Can you update and try again? |
Tyvm, been chasing my tail all day trying to figure out why. found another small bug, when deleting a digital product from the product section, it doesn't delete the digital product and then causes an error when going to digital products on adminui |
also you never attach the digital product in the notification. |
@420coupe We instead retrieve the URLs of all digital products and pass them in the notification's payload. You're free to do it differently if that's your use case. |
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.
LGTM, nice!
digital_product_order.created
event to use the workflow