Skip to content

Commit

Permalink
patchyvideo has been deploy Ze☆
Browse files Browse the repository at this point in the history
  • Loading branch information
GuihongWang committed Feb 19, 2024
1 parent 169c9cd commit af3f73a
Show file tree
Hide file tree
Showing 348 changed files with 1,861 additions and 0 deletions.
1 change: 1 addition & 0 deletions CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xn--rttn50cxwe.xn--xuw71npw9a.ml
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019-2022, VoileLabs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file added android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
216 changes: 216 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
require('cross-fetch/polyfill')

const path = require('path')
const fs = require('fs')
const gql = require('fake-tag')
const { encode } = require('html-entities')
const { Readable } = require('stream')
const { compressStream } = require('../libs/common')

const html = fs.readFileSync(path.join(__dirname, '../index.html')).toString()

/**
* @param {import('@vercel/node').VercelRequest} req
* @param {import('@vercel/node').VercelResponse} res
*/
module.exports = async (req, res) => {
try {
processRequest(req, res)
} catch (e) {
res.status(200)
res.setHeader('Content-Type', 'text/html; charset=utf-8')
res.end(html)
}
}

/**
* @param {import('@vercel/node').VercelRequest} req
* @param {import('@vercel/node').VercelResponse} res
*/
async function processRequest(req, res) {
let body = html

const timeStart = Date.now()

/* Open Graph */
try {
if (/\/video\/\w+/.test(req.url)) {
const vid = req.url.match(/\/video\/(\w+)/)[1]
const data = (
await queryGraphQL(
gql`
query ($vid: String!) {
getVideo(para: { vid: $vid, lang: "CHS" }) {
item {
coverImage
title
desc
}
tags {
languages {
value
}
}
}
}
`,
{
vid,
}
)
).data.getVideo
const og = [
// common data
`<title>${encode(data.item.title)} - PatchyVideo</title>`,
`<meta property="description" content="${encodeHTML(data.item.desc)}" />`,
`<meta name="keywords" content="${encodeHTML(
data.tags.map((tag) => tag.languages.map((v) => v.value).join(' ')).join(' ')
)}" />`,
`<meta itemprop="name" content="${encode(data.item.title)}" />`,
`<meta itemprop="description" content="${encodeHTML(data.item.desc)}" />`,
`<meta itemprop="image" content="https://patchyvideo.com/images/covers/${data.item.coverImage}" />`,

// opengraph data
`<meta property="og:type" content="video.other" />`,
`<meta property="og:title" content="${encodeHTML(data.item.title)}" />`,
`<meta property="og:image" content="https://patchyvideo.com/images/covers/${data.item.coverImage}" />`,
`<meta property="og:description" content="${encodeHTML(data.item.desc)}" />`,
`<meta property="og:url" content="https://${req.headers.host}${req.url}" />`,
`<meta property="og:site_name" content="PatchyVideo" />`,
`<meta property="og:video:url" content="https://${req.headers.host}/embed/${vid}" />`,
`<meta property="og:video:secure_url" content="https://${req.headers.host}/embed/${vid}" />`,
`<meta property="og:video:type" content="text/html" />`,
...[...new Set(data.tags.reduce((pv, cv) => [...pv, ...cv.languages.map((v) => v.value)], []))].map(
(v) => `<meta property="og:video:tag" content="${encodeHTML(v)}" />`
),

// twitter data
`<meta name="twitter:card" content="player" />`,
`<meta name="twitter:site" content="@PatchyVideo" />`,
`<meta name="twitter:url" content="https://${req.headers.host}${req.url}" />`,
`<meta name="twitter:title" content="${encodeHTML(data.item.title)}" />`,
`<meta name="twitter:description" content="${encodeHTML(data.item.desc)}" />`,
`<meta name="twitter:image" content="https://patchyvideo.com/images/covers/${data.item.coverImage}" />`,
`<meta name="twitter:player" content="https://${req.headers.host}/embed/${vid}" />`,
].join('\n')
body = body.replace(/<!-- META-START -->[\S\s]*<!-- META-END -->/, og)
} else if (/\/playlist\/\w+/.test(req.url)) {
const pid = req.url.match(/\/playlist\/(\w+)/)[1]
const data = (
await queryGraphQL(
gql`
query ($pid: String!) {
getPlaylist(para: { pid: $pid }) {
item {
title
cover
desc
}
}
}
`,
{
pid,
}
)
).data.getPlaylist
const og = [
// common data
`<title>${encode(data.item.title)} - PatchyVideo</title>`,
`<meta property="description" content="${encodeHTML(data.item.desc)}" />`,
`<meta itemprop="name" content="${encode(data.item.title)}" />`,
`<meta itemprop="description" content="${encodeHTML(data.item.desc)}" />`,
`<meta itemprop="image" content="https://patchyvideo.com/images/covers/${data.item.cover}" />`,

// opengraph data
`<meta property="og:title" content="${encodeHTML(data.item.title)}" />`,
`<meta property="og:image" content="https://patchyvideo.com/images/covers/${data.item.cover}" />`,
`<meta property="og:description" content="${encodeHTML(data.item.desc)}" />`,
`<meta property="og:url" content="https://${req.headers.host}${req.url}" />`,
`<meta property="og:site_name" content="PatchyVideo" />`,

// twitter data
`<meta name="twitter:card" content="summary" />`,
`<meta name="twitter:site" content="@PatchyVideo" />`,
`<meta name="twitter:url" content="https://${req.headers.host}${req.url}" />`,
`<meta name="twitter:title" content="${encodeHTML(data.item.title)}" />`,
`<meta name="twitter:description" content="${encodeHTML(data.item.desc)}" />`,
`<meta name="twitter:image" content="https://patchyvideo.com/images/covers/${data.item.cover}" />`,
].join('\n')
body = body.replace(/<!-- META-START -->[\S\s]*<!-- META-END -->/, og)
} else if (/\/user\/\w+/.test(req.url)) {
const uid = req.url.match(/\/user\/(\w+)/)[1]
const data = (
await queryGraphQL(
gql`
query ($uid: String!) {
getUser(para: { uid: $uid }) {
username
desc
image
gravatar
}
}
`,
{
uid,
}
)
).data.getUser
const og = [
// common data
`<title>${encode(data.username)} - PatchyVideo</title>`,
`<meta property="description" content="${encodeHTML(data.desc)}" />`,
`<meta itemprop="name" content="${encode(data.username)}" />`,
`<meta itemprop="description" content="${encodeHTML(data.desc)}" />`,
`<meta itemprop="image" content="https://patchyvideo.com/images/userphotos/${data.image}" />`,

// opengraph data
`<meta property="og:type" content="profile" />`,
`<meta property="og:profile:username" content="${encodeHTML(data.username)}" />`,
`<meta property="og:image" content="https://patchyvideo.com/images/userphotos/${data.image}" />`,
`<meta property="og:description" content="${encodeHTML(data.desc)}" />`,
`<meta property="og:url" content="https://${req.headers.host}${req.url}" />`,
`<meta property="og:site_name" content="PatchyVideo" />`,

// twitter data
`<meta name="twitter:card" content="summary" />`,
`<meta name="twitter:site" content="@PatchyVideo" />`,
`<meta name="twitter:url" content="https://${req.headers.host}${req.url}" />`,
`<meta name="twitter:title" content="${encodeHTML(data.username)}" />`,
`<meta name="twitter:description" content="${encodeHTML(data.desc)}" />`,
`<meta name="twitter:image" content="https://patchyvideo.com/images/userphotos/${data.image}" />`,
].join('\n')
body = body.replace(/<!-- META-START -->[\S\s]*<!-- META-END -->/, og)
}
} catch (e) {
body += '\n<!--\nServer responsed with error:\n' + encodeHTML(String(e), false) + '\n-->'
}

body = body.replace('<!-- TIMING -->', `<!-- RENDER: ${Date.now() - timeStart}ms -->`)

res.status(200)
res.setHeader('Content-Type', 'text/html; charset=utf-8')
await compressStream(req, Readable.from(body), res)
}

/**
* @param {string} gql
* @returns {Promise<import('graphql').ExecutionResult<import('../../packages/graphql/__generated__/graphql').Query>>}
*/
function queryGraphQL(gql, vari) {
return fetch('https://patchyvideo.com/be/gql/graphql', {
method: 'POST',
headers: new Headers({
'Content-Type': 'application/json',
}),
body: JSON.stringify({
query: gql,
variables: vari,
}),
}).then((res) => res.json())
}

function encodeHTML(string, replaceBr = true) {
return encode(replaceBr ? string.replace(/[\n\r]/g, ' ') : string, { level: 'xml' })
}
Binary file added apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions assets/404.1cc6a619.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/404.1cc6a619.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions assets/Author.4c62f310.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit af3f73a

Please sign in to comment.