Skip to content

Commit

Permalink
Merge pull request #1781 from fireship-io/hugo-ext
Browse files Browse the repository at this point in the history
video player updates
  • Loading branch information
codediodeio authored Nov 28, 2024
2 parents 96eb582 + cc35afa commit 027f23c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
ALGOLIA_ADMIN_KEY: ${{secrets.ALGOLIA_ADMIN_KEY}}
ALGOLIA_INDEX_NAME: content
ALGOLIA_INDEX_FILE: public/algolia.json
HUGO_SALT: ${{secrets.HUGO_SALT}}


jobs:
Expand Down
22 changes: 19 additions & 3 deletions app/util/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ export class UniversalPlayer {
constructor(public video: string | number, public el: HTMLElement, public type: 'youtube' | 'vimeo') {}

private async setupPlayer() {

if (this.type === 'youtube') {
const YouTubePlayer = (await import('youtube-player')).default;
const decoded = atob(this.video as string);

this.ytPlayer = YouTubePlayer(this.el);
this.ytPlayer.cueVideoById(decoded);
} else {
const VimeoPlayer = (await import('@vimeo/player')).default;
const decoded = parseInt(atob(this.video as string));
// const buildId = parseInt(document.head.dataset.build);
this.vimeoPlayer = new VimeoPlayer(this.el, { id: decoded });

const decoded = await this.decoded();
const vimeoId = parseInt(decoded)

this.vimeoPlayer = new VimeoPlayer(this.el, { id: vimeoId });
}

}
Expand All @@ -29,6 +33,18 @@ export class UniversalPlayer {
return obj;
}

async decoded() {
const path = window.location.pathname;
const s1 = btoa(path);
let p1 = (await import('./s2')).default;
const p2 = 'fUCB3Iv';
const s2 = p1+p2;
let withS = atob(this.video as string)
let encoded = withS.slice(s1.length, -s2.length);
const decoded = atob(encoded)
return decoded;
}

play() {
if (this.type === 'youtube') {
this.ytPlayer.playVideo();
Expand Down
4 changes: 4 additions & 0 deletions app/util/s2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default (()=>{
const c = [120, 105, 88, 70, 84, 116, 69, 85, 90];
return [1, 3, 4, 6, 0, 5, 7].map(i => String.fromCharCode(c[i])).join('');
})();
9 changes: 7 additions & 2 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@

</head>
<body>
{{ $vimeoEncode := .Params.vimeo | base64Encode }}


{{ $saltVimeo := "" }}
{{ if .Params.vimeo }}
{{ $saltVimeo = partial "funcEncodeValue" (dict "value" .Params.vimeo "path" .RelPermalink) }}
{{ end }}
{{ $ytEncode := .Params.youtube | base64Encode }}

<global-data
permalink="{{ .Permalink }}"
vimeo="{{ $vimeoEncode }}"
vimeo="{{ $saltVimeo }}"
youtube="{{ $ytEncode }}"
free="{{ .Params.free }}"
next="{{with .PrevInSection}}{{.Permalink}}{{end}}"
Expand Down
14 changes: 14 additions & 0 deletions layouts/partials/funcEncodeValue.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

{{/* Initialize variables */}}

{{ $salt1 := .path | base64Encode }}

{{ $value := .value }}
{{ $salt2 := partial "funcGetSalt" . }}

{{/* First base64 encode */}}
{{ $encoded := $value | base64Encode }}

{{/* Add different salts at start and end */}}
{{ $withSalt := printf "%s%s%s" $salt1 $encoded $salt2 }}
{{ return ($withSalt | base64Encode) }}
4 changes: 4 additions & 0 deletions layouts/partials/funcGetSalt.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{ $part1 := getenv "HUGO_SALT" }}
{{ $part2 := "fUCB3Iv" }}

{{ return (printf "%s%s" $part1 $part2) }}

0 comments on commit 027f23c

Please sign in to comment.