@escapenavigator/utils 1.10.138 → 1.10.140
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.
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email clients (Gmail и др.) плохо переваривают WebP — PNG лежит рядом
|
|
3
|
+
* с тем же basename. В БД храним только WebP URL; при отправке письма
|
|
4
|
+
* подменяем расширение.
|
|
5
|
+
*/
|
|
6
|
+
export declare function profileLogoUrlForEmail(logoUrl: string | null | undefined): string;
|
|
7
|
+
/** TipTap/Maily doc: image-ноды с profile logo WebP → PNG перед send-render. */
|
|
8
|
+
export declare function replaceProfileLogoUrlsInDoc<T>(doc: T): T;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.profileLogoUrlForEmail = profileLogoUrlForEmail;
|
|
4
|
+
exports.replaceProfileLogoUrlsInDoc = replaceProfileLogoUrlsInDoc;
|
|
5
|
+
const PROFILE_LOGO_PATH = 'profile_logos/';
|
|
6
|
+
/**
|
|
7
|
+
* Email clients (Gmail и др.) плохо переваривают WebP — PNG лежит рядом
|
|
8
|
+
* с тем же basename. В БД храним только WebP URL; при отправке письма
|
|
9
|
+
* подменяем расширение.
|
|
10
|
+
*/
|
|
11
|
+
function profileLogoUrlForEmail(logoUrl) {
|
|
12
|
+
if (!logoUrl)
|
|
13
|
+
return logoUrl ?? '';
|
|
14
|
+
if (!logoUrl.includes(PROFILE_LOGO_PATH) || !/\.webp(\?.*)?$/i.test(logoUrl)) {
|
|
15
|
+
return logoUrl;
|
|
16
|
+
}
|
|
17
|
+
return logoUrl.replace(/\.webp(\?.*)?$/i, '.png$1');
|
|
18
|
+
}
|
|
19
|
+
/** TipTap/Maily doc: image-ноды с profile logo WebP → PNG перед send-render. */
|
|
20
|
+
function replaceProfileLogoUrlsInDoc(doc) {
|
|
21
|
+
if (!doc || typeof doc !== 'object')
|
|
22
|
+
return doc;
|
|
23
|
+
if (Array.isArray(doc)) {
|
|
24
|
+
return doc.map((item) => replaceProfileLogoUrlsInDoc(item));
|
|
25
|
+
}
|
|
26
|
+
const node = { ...doc };
|
|
27
|
+
if (node.type === 'image' && node.attrs && typeof node.attrs === 'object') {
|
|
28
|
+
const attrs = { ...node.attrs };
|
|
29
|
+
if (typeof attrs.src === 'string') {
|
|
30
|
+
attrs.src = profileLogoUrlForEmail(attrs.src);
|
|
31
|
+
}
|
|
32
|
+
node.attrs = attrs;
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(node.content)) {
|
|
35
|
+
node.content = node.content.map((child) => replaceProfileLogoUrlsInDoc(child));
|
|
36
|
+
}
|
|
37
|
+
return node;
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const profile_logo_url_1 = require("./profile-logo-url");
|
|
4
|
+
describe('profileLogoUrlForEmail', () => {
|
|
5
|
+
it('replaces webp with png for profile logos', () => {
|
|
6
|
+
const url = 'https://escapenavigator-images.s3.eu-central-1.amazonaws.com/dev/profile_logos/123-imgABC.webp';
|
|
7
|
+
expect((0, profile_logo_url_1.profileLogoUrlForEmail)(url)).toBe('https://escapenavigator-images.s3.eu-central-1.amazonaws.com/dev/profile_logos/123-imgABC.png');
|
|
8
|
+
});
|
|
9
|
+
it('preserves query string', () => {
|
|
10
|
+
const url = 'https://cdn.example.com/profile_logos/x.webp?v=1';
|
|
11
|
+
expect((0, profile_logo_url_1.profileLogoUrlForEmail)(url)).toBe('https://cdn.example.com/profile_logos/x.png?v=1');
|
|
12
|
+
});
|
|
13
|
+
it('leaves non-profile and non-webp URLs unchanged', () => {
|
|
14
|
+
expect((0, profile_logo_url_1.profileLogoUrlForEmail)('https://cdn.example.com/inside/logo.png')).toBe('https://cdn.example.com/inside/logo.png');
|
|
15
|
+
expect((0, profile_logo_url_1.profileLogoUrlForEmail)(null)).toBe('');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
describe('replaceProfileLogoUrlsInDoc', () => {
|
|
19
|
+
it('walks nested image nodes', () => {
|
|
20
|
+
const doc = {
|
|
21
|
+
type: 'doc',
|
|
22
|
+
content: [
|
|
23
|
+
{
|
|
24
|
+
type: 'image',
|
|
25
|
+
attrs: {
|
|
26
|
+
src: 'https://cdn.example.com/profile_logos/a.webp',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
const result = (0, profile_logo_url_1.replaceProfileLogoUrlsInDoc)(doc);
|
|
32
|
+
expect(result.content[0].attrs.src).toBe('https://cdn.example.com/profile_logos/a.png');
|
|
33
|
+
});
|
|
34
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@escapenavigator/utils",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.140",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"test": "jest"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@escapenavigator/types": "^1.10.
|
|
17
|
+
"@escapenavigator/types": "^1.10.136",
|
|
18
18
|
"axios": "^0.21.4",
|
|
19
19
|
"class-transformer": "^0.5.1",
|
|
20
20
|
"class-validator": "^0.13.2",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"ts-jest": "^29.1.1",
|
|
29
29
|
"typescript": "^5.6"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "7d08baedfc8841d926752c1e457c3ee92beb4eea"
|
|
32
32
|
}
|