forked from EVOgeek/Vmeda.Online
		
	Merge pull request #3813 from crazyserver/MOBILE-4407
MOBILE-4407 url: Use Url parsing to determine last file
This commit is contained in:
		
						commit
						78aacf89a1
					
				| @ -81,7 +81,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * View has been initialized |      * @inheritdoc | ||||||
|      */ |      */ | ||||||
|     ngAfterViewInit(): void { |     ngAfterViewInit(): void { | ||||||
|         this.checkAndHandleExternalContent(); |         this.checkAndHandleExternalContent(); | ||||||
| @ -90,9 +90,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Listen to changes. |      * @inheritdoc | ||||||
|      * |  | ||||||
|      * * @param {{[name: string]: SimpleChange}} changes Changes. |  | ||||||
|      */ |      */ | ||||||
|     ngOnChanges(changes: { [name: string]: SimpleChange }): void { |     ngOnChanges(changes: { [name: string]: SimpleChange }): void { | ||||||
|         if (changes && this.initialized) { |         if (changes && this.initialized) { | ||||||
| @ -134,23 +132,23 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O | |||||||
|     protected async checkAndHandleExternalContent(): Promise<void> { |     protected async checkAndHandleExternalContent(): Promise<void> { | ||||||
|         const siteId = this.siteId || CoreSites.getRequiredCurrentSite().getId(); |         const siteId = this.siteId || CoreSites.getRequiredCurrentSite().getId(); | ||||||
|         const tagName = this.element.tagName.toUpperCase(); |         const tagName = this.element.tagName.toUpperCase(); | ||||||
|         let targetAttr; |         let targetAttr: string; | ||||||
|         let url; |         let url: string; | ||||||
| 
 | 
 | ||||||
|         // Always handle inline styles (if any).
 |         // Always handle inline styles (if any).
 | ||||||
|         this.handleInlineStyles(siteId); |         this.handleInlineStyles(siteId); | ||||||
| 
 | 
 | ||||||
|         if (tagName === 'A' || tagName == 'IMAGE') { |         if (tagName === 'A' || tagName == 'IMAGE') { | ||||||
|             targetAttr = 'href'; |             targetAttr = 'href'; | ||||||
|             url = this.href; |             url = this.href ?? ''; | ||||||
| 
 | 
 | ||||||
|         } else if (tagName === 'IMG') { |         } else if (tagName === 'IMG') { | ||||||
|             targetAttr = 'src'; |             targetAttr = 'src'; | ||||||
|             url = this.src; |             url = this.src ?? ''; | ||||||
| 
 | 
 | ||||||
|         } else if (tagName === 'AUDIO' || tagName === 'VIDEO' || tagName === 'SOURCE' || tagName === 'TRACK') { |         } else if (tagName === 'AUDIO' || tagName === 'VIDEO' || tagName === 'SOURCE' || tagName === 'TRACK') { | ||||||
|             targetAttr = 'src'; |             targetAttr = 'src'; | ||||||
|             url = this.targetSrc || this.src; |             url = (this.targetSrc || this.src) ?? ''; | ||||||
| 
 | 
 | ||||||
|             if (tagName === 'VIDEO') { |             if (tagName === 'VIDEO') { | ||||||
|                 if (this.poster) { |                 if (this.poster) { | ||||||
|  | |||||||
| @ -332,12 +332,13 @@ export class CoreUrlUtilsProvider { | |||||||
|      * @returns Last file without params. |      * @returns Last file without params. | ||||||
|      */ |      */ | ||||||
|     getLastFileWithoutParams(url: string): string { |     getLastFileWithoutParams(url: string): string { | ||||||
|         let filename = url.substring(url.lastIndexOf('/') + 1); |         const parsedUrl = CoreUrl.parse(url); | ||||||
|         if (filename.indexOf('?') != -1) { |         if (!parsedUrl) { | ||||||
|             filename = filename.substring(0, filename.indexOf('?')); |             return ''; | ||||||
|         } |         } | ||||||
|  |         const path = parsedUrl.path ?? ''; | ||||||
| 
 | 
 | ||||||
|         return filename; |         return path.split('/').pop() ?? ''; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -346,6 +347,7 @@ export class CoreUrlUtilsProvider { | |||||||
|      * |      * | ||||||
|      * @param url URL to treat. |      * @param url URL to treat. | ||||||
|      * @returns Protocol, undefined if no protocol found. |      * @returns Protocol, undefined if no protocol found. | ||||||
|  |      * @todo Use CoreUrl.parse | ||||||
|      */ |      */ | ||||||
|     getUrlProtocol(url: string): string | void { |     getUrlProtocol(url: string): string | void { | ||||||
|         if (!url) { |         if (!url) { | ||||||
| @ -381,6 +383,7 @@ export class CoreUrlUtilsProvider { | |||||||
|      * |      * | ||||||
|      * @param url URL to treat. |      * @param url URL to treat. | ||||||
|      * @returns Username. Undefined if no username found. |      * @returns Username. Undefined if no username found. | ||||||
|  |      * @todo Use CoreUrl.parse | ||||||
|      */ |      */ | ||||||
|     getUsernameFromUrl(url: string): string | undefined { |     getUsernameFromUrl(url: string): string | undefined { | ||||||
|         if (url.indexOf('@') > -1) { |         if (url.indexOf('@') > -1) { | ||||||
| @ -430,6 +433,7 @@ export class CoreUrlUtilsProvider { | |||||||
|      * |      * | ||||||
|      * @param url The url to test. |      * @param url The url to test. | ||||||
|      * @returns Whether the url uses http or https protocol. |      * @returns Whether the url uses http or https protocol. | ||||||
|  |      * @todo Use CoreUrl.parse | ||||||
|      */ |      */ | ||||||
|     isHttpURL(url: string): boolean { |     isHttpURL(url: string): boolean { | ||||||
|         return /^https?:\/\/.+/i.test(url); |         return /^https?:\/\/.+/i.test(url); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user