Skip to content

Commit

Permalink
added manual cache update for filename
Browse files Browse the repository at this point in the history
  • Loading branch information
Corepex committed Dec 13, 2024
1 parent 6e9c6b6 commit 8149e3b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion assets/build/api/docs.jsonopenapi.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
*/

import { type Asset, useAssetReplaceMutation } from '@Pimcore/modules/asset/asset-api-slice.gen'
import { type Asset, type AssetReplaceApiResponse, useAssetReplaceMutation } from '@Pimcore/modules/asset/asset-api-slice.gen'
import { type TreeNodeProps } from '@Pimcore/components/element-tree/node/tree-node'
import { type ItemType } from '@Pimcore/components/dropdown/dropdown'
import { useTranslation } from 'react-i18next'
import { Icon } from '@Pimcore/components/icon/icon'
import React from 'react'
import { useFormModal } from '@Pimcore/components/modal/form-modal/hooks/use-form-modal'
import { useMessage } from '@Pimcore/components/message/useMessage'
import { useCacheUpdate } from '@Pimcore/modules/element/hooks/use-cache-update'

export interface UseUploadNewVersionReturn {
uploadNewVersion: (id: number, accept?: string) => void
Expand All @@ -30,6 +31,7 @@ export const useUploadNewVersion = (): UseUploadNewVersionReturn => {
const { t } = useTranslation()
const modal = useFormModal()
const messageApi = useMessage()
const { updateFieldValue } = useCacheUpdate('asset', ['ASSET_TREE'])
const [replaceAsset] = useAssetReplaceMutation()

const uploadNewVersion = (id: number, accept?: string, onFinish?: () => void): void => {
Expand Down Expand Up @@ -65,6 +67,13 @@ export const useUploadNewVersion = (): UseUploadNewVersionReturn => {
if (response.error !== undefined) {
throw new Error(response.error.data.error as string)
}

const data = response.data as AssetReplaceApiResponse
updateFieldValue(
id,
'filename',
data.data
)
} catch (e: any) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
messageApi.error({
Expand Down
50 changes: 49 additions & 1 deletion assets/js/src/core/modules/asset/asset-api-slice.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,24 @@ const injectedRtkApi = api
}),
providesTags: ["Assets"],
}),
assetImageStreamCustom: build.query<AssetImageStreamCustomApiResponse, AssetImageStreamCustomApiArg>({
query: (queryArg) => ({
url: `/pimcore-studio/api/assets/${queryArg.id}/image/stream/custom`,
params: {
mimeType: queryArg.mimeType,
resizeMode: queryArg.resizeMode,
width: queryArg.width,
height: queryArg.height,
quality: queryArg.quality,
dpi: queryArg.dpi,
contain: queryArg.contain,
frame: queryArg.frame,
cover: queryArg.cover,
forceResize: queryArg.forceResize,
},
}),
providesTags: ["Assets"],
}),
assetImageDownloadByFormat: build.query<
AssetImageDownloadByFormatApiResponse,
AssetImageDownloadByFormatApiArg
Expand Down Expand Up @@ -600,6 +618,32 @@ export type AssetImageDownloadCustomApiArg = {
/** Dpi of downloaded image */
dpi?: number;
};
export type AssetImageStreamCustomApiResponse =
/** status 200 Image asset stream based on custom thumbnail configuration */ Blob;
export type AssetImageStreamCustomApiArg = {
/** Id of the image */
id: number;
/** Mime type of downloaded image. */
mimeType: "JPEG" | "PNG";
/** Resize mode of downloaded image. */
resizeMode: "resize" | "scaleByWidth" | "scaleByHeight";
/** Width of downloaded image */
width?: number;
/** Height of downloaded image */
height?: number;
/** Quality of downloaded image */
quality?: number;
/** Dpi of downloaded image */
dpi?: number;
/** Contain */
contain?: boolean;
/** Frame */
frame?: boolean;
/** Cover */
cover?: boolean;
/** ForceResize */
forceResize?: boolean;
};
export type AssetImageDownloadByFormatApiResponse = /** status 200 Image asset binary file based on format */ Blob;
export type AssetImageDownloadByFormatApiArg = {
/** Id of the image */
Expand Down Expand Up @@ -705,7 +749,10 @@ export type AssetUploadInfoApiArg = {
/** Name of the file to upload */
fileName: string;
};
export type AssetReplaceApiResponse = /** status 200 Successfully replaced asset binary */ void;
export type AssetReplaceApiResponse = /** status 200 File name of the successfully replaced asset */ {
/** new file name of the asset */
data: string;
};
export type AssetReplaceApiArg = {
/** Id of the asset */
id: number;
Expand Down Expand Up @@ -1110,6 +1157,7 @@ export const {
useAssetUpdateGridConfigurationMutation,
useAssetGetGridMutation,
useAssetImageDownloadCustomQuery,
useAssetImageStreamCustomQuery,
useAssetImageDownloadByFormatQuery,
useAssetImageStreamPreviewQuery,
useAssetImageDownloadByThumbnailQuery,
Expand Down

0 comments on commit 8149e3b

Please sign in to comment.