Skip to content

Commit

Permalink
Update media upload endpoint to accept private flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikearaya authored and pozylon committed Dec 13, 2024
1 parent 5cc84c1 commit 70ea03b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +18,7 @@ export default async function prepareAssortmentMediaUpload(
directoryName: 'assortment-media',
fileName: mediaName,
meta: { assortmentId },
isPrivate: Boolean(asPrivate),
},
context,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +14,7 @@ export default async function prepareProductMediaUpload(
directoryName: 'product-media',
fileName: mediaName,
meta: { productId },
isPrivate: Boolean(asPrivate),
},
context,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +19,7 @@ export default async function prepareUserAvatarUpload(
directoryName: 'user-avatars',
fileName: params.mediaName,
meta: { userId: normalizedUserId },
isPrivate: Boolean(params?.asPrivate),
},
context,
);
Expand Down
14 changes: 11 additions & 3 deletions packages/api/src/schema/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!
"""
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/services/createSignedURLService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SignedFileUpload>;

export const createSignedURLService: CreateSignedURLService = async (
{ directoryName, fileName, meta },
{ directoryName, fileName, meta, isPrivate },
unchainedContext,
) => {
const {
Expand All @@ -23,6 +23,7 @@ export const createSignedURLService: CreateSignedURLService = async (
directoryName,
fileName,
unchainedContext,
Boolean(isPrivate),
);
const fileData = getFileFromFileData(preparedFileData, {
...meta,
Expand Down

0 comments on commit 70ea03b

Please sign in to comment.