Skip to content

Commit

Permalink
#25959 Fixing method to validate if the image does not exits
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelrojas committed Oct 11, 2023
1 parent 9b68649 commit b655830
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
Expand Up @@ -2,7 +2,7 @@ import { Observable, forkJoin, from, of } from 'rxjs';

import { Injectable } from '@angular/core';

import { map, switchMap } from 'rxjs/operators';
import { catchError, map, mergeMap, switchMap } from 'rxjs/operators';

import { DotMessageService, DotUploadService } from '@dotcms/data-access';
import { DotCMSTempFile } from '@dotcms/dotcms-models';
Expand Down Expand Up @@ -758,23 +758,39 @@ export class DotSeoMetaTagsService {
* @returns
*/
getImageFileSize(imageUrl: string): Observable<DotCMSTempFile | ImageMetaData> {
return from(
fetch(imageUrl)
.then((response) => response.blob())
.then((blob) => {
return {
length: blob.size,
url: imageUrl
};
})
.catch((error) => {
console.warn(
'Getting the file size from an external URL failed, so we upload it to the server:',
error
);

return this.dotUploadService.uploadFile({ file: imageUrl });
})
return from(fetch(imageUrl)).pipe(
mergeMap((response) => {
return response.blob();
}),
mergeMap((response) => {
return of({
length: response.size,
url: imageUrl
});
}),
catchError((error) => {
console.warn(
'Getting the file size from an external URL failed, so we upload it to the server:',
error
);

return from(this.dotUploadService.uploadFile({ file: imageUrl })).pipe(
mergeMap((uploadedFile) => {
if (uploadedFile) {
return of(uploadedFile);
}
}),
catchError((uploadError) => {
console.warn('Error while uploading:', uploadError);
// You can handle the error from the upload service here

return of({
length: 0,
url: imageUrl
});
})
);
})
);
}
}
Expand Up @@ -111,7 +111,9 @@
}

.results-seo-tool__preview-image {
width: 100%;
width: 45.61706rem;
height: 23.875rem;
object-fit: contain;
}

.results-seo-tool__preview {
Expand Down
Expand Up @@ -5434,7 +5434,7 @@ seo.rules.description.more.one.found=More than 1 Meta Description found!
seo.rules.description.found.empty=Meta Description found, but is empty!
seo.rules.description.greater=Meta Description found, but it has more than 160 characters.
seo.rules.description.less=Meta Description found, but it has fewer than 55 characters of content.
seo.rules.description.greater=Meta Description found!
seo.rules.description.found=Meta Description found!

seo.rules.og-description.more.one.found=more than 1 og:description meta tag found!
seo.rules.og-description.found.empty=og:description meta tag found, but is empty!
Expand Down

0 comments on commit b655830

Please sign in to comment.