@cntrl-site/sdk-nextjs 1.5.0 → 1.5.1
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.
|
@@ -8,18 +8,27 @@ var Allowed;
|
|
|
8
8
|
})(Allowed || (Allowed = {}));
|
|
9
9
|
function getYoutubeId({ hostname, pathname, search }) {
|
|
10
10
|
if (hostname !== Allowed.Full && hostname !== Allowed.Tiny) {
|
|
11
|
-
throw new Error(`Cannot get valid
|
|
11
|
+
throw new Error(`Cannot get valid YouTube ID from "${hostname}" - address is not whitelisted`);
|
|
12
12
|
}
|
|
13
13
|
switch (hostname) {
|
|
14
14
|
case Allowed.Tiny:
|
|
15
15
|
return pathname.replace('/', '');
|
|
16
16
|
case Allowed.Full:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
if (pathname.startsWith('/shorts/')) {
|
|
18
|
+
const shortsId = pathname.split('/shorts/')[1];
|
|
19
|
+
if (!shortsId) {
|
|
20
|
+
throw new Error('Cannot get valid YouTube Shorts ID from the pathname.');
|
|
21
|
+
}
|
|
22
|
+
return shortsId;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const searchParams = new URLSearchParams(search);
|
|
26
|
+
const id = searchParams.get('v');
|
|
27
|
+
if (!id) {
|
|
28
|
+
throw new Error('Cannot get valid YouTube ID from search params.');
|
|
29
|
+
}
|
|
30
|
+
return id;
|
|
21
31
|
}
|
|
22
|
-
return id;
|
|
23
32
|
}
|
|
24
33
|
}
|
|
25
34
|
exports.getYoutubeId = getYoutubeId;
|
package/package.json
CHANGED
|
@@ -5,17 +5,25 @@ enum Allowed {
|
|
|
5
5
|
|
|
6
6
|
export function getYoutubeId({ hostname, pathname, search }: URL): string {
|
|
7
7
|
if (hostname !== Allowed.Full && hostname !== Allowed.Tiny) {
|
|
8
|
-
throw new Error(`Cannot get valid
|
|
8
|
+
throw new Error(`Cannot get valid YouTube ID from "${hostname}" - address is not whitelisted`);
|
|
9
9
|
}
|
|
10
10
|
switch (hostname) {
|
|
11
11
|
case Allowed.Tiny:
|
|
12
12
|
return pathname.replace('/', '');
|
|
13
13
|
case Allowed.Full:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
if (pathname.startsWith('/shorts/')) {
|
|
15
|
+
const shortsId = pathname.split('/shorts/')[1];
|
|
16
|
+
if (!shortsId) {
|
|
17
|
+
throw new Error('Cannot get valid YouTube Shorts ID from the pathname.');
|
|
18
|
+
}
|
|
19
|
+
return shortsId;
|
|
20
|
+
} else {
|
|
21
|
+
const searchParams = new URLSearchParams(search);
|
|
22
|
+
const id = searchParams.get('v');
|
|
23
|
+
if (!id) {
|
|
24
|
+
throw new Error('Cannot get valid YouTube ID from search params.');
|
|
25
|
+
}
|
|
26
|
+
return id;
|
|
18
27
|
}
|
|
19
|
-
return id;
|
|
20
28
|
}
|
|
21
29
|
}
|
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/sdk-nextjs.iml" filepath="$PROJECT_DIR$/.idea/sdk-nextjs.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
package/.idea/sdk-nextjs.iml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="WEB_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$">
|
|
5
|
-
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
6
|
-
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
7
|
-
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
-
</content>
|
|
9
|
-
<orderEntry type="inheritedJdk" />
|
|
10
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
-
</component>
|
|
12
|
-
</module>
|