From 7289d5b401d566bfb71e624b8562b504b7358af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= <root@acid-chicken.com> Date: Thu, 9 Aug 2018 16:44:34 +0900 Subject: [PATCH 1/4] Add player --- .../common/views/components/url-preview.vue | 56 ++++++------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/src/client/app/common/views/components/url-preview.vue b/src/client/app/common/views/components/url-preview.vue index 4f1e34c6ca..6100c1fbfb 100644 --- a/src/client/app/common/views/components/url-preview.vue +++ b/src/client/app/common/views/components/url-preview.vue @@ -1,12 +1,6 @@ <template> -<iframe v-if="youtubeId" type="text/html" height="250" - :src="`https://www.youtube.com/embed/${youtubeId}?origin=${misskeyUrl}`" - frameborder="0"/> -<iframe v-else-if="spotifyId" - :src="`https://open.spotify.com/embed/track/${spotifyId}`" - frameborder="0" allowtransparency="true" allow="encrypted-media" /> -<iframe v-else-if="nicovideoId" - :src="`https://embed.nicovideo.jp/watch/${nicovideoId}?oldScript=1&referer=${misskeyUrl}&from=${position || '0'}&allowProgrammaticFullScreen=1`" +<iframe v-if="player" + :src="player" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen /> <div v-else-if="tweetUrl && detail" class="twitter"> <blockquote ref="tweet" class="twitter-tweet" :data-theme="$store.state.device.darkmode ? 'dark' : null"> @@ -54,10 +48,7 @@ export default Vue.extend({ thumbnail: null, icon: null, sitename: null, - youtubeId: null, - spotifyId: null, - nicovideoId: null, - position: null, + player: null, tweetUrl: null, misskeyUrl }; @@ -65,23 +56,7 @@ export default Vue.extend({ created() { const url = new URL(this.url); - if (url.hostname == 'www.youtube.com') { - this.youtubeId = url.searchParams.get('v'); - return; - } else if (url.hostname == 'youtu.be') { - this.youtubeId = url.pathname; - return; - } else if (url.hostname == 'open.spotify.com') { - this.spotifyId = url.pathname.split('/').reverse().filter(x => x !== '')[0]; - return; - } else if (['nicovideo.jp', 'www.nicovideo.jp', 'nico.ms'].includes(url.hostname)) { - const id = url.pathname.split('/').reverse().filter(x => x !== '')[0]; - if (['sm', 'nm', 'ax', 'ca', 'cd', 'cw', 'fx', 'ig', 'na', 'om', 'sd', 'sk', 'yk', 'yo', 'za', 'zb', 'zc', 'zd', 'ze', 'nl', 'so', ...Array(10).keys()].some(x => id.startsWith(x)) { - this.nicovideoId = id; - this.position = url.searchParams.get('from'); - return; - } - } else if (this.detail && url.hostname == 'twitter.com' && /^\/.+\/status(es)?\/\d+/.test(url.pathname)) { + if (this.detail && url.hostname == 'twitter.com' && /^\/.+\/status(es)?\/\d+/.test(url.pathname)) { this.tweetUrl = url; const twttr = (window as any).twttr || {}; const loadTweet = () => twttr.widgets.load(this.$refs.tweet); @@ -100,19 +75,20 @@ export default Vue.extend({ twttr.ready = loadTweet; (window as any).twttr = twttr; } - return; - } - fetch('/url?url=' + encodeURIComponent(this.url)).then(res => { - res.json().then(info => { - this.title = info.title; - this.description = info.description; - this.thumbnail = info.thumbnail; - this.icon = info.icon; - this.sitename = info.sitename; + } else { + fetch('/url?url=' + encodeURIComponent(this.url)).then(res => { + res.json().then(info => { + this.title = info.title; + this.description = info.description; + this.thumbnail = info.thumbnail; + this.player = info.player; + this.icon = info.icon; + this.sitename = info.sitename; - this.fetching = false; + this.fetching = false; + }); }); - }); + } } }); </script> From 1b9f29395987270e823dc73bdef77daff567c85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= <root@acid-chicken.com> Date: Thu, 9 Aug 2018 23:34:54 +0900 Subject: [PATCH 2/4] Update url-preview.vue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 多分もう折り返す必要はないのだわ --- src/client/app/common/views/components/url-preview.vue | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/client/app/common/views/components/url-preview.vue b/src/client/app/common/views/components/url-preview.vue index 6100c1fbfb..0cfa76fd80 100644 --- a/src/client/app/common/views/components/url-preview.vue +++ b/src/client/app/common/views/components/url-preview.vue @@ -1,7 +1,5 @@ <template> -<iframe v-if="player" - :src="player" - frameborder="0" allow="autoplay; encrypted-media" allowfullscreen /> +<iframe v-if="player" :src="player" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen /> <div v-else-if="tweetUrl && detail" class="twitter"> <blockquote ref="tweet" class="twitter-tweet" :data-theme="$store.state.device.darkmode ? 'dark' : null"> <a :href="url"></a> From 19c872a1f34d50071283deeab05330a309210d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= <root@acid-chicken.com> Date: Sat, 11 Aug 2018 19:56:53 +0900 Subject: [PATCH 3/4] Update url-preview.vue --- src/client/app/common/views/components/url-preview.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/app/common/views/components/url-preview.vue b/src/client/app/common/views/components/url-preview.vue index 8ad6a622d0..57b441a328 100644 --- a/src/client/app/common/views/components/url-preview.vue +++ b/src/client/app/common/views/components/url-preview.vue @@ -83,7 +83,7 @@ export default Vue.extend({ this.thumbnail = info.thumbnail; this.icon = info.icon; this.sitename = info.sitename; - + this.player = info.player; this.fetching = false; } }); From 8384efc8c74a00b35ccca946d8ec4ca69d57e4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= <root@acid-chicken.com> Date: Mon, 13 Aug 2018 03:23:36 +0900 Subject: [PATCH 4/4] Create whitelist --- .../common/views/components/url-preview.vue | 77 ++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/src/client/app/common/views/components/url-preview.vue b/src/client/app/common/views/components/url-preview.vue index 57b441a328..50194b69b7 100644 --- a/src/client/app/common/views/components/url-preview.vue +++ b/src/client/app/common/views/components/url-preview.vue @@ -83,8 +83,83 @@ export default Vue.extend({ this.thumbnail = info.thumbnail; this.icon = info.icon; this.sitename = info.sitename; - this.player = info.player; this.fetching = false; + if ([ // THIS IS THE WHITELIST FOR THE EMBED PLAYER + 'afreecatv.com', + 'aparat.com', + 'applemusic.com', + 'amazon.com', + 'awa.fm', + 'bandcamp.com', + 'bbc.co.uk', + 'beatport.com', + 'bilibili.com', + 'boomstream.com', + 'breakers.tv', + 'cam4.com', + 'cavelis.net', + 'chaturbate.com', + 'cnn.com', + 'cybergame.tv', + 'dailymotion.com', + 'deezer.com', + 'djlive.pl', + 'e-onkyo.com', + 'eventials.com', + 'facebook.com', + 'fc2.com', + 'gameplank.tv', + 'goodgame.ru', + 'google.com', + 'hardtunes.com', + 'instagram.com', + 'johnnylooch.com', + 'kexp.org', + 'lahzenegar.com', + 'liveedu.tv', + 'livetube.cc', + 'livestream.com', + 'meridix.com', + 'mixcloud.com', + 'mixer.com', + 'mobcrush.com', + 'mylive.in.th', + 'myspace.com', + 'netflix.com', + 'newretrowave.com', + 'nhk.or.jp', + 'nicovideo.jp', + 'noisetrade.com', + 'nood.tv', + 'npr.org', + 'openrec.tv', + 'pandora.com', + 'pandora.tv', + 'picarto.tv', + 'pscp.tv', + 'restream.io', + 'reverbnation.com', + 'sermonaudio.com', + 'smashcast.tv', + 'songkick.com', + 'soundcloud.com', + 'spinninrecords.com', + 'stitcher.com', + 'stream.me', + 'switchboard.live', + 'tunein.com', + 'twitcasting.tv', + 'twitch.tv', + 'twitter.com', + 'vaughnlive.tv', + 'veoh.com', + 'vimeo.com', + 'watchpeoplecode.com', + 'web.tv', + 'youtube.com', + 'youtu.be' + ].some(x => x == url.hostname || url.hostname.endsWith(`.${x}`)))) + this.player = info.player; } }); }