mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2025-12-24 02:39:20 -05:00
Merge branch 'develop' into feature/vue3
# Conflicts: # cookbook/views/api.py
This commit is contained in:
@@ -1697,17 +1697,22 @@ class RecipeUrlImportView(APIView):
|
||||
|
||||
url = serializer.validated_data.get('url', None)
|
||||
data = unquote(serializer.validated_data.get('data', None))
|
||||
|
||||
duplicate = False
|
||||
if url:
|
||||
# Check for existing recipes with provided url
|
||||
existing_recipe = Recipe.objects.filter(source_url=url).first()
|
||||
if existing_recipe:
|
||||
duplicate = True
|
||||
|
||||
if not url and not data:
|
||||
return Response({'error': True, 'msg': _('Nothing to do.')}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
elif url and not data:
|
||||
if re.match('^(https?://)?(www\\.youtube\\.com|youtu\\.be)/.+$', url):
|
||||
if validate_import_url(url):
|
||||
return Response({'recipe_json': get_from_youtube_scraper(url, request), 'recipe_images': [], },
|
||||
status=status.HTTP_200_OK)
|
||||
if re.match(
|
||||
'^(.)*/view/recipe/[0-9]+/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$',
|
||||
url):
|
||||
return Response({'recipe_json': get_from_youtube_scraper(url, request), 'recipe_images': [], 'duplicate': duplicate}, status=status.HTTP_200_OK)
|
||||
if re.match('^(.)*/view/recipe/[0-9]+/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$', url):
|
||||
recipe_json = requests.get(
|
||||
url.replace('/view/recipe/', '/api/recipe/').replace(re.split('/view/recipe/[0-9]+', url)[1],
|
||||
'') + '?share='
|
||||
@@ -1724,8 +1729,7 @@ class RecipeUrlImportView(APIView):
|
||||
filetype=pathlib.Path(recipe_json['image']).suffix),
|
||||
name=f'{uuid.uuid4()}_{recipe.pk}{pathlib.Path(recipe_json["image"]).suffix}')
|
||||
recipe.save()
|
||||
return Response({'link': request.build_absolute_uri(reverse('view_recipe', args={recipe.pk}))},
|
||||
status=status.HTTP_201_CREATED)
|
||||
return Response({'link': request.build_absolute_uri(reverse('view_recipe', args={recipe.pk})), 'duplicate': duplicate}, status=status.HTTP_201_CREATED)
|
||||
else:
|
||||
try:
|
||||
if validate_import_url(url):
|
||||
@@ -1764,6 +1768,7 @@ class RecipeUrlImportView(APIView):
|
||||
return Response({
|
||||
'recipe_json': helper.get_from_scraper(scrape, request),
|
||||
'recipe_images': list(dict.fromkeys(get_images_from_soup(scrape.soup, url))),
|
||||
'duplicate': duplicate
|
||||
},
|
||||
status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
@@ -83,6 +83,11 @@
|
||||
<loading-spinner></loading-spinner>
|
||||
</b-card>
|
||||
|
||||
<!-- Warnings -->
|
||||
<b-card no-body v-if="duplicateWarning" class="warning">
|
||||
{{ duplicateWarning }}
|
||||
</b-card>
|
||||
|
||||
<!-- OPTIONS -->
|
||||
<b-card no-body v-if="recipe_json !== undefined">
|
||||
<b-card-header header-tag="header" class="p-1" role="tab">
|
||||
@@ -463,6 +468,7 @@ export default {
|
||||
},
|
||||
// URL import
|
||||
LS_IMPORT_RECENT: 'import_recent_urls', //TODO use central helper to manage all local storage keys (and maybe even access)
|
||||
duplicateWarning: '',
|
||||
website_url: '',
|
||||
website_url_list: '',
|
||||
import_multiple: false,
|
||||
@@ -643,6 +649,12 @@ export default {
|
||||
return
|
||||
}
|
||||
|
||||
if ('duplicate' in response.data && response.data['duplicate']) {
|
||||
this.duplicateWarning = "A recipe with this URL already exists.";
|
||||
} else {
|
||||
this.duplicateWarning = "";
|
||||
}
|
||||
|
||||
this.loading = false
|
||||
this.recipe_json = response.data['recipe_json'];
|
||||
|
||||
@@ -763,6 +775,16 @@ export default {
|
||||
|
||||
<style>
|
||||
|
||||
.warning {
|
||||
color: rgb(255, 149, 0);
|
||||
align-items: center;
|
||||
background-color: #fff4ec;
|
||||
padding: 10px;
|
||||
border: 1px solid rgb(255, 149, 0);
|
||||
border-radius: 5px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.bounce {
|
||||
animation: bounce 0.82s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
|
||||
transform: translate3d(0, 0, 0);
|
||||
|
||||
Reference in New Issue
Block a user