From 70ea03be8142e80749c8fb2be5319dddb1cc8415 Mon Sep 17 00:00:00 2001 From: Mikael Araya Date: Tue, 26 Nov 2024 20:47:42 +0300 Subject: [PATCH] Update media upload endpoint to accept private flag --- .../assortments/prepareAssortmentMediaUpload.ts | 7 ++++++- .../products/prepareProductMediaUpload.ts | 3 ++- .../mutations/users/prepareUserAvatarUpload.ts | 3 ++- packages/api/src/schema/mutation.ts | 14 +++++++++++--- .../core/src/services/createSignedURLService.ts | 5 +++-- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/api/src/resolvers/mutations/assortments/prepareAssortmentMediaUpload.ts b/packages/api/src/resolvers/mutations/assortments/prepareAssortmentMediaUpload.ts index 2a6fc5c6e5..2408f681df 100644 --- a/packages/api/src/resolvers/mutations/assortments/prepareAssortmentMediaUpload.ts +++ b/packages/api/src/resolvers/mutations/assortments/prepareAssortmentMediaUpload.ts @@ -3,7 +3,11 @@ import { Context } from '../../../context.js'; export default async function prepareAssortmentMediaUpload( root: never, - { mediaName, assortmentId }: { mediaName: string; assortmentId: string }, + { + mediaName, + assortmentId, + asPrivate, + }: { mediaName: string; assortmentId: string; asPrivate?: boolean }, context: Context, ) { const { services, userId } = context; @@ -14,6 +18,7 @@ export default async function prepareAssortmentMediaUpload( directoryName: 'assortment-media', fileName: mediaName, meta: { assortmentId }, + isPrivate: Boolean(asPrivate), }, context, ); diff --git a/packages/api/src/resolvers/mutations/products/prepareProductMediaUpload.ts b/packages/api/src/resolvers/mutations/products/prepareProductMediaUpload.ts index 4efd1ca4da..1e568515bd 100644 --- a/packages/api/src/resolvers/mutations/products/prepareProductMediaUpload.ts +++ b/packages/api/src/resolvers/mutations/products/prepareProductMediaUpload.ts @@ -3,7 +3,7 @@ import { log } from '@unchainedshop/logger'; export default async function prepareProductMediaUpload( root: never, - { mediaName, productId }: { mediaName: string; productId: string }, + { mediaName, productId, asPrivate }: { mediaName: string; productId: string; asPrivate?: boolean }, context: Context, ) { const { services, userId } = context; @@ -14,6 +14,7 @@ export default async function prepareProductMediaUpload( directoryName: 'product-media', fileName: mediaName, meta: { productId }, + isPrivate: Boolean(asPrivate), }, context, ); diff --git a/packages/api/src/resolvers/mutations/users/prepareUserAvatarUpload.ts b/packages/api/src/resolvers/mutations/users/prepareUserAvatarUpload.ts index ed1127ffa6..281c83f4f0 100644 --- a/packages/api/src/resolvers/mutations/users/prepareUserAvatarUpload.ts +++ b/packages/api/src/resolvers/mutations/users/prepareUserAvatarUpload.ts @@ -3,7 +3,7 @@ import { log } from '@unchainedshop/logger'; export default async function prepareUserAvatarUpload( root: never, - params: { mediaName: string; userId: string }, + params: { mediaName: string; userId: string; asPrivate: boolean }, context: Context, ) { const { services, userId } = context; @@ -19,6 +19,7 @@ export default async function prepareUserAvatarUpload( directoryName: 'user-avatars', fileName: params.mediaName, meta: { userId: normalizedUserId }, + isPrivate: Boolean(params?.asPrivate), }, context, ); diff --git a/packages/api/src/schema/mutation.ts b/packages/api/src/schema/mutation.ts index 0b1c5cd8b0..e3777b5a63 100644 --- a/packages/api/src/schema/mutation.ts +++ b/packages/api/src/schema/mutation.ts @@ -852,9 +852,17 @@ export default [ """ signPaymentProviderForCheckout(orderPaymentId: ID, transactionContext: JSON): String! - prepareProductMediaUpload(mediaName: String!, productId: ID!): MediaUploadTicket! - prepareAssortmentMediaUpload(mediaName: String!, assortmentId: ID!): MediaUploadTicket! - prepareUserAvatarUpload(mediaName: String!, userId: ID): MediaUploadTicket! + prepareProductMediaUpload( + mediaName: String! + productId: ID! + asPrivate: Boolean + ): MediaUploadTicket! + prepareAssortmentMediaUpload( + mediaName: String! + assortmentId: ID! + asPrivate: Boolean + ): MediaUploadTicket! + prepareUserAvatarUpload(mediaName: String!, userId: ID, asPrivate: Boolean): MediaUploadTicket! confirmMediaUpload(mediaUploadTicketId: ID!, size: Int!, type: String!): Media! """ diff --git a/packages/core/src/services/createSignedURLService.ts b/packages/core/src/services/createSignedURLService.ts index 0b4e4837f1..a23f5eabf1 100644 --- a/packages/core/src/services/createSignedURLService.ts +++ b/packages/core/src/services/createSignedURLService.ts @@ -6,12 +6,12 @@ import { } from '@unchainedshop/core-files'; export type CreateSignedURLService = ( - params: { directoryName: string; fileName: string; meta?: any }, + params: { directoryName: string; fileName: string; meta?: any; isPrivate?: boolean }, unchainedAPI: { userId?: string; modules: { files: FilesModule } }, ) => Promise; export const createSignedURLService: CreateSignedURLService = async ( - { directoryName, fileName, meta }, + { directoryName, fileName, meta, isPrivate }, unchainedContext, ) => { const { @@ -23,6 +23,7 @@ export const createSignedURLService: CreateSignedURLService = async ( directoryName, fileName, unchainedContext, + Boolean(isPrivate), ); const fileData = getFileFromFileData(preparedFileData, { ...meta,