(url, options = {})
| 12067 | } |
| 12068 | |
| 12069 | async getSize(url, options = {}) { |
| 12070 | const { force = false, strategy = 'auto' } = options; |
| 12071 | if (!url) return null; |
| 12072 | |
| 12073 | if (!force && this.cache.has(url)) { |
| 12074 | return this.cache.get(url); |
| 12075 | } |
| 12076 | |
| 12077 | if (url.startsWith('data:')) { |
| 12078 | const size = this._calculateBase64Size(url); |
| 12079 | this.cache.set(url, size); |
| 12080 | return size; |
| 12081 | } |
| 12082 | |
| 12083 | if (url.startsWith('blob:')) { |
| 12084 | return this._getBlobSize(url); |
| 12085 | } |
| 12086 | |
| 12087 | if (strategy === 'local-only' || strategy === 'auto') { |
| 12088 | const perfSize = this._getFromPerformance(url); |
| 12089 | if (perfSize !== null) { |
| 12090 | this.cache.set(url, perfSize); |
| 12091 | return perfSize; |
| 12092 | } |
| 12093 | if (strategy === 'local-only') return null; |
| 12094 | } |
| 12095 | |
| 12096 | return this._scheduleRequest(url); |
| 12097 | } |
| 12098 | |
| 12099 | _calculateBase64Size(dataUrl) { |
| 12100 | const base64Str = dataUrl.split(',')[1]; |
no test coverage detected