playing with AI import

This commit is contained in:
vabene1111
2025-01-20 09:40:22 +01:00
parent a56c7c29a6
commit e0b414d8e9
10 changed files with 234 additions and 1974 deletions

View File

@@ -1,7 +1,7 @@
import {useDjangoUrls} from "@/composables/useDjangoUrls";
import {ref} from "vue";
import {getCookie} from "@/utils/cookie";
import {RecipeImageFromJSON, UserFile, UserFileFromJSON} from "@/openapi";
import {RecipeFromJSON, RecipeFromSourceFromJSON, RecipeFromSourceResponseFromJSON, RecipeImageFromJSON, UserFile, UserFileFromJSON} from "@/openapi";
import {ErrorMessageType, PreparedMessage, useMessageStore} from "@/stores/MessageStore";
/**
@@ -76,5 +76,28 @@ export function useFileApi() {
})
}
return {fileApiLoading, createOrUpdateUserFile, updateRecipeImage}
/**
* uploads the given file to the image recognition endpoint
* @param file file object to upload
*/
function convertImageToRecipe(file: File){
let formData = new FormData()
if (file != null) {
formData.append('image', file)
}
return fetch(getDjangoUrl(`api/image-to-recipe/`), {
method: 'POST',
headers: {'X-CSRFToken': getCookie('csrftoken')},
body: formData
}).then(r => {
return r.json().then(r => {
return RecipeFromSourceResponseFromJSON(r)
})
}).finally(() => {
fileApiLoading.value = false
})
}
return {fileApiLoading, createOrUpdateUserFile, updateRecipeImage, convertImageToRecipe}
}