fix payloads for stringified data

This commit is contained in:
Mary Hipp 2024-08-12 15:16:22 -04:00
parent 9c732ac3b1
commit 6a01fce9c1
5 changed files with 13 additions and 26 deletions

View File

@ -43,9 +43,11 @@ export const StylePresetForm = ({
const handleClickSave = useCallback<SubmitHandler<StylePresetFormData>>( const handleClickSave = useCallback<SubmitHandler<StylePresetFormData>>(
async (data) => { async (data) => {
const payload = { const payload = {
data: {
name: data.name, name: data.name,
positive_prompt: data.positivePrompt, positive_prompt: data.positivePrompt,
negative_prompt: data.negativePrompt, negative_prompt: data.negativePrompt,
},
image: data.image, image: data.image,
}; };

View File

@ -10,8 +10,8 @@ import {
} from '@invoke-ai/ui-library'; } from '@invoke-ai/ui-library';
import { useStore } from '@nanostores/react'; import { useStore } from '@nanostores/react';
import { convertImageUrlToBlob } from 'common/util/convertImageUrlToBlob'; import { convertImageUrlToBlob } from 'common/util/convertImageUrlToBlob';
import type { PrefilledFormData } from 'features/stylePresets/store/stylePresetModal';
import { $stylePresetModalState } from 'features/stylePresets/store/stylePresetModal'; import { $stylePresetModalState } from 'features/stylePresets/store/stylePresetModal';
import type { PrefilledFormData } from 'features/stylePresets/store/types';
import { useCallback, useEffect, useMemo, useState } from 'react'; import { useCallback, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';

View File

@ -11,7 +11,7 @@ const initialState: StylePresetModalState = {
*/ */
export const $stylePresetModalState = atom<StylePresetModalState>(initialState); export const $stylePresetModalState = atom<StylePresetModalState>(initialState);
export type StylePresetModalState = { type StylePresetModalState = {
isModalOpen: boolean; isModalOpen: boolean;
updatingStylePresetId: string | null; updatingStylePresetId: string | null;
prefilledFormData: PrefilledFormData | null; prefilledFormData: PrefilledFormData | null;

View File

@ -1,16 +1,3 @@
export type StylePresetModalState = {
isModalOpen: boolean;
updatingStylePresetId: string | null;
prefilledFormData: PrefilledFormData | null;
};
export type PrefilledFormData = {
name: string;
positivePrompt: string;
negativePrompt: string;
imageUrl: string | null;
};
export type StylePresetState = { export type StylePresetState = {
activeStylePresetId: string | null; activeStylePresetId: string | null;
searchTerm: string; searchTerm: string;

View File

@ -37,15 +37,15 @@ export const stylePresetsApi = api.injectEndpoints({
}), }),
createStylePreset: build.mutation< createStylePreset: build.mutation<
paths['/api/v1/style_presets/']['post']['responses']['200']['content']['application/json'], paths['/api/v1/style_presets/']['post']['responses']['200']['content']['application/json'],
paths['/api/v1/style_presets/']['post']['requestBody']['content']['multipart/form-data'] { data: { name: string; positive_prompt: string; negative_prompt: string }; image: Blob | null }
>({ >({
query: ({ name, positive_prompt, negative_prompt, image }) => { query: ({ data, image }) => {
const formData = new FormData(); const formData = new FormData();
if (image) { if (image) {
formData.append('image', image); formData.append('image', image);
} }
formData.append('data', JSON.stringify({ name, positive_prompt, negative_prompt })); formData.append('data', JSON.stringify(data));
return { return {
url: buildStylePresetsUrl(), url: buildStylePresetsUrl(),
@ -60,16 +60,14 @@ export const stylePresetsApi = api.injectEndpoints({
}), }),
updateStylePreset: build.mutation< updateStylePreset: build.mutation<
paths['/api/v1/style_presets/i/{style_preset_id}']['patch']['responses']['200']['content']['application/json'], paths['/api/v1/style_presets/i/{style_preset_id}']['patch']['responses']['200']['content']['application/json'],
paths['/api/v1/style_presets/i/{style_preset_id}']['patch']['requestBody']['content']['multipart/form-data'] & { { data: { name: string; positive_prompt: string; negative_prompt: string }; image: Blob | null; id: string }
id: string;
}
>({ >({
query: ({ id, name, positive_prompt, negative_prompt, image }) => { query: ({ id, data, image }) => {
const formData = new FormData(); const formData = new FormData();
if (image) { if (image) {
formData.append('image', image); formData.append('image', image);
} }
formData.append('data', JSON.stringify({ name, positive_prompt, negative_prompt })); formData.append('data', JSON.stringify(data));
return { return {
url: buildStylePresetsUrl(`i/${id}`), url: buildStylePresetsUrl(`i/${id}`),