@wix/sdk 1.15.9 → 1.15.11
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/build/auth/AppStrategy.js +4 -4
- package/build/media/helpers.d.ts +36 -0
- package/build/media/helpers.js +147 -0
- package/build/wixMedia.d.ts +2 -37
- package/build/wixMedia.js +2 -147
- package/cjs/build/auth/AppStrategy.js +4 -4
- package/cjs/build/media/helpers.d.ts +36 -0
- package/cjs/build/media/helpers.js +158 -0
- package/cjs/build/wixMedia.d.ts +2 -37
- package/cjs/build/wixMedia.js +12 -156
- package/media/package.json +3 -0
- package/package.json +15 -10
|
@@ -83,7 +83,7 @@ export function AppStrategy(opts) {
|
|
|
83
83
|
}),
|
|
84
84
|
});
|
|
85
85
|
if (tokensRes.status !== 200) {
|
|
86
|
-
throw new Error(`Failed to exchange authorization code for refresh token. Unexpected status code from Wix OAuth API: ${tokensRes.status}`);
|
|
86
|
+
throw new Error(`Failed to exchange authorization code for refresh token. Unexpected status code from Wix OAuth API: ${tokensRes.status}, request id: ${tokensRes.headers.get('x-wix-request-id')}`);
|
|
87
87
|
}
|
|
88
88
|
const tokens = await tokensRes.json();
|
|
89
89
|
refreshToken = tokens.refresh_token;
|
|
@@ -118,7 +118,7 @@ export function AppStrategy(opts) {
|
|
|
118
118
|
}),
|
|
119
119
|
});
|
|
120
120
|
if (tokensRes.status !== 200) {
|
|
121
|
-
throw new Error(`Failed to exchange refresh token for access token. Unexpected status code from Wix OAuth API: ${tokensRes.status}`);
|
|
121
|
+
throw new Error(`Failed to exchange refresh token for access token. Unexpected status code from Wix OAuth API: ${tokensRes.status}, request id: ${tokensRes.headers.get('x-wix-request-id')}`);
|
|
122
122
|
}
|
|
123
123
|
const tokens = (await tokensRes.json());
|
|
124
124
|
refreshToken = tokens.refresh_token;
|
|
@@ -145,7 +145,7 @@ export function AppStrategy(opts) {
|
|
|
145
145
|
}),
|
|
146
146
|
});
|
|
147
147
|
if (tokensRes.status !== 200) {
|
|
148
|
-
throw new Error(`Failed to exchange instance ID for access token. Unexpected status code from Wix OAuth API: ${tokensRes.status}`);
|
|
148
|
+
throw new Error(`Failed to exchange instance ID for access token. Unexpected status code from Wix OAuth API: ${tokensRes.status}, request id: ${tokensRes.headers.get('x-wix-request-id')}`);
|
|
149
149
|
}
|
|
150
150
|
const tokens = (await tokensRes.json());
|
|
151
151
|
cachedToken = {
|
|
@@ -171,7 +171,7 @@ export function AppStrategy(opts) {
|
|
|
171
171
|
}),
|
|
172
172
|
});
|
|
173
173
|
if (tokenRes.status !== 200) {
|
|
174
|
-
throw new Error(`Failed to get unbound token. Unexpected status code from Wix OAuth API: ${tokenRes.status}`);
|
|
174
|
+
throw new Error(`Failed to get unbound token. Unexpected status code from Wix OAuth API: ${tokenRes.status}, request id: ${tokenRes.headers.get('x-wix-request-id')}`);
|
|
175
175
|
}
|
|
176
176
|
const { access_token, expires_in } = (await tokenRes.json());
|
|
177
177
|
cachedToken = {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ImageTransformOptions } from '@wix/image-kit';
|
|
2
|
+
export declare function getScaledToFillImageUrl(wixMediaIdentifier: string, targetWidth: number, targetHeight: number, options: ImageTransformOptions): string;
|
|
3
|
+
export declare function getScaledToFitImageUrl(wixMediaIdentifier: string, targetWidth: number, targetHeight: number, options: ImageTransformOptions): string;
|
|
4
|
+
export declare function getCroppedImageUrl(wixMediaIdentifier: string, cropX: number, cropY: number, cropWidth: number, cropHeight: number, targetWidth: number, targetHeight: number, options?: ImageTransformOptions): string;
|
|
5
|
+
export declare function getImageUrl(val: string): {
|
|
6
|
+
id: string;
|
|
7
|
+
url: string;
|
|
8
|
+
height: number;
|
|
9
|
+
width: number;
|
|
10
|
+
altText?: string;
|
|
11
|
+
filename?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function getVideoUrl(val: string, resolution?: VideoResolution): {
|
|
14
|
+
id: string;
|
|
15
|
+
url: string;
|
|
16
|
+
thumbnail: string;
|
|
17
|
+
filename?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function getAudioUrl(val: string): {
|
|
20
|
+
id: string;
|
|
21
|
+
url: string;
|
|
22
|
+
duration: number;
|
|
23
|
+
filename?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare function getDocumentUrl(val: string): {
|
|
26
|
+
id: string;
|
|
27
|
+
url: string;
|
|
28
|
+
filename?: string;
|
|
29
|
+
};
|
|
30
|
+
export declare function decodeText(s: string): string;
|
|
31
|
+
export declare enum VideoResolution {
|
|
32
|
+
MOBILE = "360p",
|
|
33
|
+
LOW = "480p",
|
|
34
|
+
MID = "720p",
|
|
35
|
+
HIGH = "1080p"
|
|
36
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { sdk } from '@wix/image-kit';
|
|
2
|
+
const WIX_PROTOCOL = 'wix:';
|
|
3
|
+
const WIX_IMAGE = 'image';
|
|
4
|
+
const WIX_VIDEO = 'video';
|
|
5
|
+
const WIX_AUDIO = 'audio';
|
|
6
|
+
const WIX_DOCUMENT = 'document';
|
|
7
|
+
const WIX_IMAGE_URL = 'https://static.wixstatic.com/media/';
|
|
8
|
+
const WIX_VIDEO_URL = 'https://video.wixstatic.com/video/';
|
|
9
|
+
const WIX_AUDIO_URL = 'https://static.wixstatic.com/mp3/';
|
|
10
|
+
const WIX_DOCUMENT_URL = 'https://d945e594-8657-47e2-9cd9-e9033c3d8da0.usrfiles.com/ugd/';
|
|
11
|
+
export function getScaledToFillImageUrl(wixMediaIdentifier, targetWidth, targetHeight, options) {
|
|
12
|
+
const img = getImageUrl(wixMediaIdentifier);
|
|
13
|
+
return sdk.getScaleToFillImageURL(img.id, img.height, img.width, targetWidth, targetHeight, options);
|
|
14
|
+
}
|
|
15
|
+
export function getScaledToFitImageUrl(wixMediaIdentifier, targetWidth, targetHeight, options) {
|
|
16
|
+
const img = getImageUrl(wixMediaIdentifier);
|
|
17
|
+
return sdk.getScaleToFitImageURL(img.id, img.height, img.width, targetWidth, targetHeight, options);
|
|
18
|
+
}
|
|
19
|
+
export function getCroppedImageUrl(wixMediaIdentifier, cropX, cropY, cropWidth, cropHeight, targetWidth, targetHeight, options) {
|
|
20
|
+
const img = getImageUrl(wixMediaIdentifier);
|
|
21
|
+
return sdk.getCropImageURL(img.id, img.height, img.width, cropX, cropY, cropWidth, cropHeight, targetWidth, targetHeight, options);
|
|
22
|
+
}
|
|
23
|
+
export function getImageUrl(val) {
|
|
24
|
+
let id, filenameOrAltText;
|
|
25
|
+
let height, width;
|
|
26
|
+
if (val.startsWith(WIX_IMAGE_URL)) {
|
|
27
|
+
id = val.split(WIX_IMAGE_URL).pop().split('/')[0];
|
|
28
|
+
width = val.split('/w_').pop().split(',')[0];
|
|
29
|
+
height = val.split(',h_').pop().split(',')[0];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const alignedImage = alignIfLegacy(val, WIX_IMAGE);
|
|
33
|
+
const { hash, pathname } = new URL(alignedImage);
|
|
34
|
+
const params = new URLSearchParams(hash.replace('#', ''));
|
|
35
|
+
height = params.get('originHeight');
|
|
36
|
+
width = params.get('originWidth');
|
|
37
|
+
[id, filenameOrAltText] = pathname
|
|
38
|
+
.replace(`${WIX_IMAGE}://v1/`, '')
|
|
39
|
+
.split('/');
|
|
40
|
+
}
|
|
41
|
+
// @ts-expect-error
|
|
42
|
+
const decodedFilenameOrAltText = decodeText(filenameOrAltText);
|
|
43
|
+
const res = {
|
|
44
|
+
id,
|
|
45
|
+
url: `${WIX_IMAGE_URL}${id}`,
|
|
46
|
+
height: Number(height),
|
|
47
|
+
width: Number(width),
|
|
48
|
+
};
|
|
49
|
+
if (!decodedFilenameOrAltText) {
|
|
50
|
+
return res;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
...res,
|
|
54
|
+
altText: decodedFilenameOrAltText,
|
|
55
|
+
filename: decodedFilenameOrAltText,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function getVideoUrl(val, resolution) {
|
|
59
|
+
let id, thumbnailId, thumbnailWidth, thumbnailHeight, decodedFilename = '';
|
|
60
|
+
if (val.startsWith(WIX_VIDEO_URL)) {
|
|
61
|
+
id = val.split(WIX_VIDEO_URL).pop().split('/')[0];
|
|
62
|
+
thumbnailId = `${id}.jpg`;
|
|
63
|
+
thumbnailWidth = '50';
|
|
64
|
+
thumbnailHeight = '50';
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
const alignedVideo = alignIfLegacy(val, WIX_VIDEO);
|
|
68
|
+
const { pathname, hash } = new URL(alignedVideo);
|
|
69
|
+
const hashParams = new URLSearchParams(hash.replace('#', ''));
|
|
70
|
+
const [_id, fileName] = pathname
|
|
71
|
+
.replace(`${WIX_VIDEO}://v1/`, '')
|
|
72
|
+
.split('/');
|
|
73
|
+
id = _id;
|
|
74
|
+
thumbnailId = hashParams.get('posterUri') || `${id}.jpg`;
|
|
75
|
+
thumbnailWidth = hashParams.get('posterWidth') || '50';
|
|
76
|
+
thumbnailHeight = hashParams.get('posterHeight') || '50';
|
|
77
|
+
decodedFilename = decodeText(fileName);
|
|
78
|
+
}
|
|
79
|
+
const res = {
|
|
80
|
+
id,
|
|
81
|
+
url: `${WIX_VIDEO_URL}${id}/${resolution ? `${resolution}/mp4/file.mp4` : 'file'}`,
|
|
82
|
+
thumbnail: `${WIX_PROTOCOL}${WIX_IMAGE}://v1/${thumbnailId}#originWidth=${thumbnailWidth}&originHeight=${thumbnailHeight}`,
|
|
83
|
+
};
|
|
84
|
+
if (!decodedFilename) {
|
|
85
|
+
return res;
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
...res,
|
|
89
|
+
filename: decodedFilename,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export function getAudioUrl(val) {
|
|
93
|
+
const alignedAudio = alignIfLegacy(val, WIX_AUDIO);
|
|
94
|
+
const { pathname, hash } = new URL(alignedAudio);
|
|
95
|
+
const [id, filename] = pathname.replace(`${WIX_AUDIO}://v1/`, '').split('/');
|
|
96
|
+
const decodedFilename = decodeText(filename);
|
|
97
|
+
const hashParams = new URLSearchParams(hash.replace('#', ''));
|
|
98
|
+
const res = {
|
|
99
|
+
id,
|
|
100
|
+
duration: Number(hashParams.get('duration') || ''),
|
|
101
|
+
url: `${WIX_AUDIO_URL}${id}`,
|
|
102
|
+
};
|
|
103
|
+
if (!decodedFilename) {
|
|
104
|
+
return res;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
...res,
|
|
108
|
+
filename: decodedFilename,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export function getDocumentUrl(val) {
|
|
112
|
+
const valWithoutUGD = val.replace('v1/ugd', 'v1');
|
|
113
|
+
const alignedDocument = alignIfLegacy(valWithoutUGD, WIX_DOCUMENT);
|
|
114
|
+
const { pathname } = new URL(alignedDocument);
|
|
115
|
+
const [id, filename] = pathname
|
|
116
|
+
.replace(`${WIX_DOCUMENT}://v1/`, '')
|
|
117
|
+
.split('/');
|
|
118
|
+
const decodedFilename = decodeText(filename);
|
|
119
|
+
const res = {
|
|
120
|
+
id,
|
|
121
|
+
url: `${WIX_DOCUMENT_URL}${id}`,
|
|
122
|
+
};
|
|
123
|
+
if (!decodedFilename) {
|
|
124
|
+
return res;
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
...res,
|
|
128
|
+
filename: decodedFilename,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export function decodeText(s) {
|
|
132
|
+
if (!s) {
|
|
133
|
+
return s;
|
|
134
|
+
}
|
|
135
|
+
return decodeURIComponent(s);
|
|
136
|
+
}
|
|
137
|
+
function alignIfLegacy(url, type) {
|
|
138
|
+
const { protocol } = new URL(url);
|
|
139
|
+
return protocol === `${type}:` ? `${WIX_PROTOCOL}${url}` : url;
|
|
140
|
+
}
|
|
141
|
+
export var VideoResolution;
|
|
142
|
+
(function (VideoResolution) {
|
|
143
|
+
VideoResolution["MOBILE"] = "360p";
|
|
144
|
+
VideoResolution["LOW"] = "480p";
|
|
145
|
+
VideoResolution["MID"] = "720p";
|
|
146
|
+
VideoResolution["HIGH"] = "1080p";
|
|
147
|
+
})(VideoResolution || (VideoResolution = {}));
|
package/build/wixMedia.d.ts
CHANGED
|
@@ -1,39 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function getScaledToFitImageUrl(wixMediaIdentifier: string, targetWidth: number, targetHeight: number, options: ImageTransformOptions): string;
|
|
4
|
-
declare function getCroppedImageUrl(wixMediaIdentifier: string, cropX: number, cropY: number, cropWidth: number, cropHeight: number, targetWidth: number, targetHeight: number, options?: ImageTransformOptions): string;
|
|
5
|
-
declare function getImageUrl(val: string): {
|
|
6
|
-
id: string;
|
|
7
|
-
url: string;
|
|
8
|
-
height: number;
|
|
9
|
-
width: number;
|
|
10
|
-
altText?: string;
|
|
11
|
-
filename?: string;
|
|
12
|
-
};
|
|
13
|
-
declare function getVideoUrl(val: string, resolution?: VideoResolution): {
|
|
14
|
-
id: string;
|
|
15
|
-
url: string;
|
|
16
|
-
thumbnail: string;
|
|
17
|
-
filename?: string;
|
|
18
|
-
};
|
|
19
|
-
declare function getAudioUrl(val: string): {
|
|
20
|
-
id: string;
|
|
21
|
-
url: string;
|
|
22
|
-
duration: number;
|
|
23
|
-
filename?: string;
|
|
24
|
-
};
|
|
25
|
-
declare function getDocumentUrl(val: string): {
|
|
26
|
-
id: string;
|
|
27
|
-
url: string;
|
|
28
|
-
filename?: string;
|
|
29
|
-
};
|
|
30
|
-
export declare function decodeText(s: string): string;
|
|
31
|
-
export declare enum VideoResolution {
|
|
32
|
-
MOBILE = "360p",
|
|
33
|
-
LOW = "480p",
|
|
34
|
-
MID = "720p",
|
|
35
|
-
HIGH = "1080p"
|
|
36
|
-
}
|
|
1
|
+
import { getAudioUrl, getCroppedImageUrl, getDocumentUrl, getImageUrl, getScaledToFillImageUrl, getScaledToFitImageUrl, getVideoUrl } from './media/helpers.js';
|
|
2
|
+
export { VideoResolution, decodeText } from './media/helpers.js';
|
|
37
3
|
export declare const media: {
|
|
38
4
|
getCroppedImageUrl: typeof getCroppedImageUrl;
|
|
39
5
|
getScaledToFillImageUrl: typeof getScaledToFillImageUrl;
|
|
@@ -43,4 +9,3 @@ export declare const media: {
|
|
|
43
9
|
getAudioUrl: typeof getAudioUrl;
|
|
44
10
|
getDocumentUrl: typeof getDocumentUrl;
|
|
45
11
|
};
|
|
46
|
-
export {};
|
package/build/wixMedia.js
CHANGED
|
@@ -1,150 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const WIX_IMAGE = 'image';
|
|
4
|
-
const WIX_VIDEO = 'video';
|
|
5
|
-
const WIX_AUDIO = 'audio';
|
|
6
|
-
const WIX_DOCUMENT = 'document';
|
|
7
|
-
const WIX_IMAGE_URL = 'https://static.wixstatic.com/media/';
|
|
8
|
-
const WIX_VIDEO_URL = 'https://video.wixstatic.com/video/';
|
|
9
|
-
const WIX_AUDIO_URL = 'https://static.wixstatic.com/mp3/';
|
|
10
|
-
const WIX_DOCUMENT_URL = 'https://d945e594-8657-47e2-9cd9-e9033c3d8da0.usrfiles.com/ugd/';
|
|
11
|
-
function getScaledToFillImageUrl(wixMediaIdentifier, targetWidth, targetHeight, options) {
|
|
12
|
-
const img = getImageUrl(wixMediaIdentifier);
|
|
13
|
-
return sdk.getScaleToFillImageURL(img.id, img.height, img.width, targetWidth, targetHeight, options);
|
|
14
|
-
}
|
|
15
|
-
function getScaledToFitImageUrl(wixMediaIdentifier, targetWidth, targetHeight, options) {
|
|
16
|
-
const img = getImageUrl(wixMediaIdentifier);
|
|
17
|
-
return sdk.getScaleToFitImageURL(img.id, img.height, img.width, targetWidth, targetHeight, options);
|
|
18
|
-
}
|
|
19
|
-
function getCroppedImageUrl(wixMediaIdentifier, cropX, cropY, cropWidth, cropHeight, targetWidth, targetHeight, options) {
|
|
20
|
-
const img = getImageUrl(wixMediaIdentifier);
|
|
21
|
-
return sdk.getCropImageURL(img.id, img.height, img.width, cropX, cropY, cropWidth, cropHeight, targetWidth, targetHeight, options);
|
|
22
|
-
}
|
|
23
|
-
function getImageUrl(val) {
|
|
24
|
-
let id, filenameOrAltText;
|
|
25
|
-
let height, width;
|
|
26
|
-
if (val.startsWith(WIX_IMAGE_URL)) {
|
|
27
|
-
id = val.split(WIX_IMAGE_URL).pop().split('/')[0];
|
|
28
|
-
width = val.split('/w_').pop().split(',')[0];
|
|
29
|
-
height = val.split(',h_').pop().split(',')[0];
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
const alignedImage = alignIfLegacy(val, WIX_IMAGE);
|
|
33
|
-
const { hash, pathname } = new URL(alignedImage);
|
|
34
|
-
const params = new URLSearchParams(hash.replace('#', ''));
|
|
35
|
-
height = params.get('originHeight');
|
|
36
|
-
width = params.get('originWidth');
|
|
37
|
-
[id, filenameOrAltText] = pathname
|
|
38
|
-
.replace(`${WIX_IMAGE}://v1/`, '')
|
|
39
|
-
.split('/');
|
|
40
|
-
}
|
|
41
|
-
// @ts-expect-error
|
|
42
|
-
const decodedFilenameOrAltText = decodeText(filenameOrAltText);
|
|
43
|
-
const res = {
|
|
44
|
-
id,
|
|
45
|
-
url: `${WIX_IMAGE_URL}${id}`,
|
|
46
|
-
height: Number(height),
|
|
47
|
-
width: Number(width),
|
|
48
|
-
};
|
|
49
|
-
if (!decodedFilenameOrAltText) {
|
|
50
|
-
return res;
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
...res,
|
|
54
|
-
altText: decodedFilenameOrAltText,
|
|
55
|
-
filename: decodedFilenameOrAltText,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function getVideoUrl(val, resolution) {
|
|
59
|
-
let id, thumbnailId, thumbnailWidth, thumbnailHeight, decodedFilename = '';
|
|
60
|
-
if (val.startsWith(WIX_VIDEO_URL)) {
|
|
61
|
-
id = val.split(WIX_VIDEO_URL).pop().split('/')[0];
|
|
62
|
-
thumbnailId = `${id}.jpg`;
|
|
63
|
-
thumbnailWidth = '50';
|
|
64
|
-
thumbnailHeight = '50';
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
const alignedVideo = alignIfLegacy(val, WIX_VIDEO);
|
|
68
|
-
const { pathname, hash } = new URL(alignedVideo);
|
|
69
|
-
const hashParams = new URLSearchParams(hash.replace('#', ''));
|
|
70
|
-
const [_id, fileName] = pathname
|
|
71
|
-
.replace(`${WIX_VIDEO}://v1/`, '')
|
|
72
|
-
.split('/');
|
|
73
|
-
id = _id;
|
|
74
|
-
thumbnailId = hashParams.get('posterUri') || `${id}.jpg`;
|
|
75
|
-
thumbnailWidth = hashParams.get('posterWidth') || '50';
|
|
76
|
-
thumbnailHeight = hashParams.get('posterHeight') || '50';
|
|
77
|
-
decodedFilename = decodeText(fileName);
|
|
78
|
-
}
|
|
79
|
-
const res = {
|
|
80
|
-
id,
|
|
81
|
-
url: `${WIX_VIDEO_URL}${id}/${resolution ? `${resolution}/mp4/file.mp4` : 'file'}`,
|
|
82
|
-
thumbnail: `${WIX_PROTOCOL}${WIX_IMAGE}://v1/${thumbnailId}#originWidth=${thumbnailWidth}&originHeight=${thumbnailHeight}`,
|
|
83
|
-
};
|
|
84
|
-
if (!decodedFilename) {
|
|
85
|
-
return res;
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
...res,
|
|
89
|
-
filename: decodedFilename,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function getAudioUrl(val) {
|
|
93
|
-
const alignedAudio = alignIfLegacy(val, WIX_AUDIO);
|
|
94
|
-
const { pathname, hash } = new URL(alignedAudio);
|
|
95
|
-
const [id, filename] = pathname.replace(`${WIX_AUDIO}://v1/`, '').split('/');
|
|
96
|
-
const decodedFilename = decodeText(filename);
|
|
97
|
-
const hashParams = new URLSearchParams(hash.replace('#', ''));
|
|
98
|
-
const res = {
|
|
99
|
-
id,
|
|
100
|
-
duration: Number(hashParams.get('duration') || ''),
|
|
101
|
-
url: `${WIX_AUDIO_URL}${id}`,
|
|
102
|
-
};
|
|
103
|
-
if (!decodedFilename) {
|
|
104
|
-
return res;
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
...res,
|
|
108
|
-
filename: decodedFilename,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function getDocumentUrl(val) {
|
|
112
|
-
const valWithoutUGD = val.replace('v1/ugd', 'v1');
|
|
113
|
-
const alignedDocument = alignIfLegacy(valWithoutUGD, WIX_DOCUMENT);
|
|
114
|
-
const { pathname } = new URL(alignedDocument);
|
|
115
|
-
const [id, filename] = pathname
|
|
116
|
-
.replace(`${WIX_DOCUMENT}://v1/`, '')
|
|
117
|
-
.split('/');
|
|
118
|
-
const decodedFilename = decodeText(filename);
|
|
119
|
-
const res = {
|
|
120
|
-
id,
|
|
121
|
-
url: `${WIX_DOCUMENT_URL}${id}`,
|
|
122
|
-
};
|
|
123
|
-
if (!decodedFilename) {
|
|
124
|
-
return res;
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
...res,
|
|
128
|
-
filename: decodedFilename,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
export function decodeText(s) {
|
|
132
|
-
if (!s) {
|
|
133
|
-
return s;
|
|
134
|
-
}
|
|
135
|
-
return decodeURIComponent(s);
|
|
136
|
-
}
|
|
137
|
-
function alignIfLegacy(url, type) {
|
|
138
|
-
const { protocol } = new URL(url);
|
|
139
|
-
return protocol === `${type}:` ? `${WIX_PROTOCOL}${url}` : url;
|
|
140
|
-
}
|
|
141
|
-
export var VideoResolution;
|
|
142
|
-
(function (VideoResolution) {
|
|
143
|
-
VideoResolution["MOBILE"] = "360p";
|
|
144
|
-
VideoResolution["LOW"] = "480p";
|
|
145
|
-
VideoResolution["MID"] = "720p";
|
|
146
|
-
VideoResolution["HIGH"] = "1080p";
|
|
147
|
-
})(VideoResolution || (VideoResolution = {}));
|
|
1
|
+
import { getAudioUrl, getCroppedImageUrl, getDocumentUrl, getImageUrl, getScaledToFillImageUrl, getScaledToFitImageUrl, getVideoUrl, } from './media/helpers.js';
|
|
2
|
+
export { VideoResolution, decodeText } from './media/helpers.js';
|
|
148
3
|
export const media = {
|
|
149
4
|
getCroppedImageUrl,
|
|
150
5
|
getScaledToFillImageUrl,
|
|
@@ -119,7 +119,7 @@ function AppStrategy(opts) {
|
|
|
119
119
|
}),
|
|
120
120
|
});
|
|
121
121
|
if (tokensRes.status !== 200) {
|
|
122
|
-
throw new Error(`Failed to exchange authorization code for refresh token. Unexpected status code from Wix OAuth API: ${tokensRes.status}`);
|
|
122
|
+
throw new Error(`Failed to exchange authorization code for refresh token. Unexpected status code from Wix OAuth API: ${tokensRes.status}, request id: ${tokensRes.headers.get('x-wix-request-id')}`);
|
|
123
123
|
}
|
|
124
124
|
const tokens = await tokensRes.json();
|
|
125
125
|
refreshToken = tokens.refresh_token;
|
|
@@ -154,7 +154,7 @@ function AppStrategy(opts) {
|
|
|
154
154
|
}),
|
|
155
155
|
});
|
|
156
156
|
if (tokensRes.status !== 200) {
|
|
157
|
-
throw new Error(`Failed to exchange refresh token for access token. Unexpected status code from Wix OAuth API: ${tokensRes.status}`);
|
|
157
|
+
throw new Error(`Failed to exchange refresh token for access token. Unexpected status code from Wix OAuth API: ${tokensRes.status}, request id: ${tokensRes.headers.get('x-wix-request-id')}`);
|
|
158
158
|
}
|
|
159
159
|
const tokens = (await tokensRes.json());
|
|
160
160
|
refreshToken = tokens.refresh_token;
|
|
@@ -181,7 +181,7 @@ function AppStrategy(opts) {
|
|
|
181
181
|
}),
|
|
182
182
|
});
|
|
183
183
|
if (tokensRes.status !== 200) {
|
|
184
|
-
throw new Error(`Failed to exchange instance ID for access token. Unexpected status code from Wix OAuth API: ${tokensRes.status}`);
|
|
184
|
+
throw new Error(`Failed to exchange instance ID for access token. Unexpected status code from Wix OAuth API: ${tokensRes.status}, request id: ${tokensRes.headers.get('x-wix-request-id')}`);
|
|
185
185
|
}
|
|
186
186
|
const tokens = (await tokensRes.json());
|
|
187
187
|
cachedToken = {
|
|
@@ -207,7 +207,7 @@ function AppStrategy(opts) {
|
|
|
207
207
|
}),
|
|
208
208
|
});
|
|
209
209
|
if (tokenRes.status !== 200) {
|
|
210
|
-
throw new Error(`Failed to get unbound token. Unexpected status code from Wix OAuth API: ${tokenRes.status}`);
|
|
210
|
+
throw new Error(`Failed to get unbound token. Unexpected status code from Wix OAuth API: ${tokenRes.status}, request id: ${tokenRes.headers.get('x-wix-request-id')}`);
|
|
211
211
|
}
|
|
212
212
|
const { access_token, expires_in } = (await tokenRes.json());
|
|
213
213
|
cachedToken = {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ImageTransformOptions } from '@wix/image-kit';
|
|
2
|
+
export declare function getScaledToFillImageUrl(wixMediaIdentifier: string, targetWidth: number, targetHeight: number, options: ImageTransformOptions): string;
|
|
3
|
+
export declare function getScaledToFitImageUrl(wixMediaIdentifier: string, targetWidth: number, targetHeight: number, options: ImageTransformOptions): string;
|
|
4
|
+
export declare function getCroppedImageUrl(wixMediaIdentifier: string, cropX: number, cropY: number, cropWidth: number, cropHeight: number, targetWidth: number, targetHeight: number, options?: ImageTransformOptions): string;
|
|
5
|
+
export declare function getImageUrl(val: string): {
|
|
6
|
+
id: string;
|
|
7
|
+
url: string;
|
|
8
|
+
height: number;
|
|
9
|
+
width: number;
|
|
10
|
+
altText?: string;
|
|
11
|
+
filename?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function getVideoUrl(val: string, resolution?: VideoResolution): {
|
|
14
|
+
id: string;
|
|
15
|
+
url: string;
|
|
16
|
+
thumbnail: string;
|
|
17
|
+
filename?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function getAudioUrl(val: string): {
|
|
20
|
+
id: string;
|
|
21
|
+
url: string;
|
|
22
|
+
duration: number;
|
|
23
|
+
filename?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare function getDocumentUrl(val: string): {
|
|
26
|
+
id: string;
|
|
27
|
+
url: string;
|
|
28
|
+
filename?: string;
|
|
29
|
+
};
|
|
30
|
+
export declare function decodeText(s: string): string;
|
|
31
|
+
export declare enum VideoResolution {
|
|
32
|
+
MOBILE = "360p",
|
|
33
|
+
LOW = "480p",
|
|
34
|
+
MID = "720p",
|
|
35
|
+
HIGH = "1080p"
|
|
36
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VideoResolution = void 0;
|
|
4
|
+
exports.getScaledToFillImageUrl = getScaledToFillImageUrl;
|
|
5
|
+
exports.getScaledToFitImageUrl = getScaledToFitImageUrl;
|
|
6
|
+
exports.getCroppedImageUrl = getCroppedImageUrl;
|
|
7
|
+
exports.getImageUrl = getImageUrl;
|
|
8
|
+
exports.getVideoUrl = getVideoUrl;
|
|
9
|
+
exports.getAudioUrl = getAudioUrl;
|
|
10
|
+
exports.getDocumentUrl = getDocumentUrl;
|
|
11
|
+
exports.decodeText = decodeText;
|
|
12
|
+
const image_kit_1 = require("@wix/image-kit");
|
|
13
|
+
const WIX_PROTOCOL = 'wix:';
|
|
14
|
+
const WIX_IMAGE = 'image';
|
|
15
|
+
const WIX_VIDEO = 'video';
|
|
16
|
+
const WIX_AUDIO = 'audio';
|
|
17
|
+
const WIX_DOCUMENT = 'document';
|
|
18
|
+
const WIX_IMAGE_URL = 'https://static.wixstatic.com/media/';
|
|
19
|
+
const WIX_VIDEO_URL = 'https://video.wixstatic.com/video/';
|
|
20
|
+
const WIX_AUDIO_URL = 'https://static.wixstatic.com/mp3/';
|
|
21
|
+
const WIX_DOCUMENT_URL = 'https://d945e594-8657-47e2-9cd9-e9033c3d8da0.usrfiles.com/ugd/';
|
|
22
|
+
function getScaledToFillImageUrl(wixMediaIdentifier, targetWidth, targetHeight, options) {
|
|
23
|
+
const img = getImageUrl(wixMediaIdentifier);
|
|
24
|
+
return image_kit_1.sdk.getScaleToFillImageURL(img.id, img.height, img.width, targetWidth, targetHeight, options);
|
|
25
|
+
}
|
|
26
|
+
function getScaledToFitImageUrl(wixMediaIdentifier, targetWidth, targetHeight, options) {
|
|
27
|
+
const img = getImageUrl(wixMediaIdentifier);
|
|
28
|
+
return image_kit_1.sdk.getScaleToFitImageURL(img.id, img.height, img.width, targetWidth, targetHeight, options);
|
|
29
|
+
}
|
|
30
|
+
function getCroppedImageUrl(wixMediaIdentifier, cropX, cropY, cropWidth, cropHeight, targetWidth, targetHeight, options) {
|
|
31
|
+
const img = getImageUrl(wixMediaIdentifier);
|
|
32
|
+
return image_kit_1.sdk.getCropImageURL(img.id, img.height, img.width, cropX, cropY, cropWidth, cropHeight, targetWidth, targetHeight, options);
|
|
33
|
+
}
|
|
34
|
+
function getImageUrl(val) {
|
|
35
|
+
let id, filenameOrAltText;
|
|
36
|
+
let height, width;
|
|
37
|
+
if (val.startsWith(WIX_IMAGE_URL)) {
|
|
38
|
+
id = val.split(WIX_IMAGE_URL).pop().split('/')[0];
|
|
39
|
+
width = val.split('/w_').pop().split(',')[0];
|
|
40
|
+
height = val.split(',h_').pop().split(',')[0];
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const alignedImage = alignIfLegacy(val, WIX_IMAGE);
|
|
44
|
+
const { hash, pathname } = new URL(alignedImage);
|
|
45
|
+
const params = new URLSearchParams(hash.replace('#', ''));
|
|
46
|
+
height = params.get('originHeight');
|
|
47
|
+
width = params.get('originWidth');
|
|
48
|
+
[id, filenameOrAltText] = pathname
|
|
49
|
+
.replace(`${WIX_IMAGE}://v1/`, '')
|
|
50
|
+
.split('/');
|
|
51
|
+
}
|
|
52
|
+
// @ts-expect-error
|
|
53
|
+
const decodedFilenameOrAltText = decodeText(filenameOrAltText);
|
|
54
|
+
const res = {
|
|
55
|
+
id,
|
|
56
|
+
url: `${WIX_IMAGE_URL}${id}`,
|
|
57
|
+
height: Number(height),
|
|
58
|
+
width: Number(width),
|
|
59
|
+
};
|
|
60
|
+
if (!decodedFilenameOrAltText) {
|
|
61
|
+
return res;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
...res,
|
|
65
|
+
altText: decodedFilenameOrAltText,
|
|
66
|
+
filename: decodedFilenameOrAltText,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function getVideoUrl(val, resolution) {
|
|
70
|
+
let id, thumbnailId, thumbnailWidth, thumbnailHeight, decodedFilename = '';
|
|
71
|
+
if (val.startsWith(WIX_VIDEO_URL)) {
|
|
72
|
+
id = val.split(WIX_VIDEO_URL).pop().split('/')[0];
|
|
73
|
+
thumbnailId = `${id}.jpg`;
|
|
74
|
+
thumbnailWidth = '50';
|
|
75
|
+
thumbnailHeight = '50';
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const alignedVideo = alignIfLegacy(val, WIX_VIDEO);
|
|
79
|
+
const { pathname, hash } = new URL(alignedVideo);
|
|
80
|
+
const hashParams = new URLSearchParams(hash.replace('#', ''));
|
|
81
|
+
const [_id, fileName] = pathname
|
|
82
|
+
.replace(`${WIX_VIDEO}://v1/`, '')
|
|
83
|
+
.split('/');
|
|
84
|
+
id = _id;
|
|
85
|
+
thumbnailId = hashParams.get('posterUri') || `${id}.jpg`;
|
|
86
|
+
thumbnailWidth = hashParams.get('posterWidth') || '50';
|
|
87
|
+
thumbnailHeight = hashParams.get('posterHeight') || '50';
|
|
88
|
+
decodedFilename = decodeText(fileName);
|
|
89
|
+
}
|
|
90
|
+
const res = {
|
|
91
|
+
id,
|
|
92
|
+
url: `${WIX_VIDEO_URL}${id}/${resolution ? `${resolution}/mp4/file.mp4` : 'file'}`,
|
|
93
|
+
thumbnail: `${WIX_PROTOCOL}${WIX_IMAGE}://v1/${thumbnailId}#originWidth=${thumbnailWidth}&originHeight=${thumbnailHeight}`,
|
|
94
|
+
};
|
|
95
|
+
if (!decodedFilename) {
|
|
96
|
+
return res;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
...res,
|
|
100
|
+
filename: decodedFilename,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function getAudioUrl(val) {
|
|
104
|
+
const alignedAudio = alignIfLegacy(val, WIX_AUDIO);
|
|
105
|
+
const { pathname, hash } = new URL(alignedAudio);
|
|
106
|
+
const [id, filename] = pathname.replace(`${WIX_AUDIO}://v1/`, '').split('/');
|
|
107
|
+
const decodedFilename = decodeText(filename);
|
|
108
|
+
const hashParams = new URLSearchParams(hash.replace('#', ''));
|
|
109
|
+
const res = {
|
|
110
|
+
id,
|
|
111
|
+
duration: Number(hashParams.get('duration') || ''),
|
|
112
|
+
url: `${WIX_AUDIO_URL}${id}`,
|
|
113
|
+
};
|
|
114
|
+
if (!decodedFilename) {
|
|
115
|
+
return res;
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
...res,
|
|
119
|
+
filename: decodedFilename,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function getDocumentUrl(val) {
|
|
123
|
+
const valWithoutUGD = val.replace('v1/ugd', 'v1');
|
|
124
|
+
const alignedDocument = alignIfLegacy(valWithoutUGD, WIX_DOCUMENT);
|
|
125
|
+
const { pathname } = new URL(alignedDocument);
|
|
126
|
+
const [id, filename] = pathname
|
|
127
|
+
.replace(`${WIX_DOCUMENT}://v1/`, '')
|
|
128
|
+
.split('/');
|
|
129
|
+
const decodedFilename = decodeText(filename);
|
|
130
|
+
const res = {
|
|
131
|
+
id,
|
|
132
|
+
url: `${WIX_DOCUMENT_URL}${id}`,
|
|
133
|
+
};
|
|
134
|
+
if (!decodedFilename) {
|
|
135
|
+
return res;
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
...res,
|
|
139
|
+
filename: decodedFilename,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function decodeText(s) {
|
|
143
|
+
if (!s) {
|
|
144
|
+
return s;
|
|
145
|
+
}
|
|
146
|
+
return decodeURIComponent(s);
|
|
147
|
+
}
|
|
148
|
+
function alignIfLegacy(url, type) {
|
|
149
|
+
const { protocol } = new URL(url);
|
|
150
|
+
return protocol === `${type}:` ? `${WIX_PROTOCOL}${url}` : url;
|
|
151
|
+
}
|
|
152
|
+
var VideoResolution;
|
|
153
|
+
(function (VideoResolution) {
|
|
154
|
+
VideoResolution["MOBILE"] = "360p";
|
|
155
|
+
VideoResolution["LOW"] = "480p";
|
|
156
|
+
VideoResolution["MID"] = "720p";
|
|
157
|
+
VideoResolution["HIGH"] = "1080p";
|
|
158
|
+
})(VideoResolution || (exports.VideoResolution = VideoResolution = {}));
|
package/cjs/build/wixMedia.d.ts
CHANGED
|
@@ -1,39 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function getScaledToFitImageUrl(wixMediaIdentifier: string, targetWidth: number, targetHeight: number, options: ImageTransformOptions): string;
|
|
4
|
-
declare function getCroppedImageUrl(wixMediaIdentifier: string, cropX: number, cropY: number, cropWidth: number, cropHeight: number, targetWidth: number, targetHeight: number, options?: ImageTransformOptions): string;
|
|
5
|
-
declare function getImageUrl(val: string): {
|
|
6
|
-
id: string;
|
|
7
|
-
url: string;
|
|
8
|
-
height: number;
|
|
9
|
-
width: number;
|
|
10
|
-
altText?: string;
|
|
11
|
-
filename?: string;
|
|
12
|
-
};
|
|
13
|
-
declare function getVideoUrl(val: string, resolution?: VideoResolution): {
|
|
14
|
-
id: string;
|
|
15
|
-
url: string;
|
|
16
|
-
thumbnail: string;
|
|
17
|
-
filename?: string;
|
|
18
|
-
};
|
|
19
|
-
declare function getAudioUrl(val: string): {
|
|
20
|
-
id: string;
|
|
21
|
-
url: string;
|
|
22
|
-
duration: number;
|
|
23
|
-
filename?: string;
|
|
24
|
-
};
|
|
25
|
-
declare function getDocumentUrl(val: string): {
|
|
26
|
-
id: string;
|
|
27
|
-
url: string;
|
|
28
|
-
filename?: string;
|
|
29
|
-
};
|
|
30
|
-
export declare function decodeText(s: string): string;
|
|
31
|
-
export declare enum VideoResolution {
|
|
32
|
-
MOBILE = "360p",
|
|
33
|
-
LOW = "480p",
|
|
34
|
-
MID = "720p",
|
|
35
|
-
HIGH = "1080p"
|
|
36
|
-
}
|
|
1
|
+
import { getAudioUrl, getCroppedImageUrl, getDocumentUrl, getImageUrl, getScaledToFillImageUrl, getScaledToFitImageUrl, getVideoUrl } from './media/helpers.js';
|
|
2
|
+
export { VideoResolution, decodeText } from './media/helpers.js';
|
|
37
3
|
export declare const media: {
|
|
38
4
|
getCroppedImageUrl: typeof getCroppedImageUrl;
|
|
39
5
|
getScaledToFillImageUrl: typeof getScaledToFillImageUrl;
|
|
@@ -43,4 +9,3 @@ export declare const media: {
|
|
|
43
9
|
getAudioUrl: typeof getAudioUrl;
|
|
44
10
|
getDocumentUrl: typeof getDocumentUrl;
|
|
45
11
|
};
|
|
46
|
-
export {};
|
package/cjs/build/wixMedia.js
CHANGED
|
@@ -1,160 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.media = exports.VideoResolution = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const WIX_VIDEO = 'video';
|
|
9
|
-
const WIX_AUDIO = 'audio';
|
|
10
|
-
const WIX_DOCUMENT = 'document';
|
|
11
|
-
const WIX_IMAGE_URL = 'https://static.wixstatic.com/media/';
|
|
12
|
-
const WIX_VIDEO_URL = 'https://video.wixstatic.com/video/';
|
|
13
|
-
const WIX_AUDIO_URL = 'https://static.wixstatic.com/mp3/';
|
|
14
|
-
const WIX_DOCUMENT_URL = 'https://d945e594-8657-47e2-9cd9-e9033c3d8da0.usrfiles.com/ugd/';
|
|
15
|
-
function getScaledToFillImageUrl(wixMediaIdentifier, targetWidth, targetHeight, options) {
|
|
16
|
-
const img = getImageUrl(wixMediaIdentifier);
|
|
17
|
-
return image_kit_1.sdk.getScaleToFillImageURL(img.id, img.height, img.width, targetWidth, targetHeight, options);
|
|
18
|
-
}
|
|
19
|
-
function getScaledToFitImageUrl(wixMediaIdentifier, targetWidth, targetHeight, options) {
|
|
20
|
-
const img = getImageUrl(wixMediaIdentifier);
|
|
21
|
-
return image_kit_1.sdk.getScaleToFitImageURL(img.id, img.height, img.width, targetWidth, targetHeight, options);
|
|
22
|
-
}
|
|
23
|
-
function getCroppedImageUrl(wixMediaIdentifier, cropX, cropY, cropWidth, cropHeight, targetWidth, targetHeight, options) {
|
|
24
|
-
const img = getImageUrl(wixMediaIdentifier);
|
|
25
|
-
return image_kit_1.sdk.getCropImageURL(img.id, img.height, img.width, cropX, cropY, cropWidth, cropHeight, targetWidth, targetHeight, options);
|
|
26
|
-
}
|
|
27
|
-
function getImageUrl(val) {
|
|
28
|
-
let id, filenameOrAltText;
|
|
29
|
-
let height, width;
|
|
30
|
-
if (val.startsWith(WIX_IMAGE_URL)) {
|
|
31
|
-
id = val.split(WIX_IMAGE_URL).pop().split('/')[0];
|
|
32
|
-
width = val.split('/w_').pop().split(',')[0];
|
|
33
|
-
height = val.split(',h_').pop().split(',')[0];
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
const alignedImage = alignIfLegacy(val, WIX_IMAGE);
|
|
37
|
-
const { hash, pathname } = new URL(alignedImage);
|
|
38
|
-
const params = new URLSearchParams(hash.replace('#', ''));
|
|
39
|
-
height = params.get('originHeight');
|
|
40
|
-
width = params.get('originWidth');
|
|
41
|
-
[id, filenameOrAltText] = pathname
|
|
42
|
-
.replace(`${WIX_IMAGE}://v1/`, '')
|
|
43
|
-
.split('/');
|
|
44
|
-
}
|
|
45
|
-
// @ts-expect-error
|
|
46
|
-
const decodedFilenameOrAltText = decodeText(filenameOrAltText);
|
|
47
|
-
const res = {
|
|
48
|
-
id,
|
|
49
|
-
url: `${WIX_IMAGE_URL}${id}`,
|
|
50
|
-
height: Number(height),
|
|
51
|
-
width: Number(width),
|
|
52
|
-
};
|
|
53
|
-
if (!decodedFilenameOrAltText) {
|
|
54
|
-
return res;
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
...res,
|
|
58
|
-
altText: decodedFilenameOrAltText,
|
|
59
|
-
filename: decodedFilenameOrAltText,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function getVideoUrl(val, resolution) {
|
|
63
|
-
let id, thumbnailId, thumbnailWidth, thumbnailHeight, decodedFilename = '';
|
|
64
|
-
if (val.startsWith(WIX_VIDEO_URL)) {
|
|
65
|
-
id = val.split(WIX_VIDEO_URL).pop().split('/')[0];
|
|
66
|
-
thumbnailId = `${id}.jpg`;
|
|
67
|
-
thumbnailWidth = '50';
|
|
68
|
-
thumbnailHeight = '50';
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
const alignedVideo = alignIfLegacy(val, WIX_VIDEO);
|
|
72
|
-
const { pathname, hash } = new URL(alignedVideo);
|
|
73
|
-
const hashParams = new URLSearchParams(hash.replace('#', ''));
|
|
74
|
-
const [_id, fileName] = pathname
|
|
75
|
-
.replace(`${WIX_VIDEO}://v1/`, '')
|
|
76
|
-
.split('/');
|
|
77
|
-
id = _id;
|
|
78
|
-
thumbnailId = hashParams.get('posterUri') || `${id}.jpg`;
|
|
79
|
-
thumbnailWidth = hashParams.get('posterWidth') || '50';
|
|
80
|
-
thumbnailHeight = hashParams.get('posterHeight') || '50';
|
|
81
|
-
decodedFilename = decodeText(fileName);
|
|
82
|
-
}
|
|
83
|
-
const res = {
|
|
84
|
-
id,
|
|
85
|
-
url: `${WIX_VIDEO_URL}${id}/${resolution ? `${resolution}/mp4/file.mp4` : 'file'}`,
|
|
86
|
-
thumbnail: `${WIX_PROTOCOL}${WIX_IMAGE}://v1/${thumbnailId}#originWidth=${thumbnailWidth}&originHeight=${thumbnailHeight}`,
|
|
87
|
-
};
|
|
88
|
-
if (!decodedFilename) {
|
|
89
|
-
return res;
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
...res,
|
|
93
|
-
filename: decodedFilename,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
function getAudioUrl(val) {
|
|
97
|
-
const alignedAudio = alignIfLegacy(val, WIX_AUDIO);
|
|
98
|
-
const { pathname, hash } = new URL(alignedAudio);
|
|
99
|
-
const [id, filename] = pathname.replace(`${WIX_AUDIO}://v1/`, '').split('/');
|
|
100
|
-
const decodedFilename = decodeText(filename);
|
|
101
|
-
const hashParams = new URLSearchParams(hash.replace('#', ''));
|
|
102
|
-
const res = {
|
|
103
|
-
id,
|
|
104
|
-
duration: Number(hashParams.get('duration') || ''),
|
|
105
|
-
url: `${WIX_AUDIO_URL}${id}`,
|
|
106
|
-
};
|
|
107
|
-
if (!decodedFilename) {
|
|
108
|
-
return res;
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
...res,
|
|
112
|
-
filename: decodedFilename,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
function getDocumentUrl(val) {
|
|
116
|
-
const valWithoutUGD = val.replace('v1/ugd', 'v1');
|
|
117
|
-
const alignedDocument = alignIfLegacy(valWithoutUGD, WIX_DOCUMENT);
|
|
118
|
-
const { pathname } = new URL(alignedDocument);
|
|
119
|
-
const [id, filename] = pathname
|
|
120
|
-
.replace(`${WIX_DOCUMENT}://v1/`, '')
|
|
121
|
-
.split('/');
|
|
122
|
-
const decodedFilename = decodeText(filename);
|
|
123
|
-
const res = {
|
|
124
|
-
id,
|
|
125
|
-
url: `${WIX_DOCUMENT_URL}${id}`,
|
|
126
|
-
};
|
|
127
|
-
if (!decodedFilename) {
|
|
128
|
-
return res;
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
...res,
|
|
132
|
-
filename: decodedFilename,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
function decodeText(s) {
|
|
136
|
-
if (!s) {
|
|
137
|
-
return s;
|
|
138
|
-
}
|
|
139
|
-
return decodeURIComponent(s);
|
|
140
|
-
}
|
|
141
|
-
function alignIfLegacy(url, type) {
|
|
142
|
-
const { protocol } = new URL(url);
|
|
143
|
-
return protocol === `${type}:` ? `${WIX_PROTOCOL}${url}` : url;
|
|
144
|
-
}
|
|
145
|
-
var VideoResolution;
|
|
146
|
-
(function (VideoResolution) {
|
|
147
|
-
VideoResolution["MOBILE"] = "360p";
|
|
148
|
-
VideoResolution["LOW"] = "480p";
|
|
149
|
-
VideoResolution["MID"] = "720p";
|
|
150
|
-
VideoResolution["HIGH"] = "1080p";
|
|
151
|
-
})(VideoResolution || (exports.VideoResolution = VideoResolution = {}));
|
|
3
|
+
exports.media = exports.decodeText = exports.VideoResolution = void 0;
|
|
4
|
+
const helpers_js_1 = require("./media/helpers.js");
|
|
5
|
+
var helpers_js_2 = require("./media/helpers.js");
|
|
6
|
+
Object.defineProperty(exports, "VideoResolution", { enumerable: true, get: function () { return helpers_js_2.VideoResolution; } });
|
|
7
|
+
Object.defineProperty(exports, "decodeText", { enumerable: true, get: function () { return helpers_js_2.decodeText; } });
|
|
152
8
|
exports.media = {
|
|
153
|
-
getCroppedImageUrl,
|
|
154
|
-
getScaledToFillImageUrl,
|
|
155
|
-
getScaledToFitImageUrl,
|
|
156
|
-
getImageUrl,
|
|
157
|
-
getVideoUrl,
|
|
158
|
-
getAudioUrl,
|
|
159
|
-
getDocumentUrl,
|
|
9
|
+
getCroppedImageUrl: helpers_js_1.getCroppedImageUrl,
|
|
10
|
+
getScaledToFillImageUrl: helpers_js_1.getScaledToFillImageUrl,
|
|
11
|
+
getScaledToFitImageUrl: helpers_js_1.getScaledToFitImageUrl,
|
|
12
|
+
getImageUrl: helpers_js_1.getImageUrl,
|
|
13
|
+
getVideoUrl: helpers_js_1.getVideoUrl,
|
|
14
|
+
getAudioUrl: helpers_js_1.getAudioUrl,
|
|
15
|
+
getDocumentUrl: helpers_js_1.getDocumentUrl,
|
|
160
16
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ronny Ringel",
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
"./auth/velo": {
|
|
39
39
|
"import": "./build/auth/VeloAuthStrategy.js",
|
|
40
40
|
"require": "./cjs/build/auth/VeloAuthStrategy.js"
|
|
41
|
+
},
|
|
42
|
+
"./media": {
|
|
43
|
+
"import": "./build/media/helpers.js",
|
|
44
|
+
"require": "./cjs/build/media/helpers.js"
|
|
41
45
|
}
|
|
42
46
|
},
|
|
43
47
|
"sideEffects": false,
|
|
@@ -46,7 +50,8 @@
|
|
|
46
50
|
"auth",
|
|
47
51
|
"client",
|
|
48
52
|
"cjs",
|
|
49
|
-
"context"
|
|
53
|
+
"context",
|
|
54
|
+
"media"
|
|
50
55
|
],
|
|
51
56
|
"publishConfig": {
|
|
52
57
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -67,23 +72,23 @@
|
|
|
67
72
|
"@wix/image-kit": "^1.102.0",
|
|
68
73
|
"@wix/redirects": "^1.0.70",
|
|
69
74
|
"@wix/sdk-context": "^0.0.1",
|
|
70
|
-
"@wix/sdk-runtime": "0.3.
|
|
71
|
-
"@wix/sdk-types": "^1.13.
|
|
75
|
+
"@wix/sdk-runtime": "0.3.35",
|
|
76
|
+
"@wix/sdk-types": "^1.13.3",
|
|
72
77
|
"jose": "^5.9.6",
|
|
73
|
-
"type-fest": "^4.
|
|
78
|
+
"type-fest": "^4.34.1"
|
|
74
79
|
},
|
|
75
80
|
"optionalDependencies": {
|
|
76
81
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
|
|
77
82
|
},
|
|
78
83
|
"devDependencies": {
|
|
79
84
|
"@types/is-ci": "^3.0.4",
|
|
80
|
-
"@types/node": "^20.17.
|
|
81
|
-
"@vitest/ui": "^1.6.
|
|
85
|
+
"@types/node": "^20.17.19",
|
|
86
|
+
"@vitest/ui": "^1.6.1",
|
|
82
87
|
"@wix/ecom": "^1.0.886",
|
|
83
88
|
"@wix/events": "^1.0.382",
|
|
84
89
|
"@wix/metro": "^1.0.93",
|
|
85
90
|
"@wix/metro-runtime": "^1.1891.0",
|
|
86
|
-
"@wix/sdk-runtime": "0.3.
|
|
91
|
+
"@wix/sdk-runtime": "0.3.35",
|
|
87
92
|
"eslint": "^8.57.1",
|
|
88
93
|
"eslint-config-sdk": "0.0.0",
|
|
89
94
|
"graphql": "^16.8.0",
|
|
@@ -91,7 +96,7 @@
|
|
|
91
96
|
"jsdom": "^22.1.0",
|
|
92
97
|
"msw": "^2.7.0",
|
|
93
98
|
"typescript": "^5.7.3",
|
|
94
|
-
"vitest": "^1.6.
|
|
99
|
+
"vitest": "^1.6.1",
|
|
95
100
|
"vitest-teamcity-reporter": "^0.3.1"
|
|
96
101
|
},
|
|
97
102
|
"yoshiFlowLibrary": {
|
|
@@ -117,5 +122,5 @@
|
|
|
117
122
|
"wallaby": {
|
|
118
123
|
"autoDetect": true
|
|
119
124
|
},
|
|
120
|
-
"falconPackageHash": "
|
|
125
|
+
"falconPackageHash": "429ddea4461d1b04a52fd7c3fd22843f303a0d897693ed0d6118a2b5"
|
|
121
126
|
}
|