Skip to content

Commit

Permalink
embed base version
Browse files Browse the repository at this point in the history
  • Loading branch information
vintikzzz committed May 5, 2024
1 parent c18233b commit f9b28d8
Show file tree
Hide file tree
Showing 54 changed files with 1,543 additions and 567 deletions.
2 changes: 1 addition & 1 deletion .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ tmp_dir = "tmp"
args_bin = ['s', '--assets-host', 'http://localhost:8082']
bin = ";SUPERTOKENS_DEBUG=1 GIN_MODE=debug ./tmp/main"
cmd = "go build -o ./tmp/main ."
full_bin = "dlv exec ./tmp/main --listen=127.0.0.1:2345 --headless=true --api-version=2 --accept-multiclient --continue --log -- "
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata", "node_modules"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
kill_delay = "0s"
Expand Down
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Remote debug",
"type": "go",
"request": "attach",
"mode": "remote",
"port": 2345,
"host": "127.0.0.1",
"showLog": true,
"apiVersion": 2,
"trace": "verbose"
},
{
"name": "Launch App Server",
"type": "go",
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ Some features to mention:
- [ ] Subtitle uploading support
- [ ] Chromecast support
- [ ] Subtitle size control
- [ ] Embed control
- [x] Authentication
- [x] Passwordless authentication
- [x] Patreon account linking
- [x] Ads and statistic integration support
- [ ] Feedback form
- [ ] Chrome extension integration
- [ ] Embed support
- [x] Embed support
- [x] Base version
- [ ] Extended version
- [ ] 🚀Switch webtor.io to web-ui-v2


Expand Down
21 changes: 10 additions & 11 deletions assets/src/js/app/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ av(target, 'action/post', async function() {
initCloseable(closeable);
}
const initProgressLog = (await import('../lib/progressLog')).initProgressLog;
const pb = initProgressLog(progress, function(ev) {
if (ev.level == 'rendertemplate') {
window.addEventListener('player_ready', function(e) {
progress.classList.add('hidden');
el.classList.remove('hidden');
}, {once: true});
el.classList.add('hidden');
el.classList.add('mb-5')
self.appendChild(el);
ev.render(el);
}
initProgressLog(progress, function(ev) {
if (ev.level == 'rendertemplate') return;
window.addEventListener('player_ready', function(e) {
progress.classList.add('hidden');
el.classList.remove('hidden');
}, {once: true});
el.classList.add('hidden');
el.classList.add('mb-5')
self.appendChild(el);
ev.render(el);
});
});

Expand Down
41 changes: 41 additions & 0 deletions assets/src/js/app/embed/check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import message from './message';
const sha1 = require('sha1');

function setWidth() {
const width = document.body.offsetWidth;
const height = width/16*9;
document.body.style.height = height + 'px';
}
setWidth();
window.addEventListener('resize', setWidth);
window.addEventListener('click', async () => {
message.send('init');
const init = await message.receiveOnce('init');
const c = await check();
if (c) {
initEmbed(init);
}
});

async function check() {
message.send('inject', window._checkScript);
const check = await message.receiveOnce('check');
return sha1(window._id + check) == _checkHash;
}

function initEmbed(init) {
const form = document.createElement('form');
form.setAttribute('method', 'post');
form.setAttribute('enctype', 'multipart/form-data');
const csrf = document.createElement('input');
csrf.setAttribute('name', '_csrf');
csrf.setAttribute('value', window._CSRF);
form.append(csrf);
const i = document.createElement('input');
i.setAttribute('name', 'settings');
i.setAttribute('value', JSON.stringify(init));
form.append(i);
document.body.append(form);
// form.setAttribute('action', '/');
form.submit();
}
28 changes: 28 additions & 0 deletions assets/src/js/app/embed/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import '../../../styles/embed.css';

function setWidth() {
const width = document.body.offsetWidth;
const height = width/16*9;
document.body.style.height = height + 'px';
}
setWidth();
window.addEventListener('resize', setWidth);

window.addEventListener('load', async () => {
const progress = document.querySelector('.progress-alert');
const el = document.createElement('div');
const initProgressLog = (await import('../../lib/progressLog')).initProgressLog;
initProgressLog(progress, function(ev) {
if (ev.level != 'rendertemplate') return;
window.addEventListener('player_ready', function(e) {
window.removeEventListener('resize', setWidth);
document.body.style.height = 'auto';
progress.classList.add('hidden');
el.classList.remove('hidden');
}, {once: true});
el.classList.add('hidden');
el.classList.add('mb-5')
document.body.appendChild(el);
ev.render(el);
});
});
57 changes: 57 additions & 0 deletions assets/src/js/app/embed/message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {makeDebug} from '../../lib/debug';
const debug = await makeDebug('webtor:embed:message');
function inIframe() {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
const id = window._id;
debug('using message id=%o', id);
const message = {
id() {
return id;
},
send(m, data = {}) {
if (!inIframe) return;
if (!id) {
m = 'webtor: ' + m;
} else {
m = {
id,
name: m,
data,
};
}
debug('post message=%o data=%o', m, data);
window.parent.postMessage(m, '*');
},
receiveOnce(name) {
return new Promise((resolve, reject) => {
const func = (event) => {
const d = event.data;
if (!id) {
window.removeEventListener('message', func);
resolve();
}
if (d.id == id && d.name == name) {
debug('receive message=%o', d);
window.removeEventListener('message', func);
resolve(d.data);
}
}
window.addEventListener('message', func);
});
},
receive(name, callback) {
window.addEventListener('message', function(event) {
const d = event.data;
if (d.id == id && d.name == name) {
debug('receive message=%o', d);
callback(d.data);
}
});
}
}
export default message;
6 changes: 4 additions & 2 deletions assets/src/js/lib/asyncView.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import MD5 from "crypto-js/md5";
import {makeDebug} from './debug';
const debug = await makeDebug('webtor:embed:message');
export function initAsyncView(target, name, init, destroy) {
const layout = target.getAttribute('async-layout');
if (layout) {
name = name + '_' + MD5(layout).toString();
}
const onLoad = function(e) {
console.log(`async:${name} load`);
debug(`webtor:async view loaded name=%o`, name);
if (e && e.detail && e.detail.target) {
target = e.detail.target;
}
Expand All @@ -26,7 +28,7 @@ export function initAsyncView(target, name, init, destroy) {
onLoad();
}
const listener = async (e) => {
console.log(`async:${name} destroy`);
debug(`webtor:async view destroyed name=%o`, name);
const event = new CustomEvent(`async:${name}_destroyed`);
if (destroy) {
let target = document;
Expand Down
8 changes: 8 additions & 0 deletions assets/src/js/lib/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export async function makeDebug(name) {
if (localStorage.debug) {
const makeDebug = (await import('debug')).default;
return makeDebug(name);
} else {
return function() {};
}
}
2 changes: 1 addition & 1 deletion assets/src/js/lib/mediaelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function initPlayer(target, ready) {
capLevelOnFPSDrop: true,
// progressive: true,
testBandwidth: false,
path: 'https://cdn.jsdelivr.net/npm/hls.[email protected]',
path: '/assets/lib/hls.min.js',
},
error: function(e) {
console.log(e);
Expand Down
69 changes: 69 additions & 0 deletions assets/src/styles/embed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

.loading-elipsis::after {
overflow: hidden;
display: inline-block;
vertical-align: bottom;
animation: ellipsis steps(4, end) 1500ms infinite;
content: "...";
width: 0;
margin-left: 0.15rem;
}

@keyframes ellipsis {
to {
width: 2.25em;
}
}

.popin {
animation: popin 200ms;
}

@keyframes popin {
from {
transform: scaleX(0.95);
opacity: 0;
}

to {
transform: scaleX(1);
opacity: 1;
}
}

@layer components {
.progress-alert {
@apply py-4 popin;
position: relative;
color: white;

pre {
@apply px-5 leading-8 whitespace-pre-wrap flex;
&::before {
content: "> ";
@apply shrink-0;
}
&.in-progress {
@apply loading-elipsis;
}
&.error-summary {
@apply px-5 bg-warning text-warning-content;
}
&.done-summary {
@apply px-5 bg-success text-success-content;
}
}
.close {
@apply btn btn-sm btn-accent mr-4;
}
&-oneline {
@apply flex;
pre {
@apply flex-grow;
}
}
}
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,14 @@ require (
github.com/prometheus/procfs v0.13.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stgleb/obfuscator v0.0.0-20170831162424-96509f6d8966 // indirect
github.com/stretchr/objx v0.5.1 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/swaggo/files v1.0.1 // indirect
github.com/swaggo/gin-swagger v1.6.0 // indirect
github.com/swaggo/swag v1.16.2 // indirect
github.com/tdewolff/minify v2.3.6+incompatible // indirect
github.com/tdewolff/parse v2.3.4+incompatible // indirect
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/twilio/twilio-go v1.15.3 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasO
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stgleb/obfuscator v0.0.0-20170831162424-96509f6d8966 h1:HgjquJp9RiEyIkSO9kZ6auGD5WtYOSTobcjl8VuyMlg=
github.com/stgleb/obfuscator v0.0.0-20170831162424-96509f6d8966/go.mod h1:5XWG4cXzV9TRqOCk0dF8hi++jZDG3nf4DV1tn/bJR3s=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down Expand Up @@ -534,6 +536,10 @@ github.com/swaggo/gin-swagger v1.6.0/go.mod h1:BG00cCEy294xtVpyIAHG6+e2Qzj/xKlRd
github.com/swaggo/swag v1.16.2 h1:28Pp+8DkQoV+HLzLx8RGJZXNGKbFqnuvSbAAtoxiY04=
github.com/swaggo/swag v1.16.2/go.mod h1:6YzXnDcpr0767iOejs318CwYkCQqyGer6BizOg03f+E=
github.com/syncthing/syncthing v0.14.48-rc.4/go.mod h1:nw3siZwHPA6M8iSfjDCWQ402eqvEIasMQOE8nFOxy7M=
github.com/tdewolff/minify v2.3.6+incompatible h1:2hw5/9ZvxhWLvBUnHE06gElGYz+Jv9R4Eys0XUzItYo=
github.com/tdewolff/minify v2.3.6+incompatible/go.mod h1:9Ov578KJUmAWpS6NeZwRZyT56Uf6o3Mcz9CEsg8USYs=
github.com/tdewolff/parse v2.3.4+incompatible h1:x05/cnGwIMf4ceLuDMBOdQ1qGniMoxpP46ghf0Qzh38=
github.com/tdewolff/parse v2.3.4+incompatible/go.mod h1:8oBwCsVmUkgHO8M5iCzSIDtpzXOT0WXX9cWhz+bIzJQ=
github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
github.com/tinylib/msgp v1.1.0/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
github.com/tinylib/msgp v1.1.1/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
Expand Down
Loading

0 comments on commit f9b28d8

Please sign in to comment.