-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace Altinn.Studio.Designer.Enums; | ||
|
||
/// <summary> | ||
/// ImageUrlValidationResult | ||
/// </summary> | ||
public enum ImageUrlValidationResult | ||
{ | ||
[EnumMember(Value = "Ok")] | ||
Ok, | ||
|
||
[EnumMember(Value = "NotAnImage")] | ||
NotAnImage, | ||
|
||
[EnumMember(Value = "Unathorized")] | ||
Unathorized, | ||
|
||
[EnumMember(Value = "NotValidUrl")] | ||
NotValidUrl | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace Altinn.Studio.Designer.TypedHttpClients.ImageClient; | ||
|
||
public class ImageClient | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
public ImageClient(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
} | ||
|
||
public async Task<HttpResponseMessage> ValidateUrlAsync(string url) | ||
{ | ||
try | ||
{ | ||
// Send a HEAD request to the URL to check if the resource exists and fetch the headers | ||
var request = new HttpRequestMessage(HttpMethod.Head, url); | ||
Check warning Code scanning / CodeQL Missing Dispose call on local IDisposable Warning
Disposable 'HttpRequestMessage' is created but not disposed.
|
||
var response = await _httpClient.SendAsync(request); | ||
|
||
// If the response status is not successful, return null | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
return null; | ||
} | ||
|
||
return response; | ||
} | ||
catch (UriFormatException) | ||
{ | ||
return null; | ||
} | ||
catch (InvalidOperationException) | ||
{ | ||
return null; | ||
} | ||
catch (HttpRequestException ex) | ||
Check warning on line 40 in backend/src/Designer/TypedHttpClients/ImageClient/ImageClient.cs GitHub Actions / Run integration tests against actual gitea and db
Check warning on line 40 in backend/src/Designer/TypedHttpClients/ImageClient/ImageClient.cs GitHub Actions / Run dotnet build and test (ubuntu-latest)
Check warning Code scanning / CodeQL Useless assignment to local variable Warning
This assignment to
ex Error loading related location Loading |
||
{ | ||
return null; | ||
} | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import type { UseQueryResult } from '@tanstack/react-query'; | ||
import { useServicesContext } from 'app-shared/contexts/ServicesContext'; | ||
import { QueryKey } from 'app-shared/types/QueryKey'; | ||
import {ExternalImageUrlValidationResponse} from "app-shared/types/api/ExternalImageUrlValidationResponse"; | ||
Check failure on line 5 in frontend/packages/shared/src/hooks/queries/useValidateImageExternalUrlQuery.ts GitHub Actions / Typechecking and linting
Check failure on line 5 in frontend/packages/shared/src/hooks/queries/useValidateImageExternalUrlQuery.ts GitHub Actions / Typechecking and linting
|
||
|
||
|
||
export const useValidateImageExternalUrlQuery = ( | ||
org: string, | ||
app: string, | ||
url: string, | ||
): UseQueryResult<ExternalImageUrlValidationResponse> => { | ||
const { validateImageFromExternalUrl } = useServicesContext(); | ||
return useQuery<ExternalImageUrlValidationResponse>({ | ||
queryKey: [QueryKey.ImageUrlValidation, org, app, url], | ||
queryFn: () => validateImageFromExternalUrl(org, app, url), | ||
staleTime: 0, | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type ExternalImageUrlValidationResponse = | ||
| 'Ok' | ||
| 'NotAnImage' | ||
| 'Unauthorized' | ||
| 'NotValidUrl'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
.missingUrl { | ||
font-style: italic; | ||
} | ||
|
||
.validationStatusContainer { | ||
margin: var(--fds-spacing-3); | ||
color: var(--fds-semantic-text-danger-default); | ||
} |