From b48d452abf39531ac85eb8109a1c8e6b0f5ec827 Mon Sep 17 00:00:00 2001 From: 3y3 <3y3@ya.ru> Date: Thu, 5 Sep 2024 23:08:53 +0300 Subject: [PATCH] fix: Trim new video formats names --- src/transform/plugins/video/const.ts | 8 ++++---- src/transform/plugins/video/index.ts | 4 ++-- src/transform/plugins/video/parsers.ts | 20 ++++++++++---------- src/transform/plugins/video/types.ts | 4 ++-- src/transform/plugins/video/utils.ts | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/transform/plugins/video/const.ts b/src/transform/plugins/video/const.ts index bfc8e12c..72822621 100644 --- a/src/transform/plugins/video/const.ts +++ b/src/transform/plugins/video/const.ts @@ -9,8 +9,8 @@ export enum VideoService { Vine = 'vine', Prezi = 'prezi', Osf = 'osf', - YandexVideo = 'yandexVideo', - VkVideo = 'vkVideo', + Yandex = 'yandex', + Vk = 'vk', } export const defaults: VideoFullOptions = { @@ -20,6 +20,6 @@ export const defaults: VideoFullOptions = { vine: {width: 600, height: 600, embed: 'simple'}, prezi: {width: 550, height: 400}, osf: {width: '100%', height: '100%'}, - yandexVideo: {width: 640, height: 390}, - vkVideo: {width: 640, height: 390}, + yandex: {width: 640, height: 390}, + vk: {width: 640, height: 390}, }; diff --git a/src/transform/plugins/video/index.ts b/src/transform/plugins/video/index.ts index de67187f..785d0631 100644 --- a/src/transform/plugins/video/index.ts +++ b/src/transform/plugins/video/index.ts @@ -3,8 +3,8 @@ // Process @[vine](vineVideoID) // Process @[prezi](preziID) // Process @[osf](guid) -// Process @[yandexVideo](videoID) -// Process @[vkVideo](videoID) +// Process @[yandex](videoID) +// Process @[vk](videoID) import type MarkdownIt from 'markdown-it'; // eslint-disable-next-line no-duplicate-imports diff --git a/src/transform/plugins/video/parsers.ts b/src/transform/plugins/video/parsers.ts index 50c3adf1..d0b5dda3 100644 --- a/src/transform/plugins/video/parsers.ts +++ b/src/transform/plugins/video/parsers.ts @@ -33,15 +33,15 @@ export function mfrParser(url: string) { return match ? match[1] : url; } -const yandexVideoRegex = /^https:\/\/runtime.video.cloud.yandex.net\/player\/video\/([a-zA-Z0-9]+)/; -export function yandexVideoParser(url: string) { - const match = url.match(yandexVideoRegex); +const yandexRegex = /^https:\/\/runtime.video.cloud.yandex.net\/player\/video\/([a-zA-Z0-9]+)/; +export function yandexParser(url: string) { + const match = url.match(yandexRegex); return match ? match[1] : url; } -const vkVideoRegex = /^https:\/\/vk.com\/video_ext\.php?(oid=[-\d]+&id=[-\d]+)/; -export function vkVideoParser(url: string) { - const match = url.match(vkVideoRegex); +const vkRegex = /^https:\/\/vk.com\/video_ext\.php?(oid=[-\d]+&id=[-\d]+)/; +export function vkParser(url: string) { + const match = url.match(vkRegex); return match ? match[1] : url; } @@ -64,11 +64,11 @@ export function parseVideoUrl(service: string, url: string): string | false { case VideoService.Osf: videoID = mfrParser(url); break; - case VideoService.YandexVideo: - videoID = yandexVideoParser(url); + case VideoService.Yandex: + videoID = yandexParser(url); break; - case VideoService.VkVideo: - videoID = vkVideoParser(url); + case VideoService.Vk: + videoID = vkParser(url); break; default: return false; diff --git a/src/transform/plugins/video/types.ts b/src/transform/plugins/video/types.ts index 5de58534..46409ba3 100644 --- a/src/transform/plugins/video/types.ts +++ b/src/transform/plugins/video/types.ts @@ -12,8 +12,8 @@ export type VideoServicesOptions = { [VideoService.Vine]: {width: number; height: number; embed: 'simple' | string}; [VideoService.Prezi]: {width: number; height: number}; [VideoService.Osf]: {width: string; height: string}; - [VideoService.YandexVideo]: {width: number; height: number}; - [VideoService.VkVideo]: {width: number; height: number}; + [VideoService.Yandex]: {width: number; height: number}; + [VideoService.Vk]: {width: number; height: number}; }; export type VideoFullOptions = VideoServicesOptions & { diff --git a/src/transform/plugins/video/utils.ts b/src/transform/plugins/video/utils.ts index d25b8432..9b609155 100644 --- a/src/transform/plugins/video/utils.ts +++ b/src/transform/plugins/video/utils.ts @@ -17,9 +17,9 @@ export const videoUrl: VideoUrlFn = (service, videoID, options) => { ); case 'osf': return `https://mfr.osf.io/render?url=https://osf.io/${videoID}/?action=download`; - case 'yandexVideo': + case 'yandex': return `https://runtime.video.cloud.yandex.net/player/${videoID}`; - case 'vkVideo': + case 'vk': return `https://vk.com/video_ext.php?${videoID}`; default: return service;