diff --git a/libs/feature/editor/src/lib/components/import-record/import-record.component.ts b/libs/feature/editor/src/lib/components/import-record/import-record.component.ts index 98f1193b7..b61af1fdb 100644 --- a/libs/feature/editor/src/lib/components/import-record/import-record.component.ts +++ b/libs/feature/editor/src/lib/components/import-record/import-record.component.ts @@ -19,7 +19,6 @@ import { } from '@ng-icons/core' import { iconoirArrowLeft, - iconoirAttachment, iconoirImport, iconoirLightBulbOn, } from '@ng-icons/iconoir' @@ -106,10 +105,10 @@ export class ImportRecordComponent { this.cdr.markForCheck() } - importRecord(url: string) { + importRecord(url: URL) { this.isRecordImportInProgress = true - this.recordsRepository.duplicateExternalRecord(url).subscribe({ + this.recordsRepository.duplicateExternalRecord(url.toString()).subscribe({ next: (recordTempId) => { if (recordTempId) { this.notificationsService.showNotification( diff --git a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-online-resources/form-field-online-resources.component.ts b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-online-resources/form-field-online-resources.component.ts index 607909501..17a86ea33 100644 --- a/libs/feature/editor/src/lib/components/record-form/form-field/form-field-online-resources/form-field-online-resources.component.ts +++ b/libs/feature/editor/src/lib/components/record-form/form-field/form-field-online-resources/form-field-online-resources.component.ts @@ -158,12 +158,12 @@ export class FormFieldOnlineResourcesComponent { } } - handleServiceUrlChange(url: string) { + handleServiceUrlChange(url: URL) { this.valueChange.emit([ ...this.allResources, { ...this.newService, - url: new URL(url), + url, }, ]) } diff --git a/libs/ui/inputs/src/lib/file-input/file-input.component.spec.ts b/libs/ui/inputs/src/lib/file-input/file-input.component.spec.ts index db22eebf8..9c3a474c7 100644 --- a/libs/ui/inputs/src/lib/file-input/file-input.component.spec.ts +++ b/libs/ui/inputs/src/lib/file-input/file-input.component.spec.ts @@ -48,8 +48,8 @@ describe('FileInputComponent', () => { it('emits the entered URL', () => { let emitted component.urlChange.subscribe((v) => (emitted = v)) - component.handleUrlChange('http://hello.world') - expect(emitted).toEqual('http://hello.world') + component.handleUrlChange(new URL('http://hello.world')) + expect(emitted).toEqual('http://hello.world/') }) }) diff --git a/libs/ui/inputs/src/lib/file-input/file-input.component.ts b/libs/ui/inputs/src/lib/file-input/file-input.component.ts index 88efe3b12..cd7bad264 100644 --- a/libs/ui/inputs/src/lib/file-input/file-input.component.ts +++ b/libs/ui/inputs/src/lib/file-input/file-input.component.ts @@ -89,8 +89,8 @@ export class FileInputComponent { this.handleDropFiles(Array.from((event.target as HTMLInputElement).files)) } - handleUrlChange(url: string) { - this.urlChange.emit(url) + handleUrlChange(url: URL) { + this.urlChange.emit(url.toString()) } handleSecondaryTextClick(event: Event) { diff --git a/libs/ui/inputs/src/lib/image-input/image-input.component.spec.ts b/libs/ui/inputs/src/lib/image-input/image-input.component.spec.ts index d5b0b6f86..997803057 100644 --- a/libs/ui/inputs/src/lib/image-input/image-input.component.spec.ts +++ b/libs/ui/inputs/src/lib/image-input/image-input.component.spec.ts @@ -39,7 +39,7 @@ describe('ImageInputComponent', () => { type: 'text/plain', }) const someImageFile = new File([], 'someImageFile', { type: 'image/png' }) - const result = component.filterTypeImage([ + const result = component['filterTypeImage']([ someNonImageFile, someImageFile, ]) @@ -58,7 +58,7 @@ describe('ImageInputComponent', () => { it('should emit the downloaded file on nominal case', waitForAsync(() => { jest.spyOn(component.fileChange, 'emit') - component.downloadUrl('http://test.com/image.png') + component.downloadUrl(new URL('http://test.com/image.png')) const reqHead = httpTestingController.expectOne(testUrl) expect(reqHead.request.method).toEqual('HEAD') @@ -85,7 +85,7 @@ describe('ImageInputComponent', () => { })) it('should not download the file when content-type is not image', waitForAsync(() => { - component.downloadUrl('http://test.com/image.png') + component.downloadUrl(new URL('http://test.com/image.png')) const reqHead = httpTestingController.expectOne(testUrl) expect(reqHead.request.method).toEqual('HEAD') @@ -103,7 +103,7 @@ describe('ImageInputComponent', () => { })) it('should not download the file when content-length is above limit', waitForAsync(() => { - component.downloadUrl('http://test.com/image.png') + component.downloadUrl(new URL('http://test.com/image.png')) const reqHead = httpTestingController.expectOne(testUrl) expect(reqHead.request.method).toEqual('HEAD') @@ -123,7 +123,7 @@ describe('ImageInputComponent', () => { it('should emit the file URL when encountering a download error', waitForAsync(() => { jest.spyOn(component.urlChange, 'emit') - component.downloadUrl('http://test.com/image.png') + component.downloadUrl(new URL('http://test.com/image.png')) const reqHead = httpTestingController.expectOne(testUrl) expect(reqHead.request.method).toEqual('HEAD') diff --git a/libs/ui/inputs/src/lib/image-input/image-input.component.ts b/libs/ui/inputs/src/lib/image-input/image-input.component.ts index 6f403b3f8..a31dc62ac 100644 --- a/libs/ui/inputs/src/lib/image-input/image-input.component.ts +++ b/libs/ui/inputs/src/lib/image-input/image-input.component.ts @@ -23,12 +23,12 @@ import { provideNgIconsConfig, } from '@ng-icons/core' import { + iconoirBin, iconoirFramePlusIn, + iconoirLink, iconoirMediaImage, iconoirMediaImageXmark, - iconoirBin, iconoirPlus, - iconoirLink, } from '@ng-icons/iconoir' @Component({ @@ -136,20 +136,20 @@ export class ImageInputComponent { this.showUrlInput = true } - async downloadUrl(url: string) { + async downloadUrl(url: URL) { this.downloadError = false - const name = url.split('/').pop() + const name = url.toString().split('/').pop() try { const response = await firstValueFrom( - this.http.head(url, { observe: 'response' }) + this.http.head(url.toString(), { observe: 'response' }) ) if ( response.headers.get('content-type')?.startsWith('image/') && parseInt(response.headers.get('content-length')) < megabytesToBytes(this.maxSizeMB) ) { - this.http.get(url, { responseType: 'blob' }).subscribe({ + this.http.get(url.toString(), { responseType: 'blob' }).subscribe({ next: (blob) => { this.cd.markForCheck() const file = new File([blob], name) @@ -158,7 +158,7 @@ export class ImageInputComponent { error: () => { this.downloadError = true this.cd.markForCheck() - this.urlChange.emit(url) + this.urlChange.emit(url.toString()) }, }) }