@blocklet/images 1.16.34-beta-20241214-102147-410be539 → 1.16.34-beta-20241218-045149-150af879
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/lib/index.d.ts +1 -0
- package/lib/index.js +15 -0
- package/lib/video.d.ts +12 -0
- package/lib/video.js +128 -0
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ import { validateLogo } from './logo-validate';
|
|
|
2
2
|
import { validateScreenshots } from './screenshot-validate';
|
|
3
3
|
import { ordinalSuffix } from './ordinal-suffix';
|
|
4
4
|
import { getBlurhash } from './blurhash';
|
|
5
|
+
export * from './video';
|
|
5
6
|
export { validateLogo, validateScreenshots, ordinalSuffix, getBlurhash };
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.getBlurhash = exports.ordinalSuffix = exports.validateScreenshots = exports.validateLogo = void 0;
|
|
4
18
|
const logo_validate_1 = require("./logo-validate");
|
|
@@ -9,3 +23,4 @@ const ordinal_suffix_1 = require("./ordinal-suffix");
|
|
|
9
23
|
Object.defineProperty(exports, "ordinalSuffix", { enumerable: true, get: function () { return ordinal_suffix_1.ordinalSuffix; } });
|
|
10
24
|
const blurhash_1 = require("./blurhash");
|
|
11
25
|
Object.defineProperty(exports, "getBlurhash", { enumerable: true, get: function () { return blurhash_1.getBlurhash; } });
|
|
26
|
+
__exportStar(require("./video"), exports);
|
package/lib/video.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare function getYoutubeId(link: string): string;
|
|
2
|
+
declare function getVimeoId(link: string): string;
|
|
3
|
+
declare function getVideoId(link: string): any;
|
|
4
|
+
declare function getEmbedUrl(link: string, { modestbranding, controls, autoplay }?: {
|
|
5
|
+
modestbranding?: number;
|
|
6
|
+
controls?: number;
|
|
7
|
+
autoplay?: number;
|
|
8
|
+
}): any;
|
|
9
|
+
declare function getVideoCoverUrl(link: string): any;
|
|
10
|
+
declare function getVideoCheckUrl(link: string): string;
|
|
11
|
+
declare function isVideoUrl(link: string): boolean;
|
|
12
|
+
export { getVideoId, getEmbedUrl, getVideoCoverUrl, getVideoCheckUrl, getYoutubeId, getVimeoId, isVideoUrl };
|
package/lib/video.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVideoId = getVideoId;
|
|
4
|
+
exports.getEmbedUrl = getEmbedUrl;
|
|
5
|
+
exports.getVideoCoverUrl = getVideoCoverUrl;
|
|
6
|
+
exports.getVideoCheckUrl = getVideoCheckUrl;
|
|
7
|
+
exports.getYoutubeId = getYoutubeId;
|
|
8
|
+
exports.getVimeoId = getVimeoId;
|
|
9
|
+
exports.isVideoUrl = isVideoUrl;
|
|
10
|
+
function getYoutubeId(link) {
|
|
11
|
+
const url = link.trim();
|
|
12
|
+
if (url.includes('youtu.be/')) {
|
|
13
|
+
return url.split('youtu.be/')[1]?.split('?')[0];
|
|
14
|
+
}
|
|
15
|
+
// 检查是否是嵌入格式
|
|
16
|
+
if (url.includes('/embed/')) {
|
|
17
|
+
return url.split('/embed/')[1]?.split('?')[0];
|
|
18
|
+
}
|
|
19
|
+
// 检查是否是标准格式
|
|
20
|
+
if (url.includes('youtube.com/watch')) {
|
|
21
|
+
const urlObj = new URL(url);
|
|
22
|
+
return urlObj.searchParams.get('v');
|
|
23
|
+
}
|
|
24
|
+
// 检查是否是短链视频格式
|
|
25
|
+
if (url.includes('youtube.com/shorts/')) {
|
|
26
|
+
return url.split('/shorts/')[1]?.split('?')[0];
|
|
27
|
+
}
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
function getVimeoId(link) {
|
|
31
|
+
const url = link.trim();
|
|
32
|
+
// 检查是否是嵌入格式
|
|
33
|
+
if (url.includes('/embed/')) {
|
|
34
|
+
return url.split('/embed/')[1]?.split('?')[0];
|
|
35
|
+
}
|
|
36
|
+
// 检查是否是标准格式
|
|
37
|
+
if (url.includes('vimeo.com/video/')) {
|
|
38
|
+
return url.split('/video/')[1]?.split('?')[0];
|
|
39
|
+
}
|
|
40
|
+
// 检查是否是频道视频格式
|
|
41
|
+
if (url.includes('vimeo.com/channels/')) {
|
|
42
|
+
return url.split('/channels/')[1]?.split('/')[1]?.split('?')[0];
|
|
43
|
+
}
|
|
44
|
+
// 检查是否是群组视频格式
|
|
45
|
+
if (url.includes('vimeo.com/groups/')) {
|
|
46
|
+
return url.split('/groups/')[1]?.split('/')[1]?.split('?')[0];
|
|
47
|
+
}
|
|
48
|
+
// 检查是否是标准短格式
|
|
49
|
+
if (url.includes('vimeo.com/')) {
|
|
50
|
+
return url.split('vimeo.com/')[1]?.split('?')[0];
|
|
51
|
+
}
|
|
52
|
+
return '';
|
|
53
|
+
}
|
|
54
|
+
const cacheVideoId = {};
|
|
55
|
+
function getVideoId(link) {
|
|
56
|
+
const url = link.trim();
|
|
57
|
+
if (!url || !/^https?:\/\/.+\..+/.test(url))
|
|
58
|
+
return [];
|
|
59
|
+
if (cacheVideoId[url])
|
|
60
|
+
return cacheVideoId[url];
|
|
61
|
+
cacheVideoId[url] = (() => {
|
|
62
|
+
const urlObj = new URL(url);
|
|
63
|
+
if (urlObj.host.includes('youtube.com') || urlObj.host.includes('youtu.be')) {
|
|
64
|
+
return [getYoutubeId(url), 'youtube'];
|
|
65
|
+
}
|
|
66
|
+
if (urlObj.host.includes('vimeo.com')) {
|
|
67
|
+
return [getVimeoId(url), 'vimeo'];
|
|
68
|
+
}
|
|
69
|
+
return [];
|
|
70
|
+
})();
|
|
71
|
+
return cacheVideoId[url];
|
|
72
|
+
}
|
|
73
|
+
const cacheEmbedUrl = {};
|
|
74
|
+
function getEmbedUrl(link, { modestbranding = 1, controls = 0, autoplay = 0 } = {}) {
|
|
75
|
+
const url = link.trim();
|
|
76
|
+
if (!url)
|
|
77
|
+
return '';
|
|
78
|
+
if (cacheEmbedUrl[url] !== undefined)
|
|
79
|
+
return cacheEmbedUrl[url];
|
|
80
|
+
const [id, platform] = getVideoId(url);
|
|
81
|
+
if (platform === 'youtube') {
|
|
82
|
+
cacheEmbedUrl[url] =
|
|
83
|
+
`https://www.youtube.com/embed/${id}?modestbranding=${modestbranding}&controls=${controls}&autoplay=${autoplay}`;
|
|
84
|
+
}
|
|
85
|
+
else if (platform === 'vimeo') {
|
|
86
|
+
cacheEmbedUrl[url] = `https://player.vimeo.com/video/${id}?autoplay=${autoplay}`;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
cacheEmbedUrl[url] = '';
|
|
90
|
+
}
|
|
91
|
+
return cacheEmbedUrl[url];
|
|
92
|
+
}
|
|
93
|
+
const cacheCoverUrl = {};
|
|
94
|
+
function getVideoCoverUrl(link) {
|
|
95
|
+
const url = link.trim();
|
|
96
|
+
if (!url)
|
|
97
|
+
return '';
|
|
98
|
+
if (cacheCoverUrl[url] !== undefined)
|
|
99
|
+
return cacheCoverUrl[url];
|
|
100
|
+
const [id, platform] = getVideoId(url);
|
|
101
|
+
if (platform === 'youtube') {
|
|
102
|
+
cacheCoverUrl[url] = `https://img.youtube.com/vi/${id}/mqdefault.jpg`;
|
|
103
|
+
}
|
|
104
|
+
else if (platform === 'vimeo') {
|
|
105
|
+
cacheCoverUrl[url] = `https://i.vimeocdn.com/${id}/1000x563`;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
cacheCoverUrl[url] = '';
|
|
109
|
+
}
|
|
110
|
+
return cacheCoverUrl[url];
|
|
111
|
+
}
|
|
112
|
+
function getVideoCheckUrl(link) {
|
|
113
|
+
const url = link.trim();
|
|
114
|
+
if (!url)
|
|
115
|
+
return '';
|
|
116
|
+
const [id, platform] = getVideoId(url);
|
|
117
|
+
if (platform === 'youtube') {
|
|
118
|
+
return `https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=${id}&format=json`;
|
|
119
|
+
}
|
|
120
|
+
if (platform === 'vimeo') {
|
|
121
|
+
return `https://vimeo.com/api/oembed.json?url=https://vimeo.com/${id}`;
|
|
122
|
+
}
|
|
123
|
+
return '';
|
|
124
|
+
}
|
|
125
|
+
function isVideoUrl(link) {
|
|
126
|
+
const url = link.trim();
|
|
127
|
+
return getVideoId(url).length > 0;
|
|
128
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/images",
|
|
3
|
-
"version": "1.16.34-beta-
|
|
3
|
+
"version": "1.16.34-beta-20241218-045149-150af879",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"ts-node": "^10.9.1",
|
|
55
55
|
"typescript": "^5.6.3"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "91907df23611fc7d41194669bc0831af1909114c"
|
|
58
58
|
}
|