@ecency/render-helper 2.3.7 → 2.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -50,10 +50,10 @@ describe('Proxify image src', () => {
|
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
it('3- set proxy base', () => {
|
|
53
|
-
setProxyBase('https://
|
|
53
|
+
setProxyBase('https://images.hive.blog')
|
|
54
54
|
|
|
55
55
|
const input = 'https://i.imgur.com/muESb0B.png'
|
|
56
|
-
const expected = 'https://
|
|
56
|
+
const expected = 'https://images.hive.blog/p/2bP4pJr4wVimqCWjYimXJe2cnCgnJdyHYxb4dfF6gmC?format=match&mode=fit'
|
|
57
57
|
|
|
58
58
|
expect(proxifyImageSrc(input)).toBe(expected)
|
|
59
59
|
})
|
package/src/proxify-image-src.ts
CHANGED
|
@@ -2,9 +2,11 @@ import multihash from 'multihashes'
|
|
|
2
2
|
import querystring from 'querystring'
|
|
3
3
|
|
|
4
4
|
let proxyBase = 'https://images.ecency.com'
|
|
5
|
+
let fileExtension = true
|
|
5
6
|
|
|
6
7
|
export function setProxyBase(p: string): void {
|
|
7
8
|
proxyBase = p
|
|
9
|
+
fileExtension = proxyBase == 'https://images.ecency.com';
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
export function extractPHash(url: string): string | null {
|
|
@@ -62,10 +64,14 @@ export function proxifyImageSrc(url?: string, width = 0, height = 0, format = 'm
|
|
|
62
64
|
const qs = querystring.stringify(options)
|
|
63
65
|
|
|
64
66
|
if (pHash) {
|
|
65
|
-
|
|
67
|
+
if (fileExtension) {
|
|
68
|
+
return `${proxyBase}/p/${pHash}${format==='webp'?'.webp':'.png'}?${qs}`
|
|
69
|
+
} else {
|
|
70
|
+
return `${proxyBase}/p/${pHash}?${qs}`
|
|
71
|
+
}
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
const b58url = multihash.toB58String(Buffer.from(realUrl.toString()))
|
|
69
75
|
|
|
70
|
-
return `${proxyBase}/p/${b58url}${format==='webp'?'.webp':'.png'}?${qs}`
|
|
76
|
+
return `${proxyBase}/p/${b58url}${fileExtension ? format==='webp'?'.webp':'.png' : ''}?${qs}`
|
|
71
77
|
}
|