mirror of
https://github.com/wassname/talk.git
synced 2026-07-12 06:03:27 +08:00
Create load stream by id route
This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
import {graphql} from 'react-apollo';
|
||||
import STREAM_QUERY from './streamQuery.graphql';
|
||||
import pym from 'coral-framework/PymConnection';
|
||||
|
||||
let url = pym.parentUrl.split('#')[0] || 'http://localhost:3000/';
|
||||
function getQueryVariable(variable) {
|
||||
let query = window.location.search.substring(1);
|
||||
let vars = query.split('&');
|
||||
for (let i = 0; i < vars.length; i++) {
|
||||
let pair = vars[i].split('=');
|
||||
if (decodeURIComponent(pair[0]) === variable) {
|
||||
return decodeURIComponent(pair[1]);
|
||||
}
|
||||
}
|
||||
console.log('Query variable %s not found', variable);
|
||||
}
|
||||
|
||||
export const queryStream = graphql(STREAM_QUERY, {
|
||||
options: {variables: {asset_url: url}}
|
||||
options: {variables: {asset_url: getQueryVariable('asset_url')}}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const Assets = require('../../services/assets');
|
||||
|
||||
const body = 'Lorem ipsum dolor sponge amet, consectetur adipiscing clam. Ut lobortis sollicitudin pillar a ornare. Curabitur dignissim vestibulum cay non rhoncus. Cras laoreet ante vel nunc hendrerit, shelf imperdiet neque egestas. Suspendisse aliquet iaculis fermentum. Talk volutpat, tellus posuere laoreet consequat, mi lacus laoreet massa, sed vehicula mauris velit non lectus. Integer non trust nec neque congue faucibus porttitor sit amet elkhorn.';
|
||||
|
||||
router.get('/id/:asset_id', (req, res, next) => {
|
||||
|
||||
return Assets.findById(req.params.asset_id)
|
||||
.then(asset => {
|
||||
res.render('article', {
|
||||
title: asset.title,
|
||||
asset_url: asset.url,
|
||||
body: '',
|
||||
basePath: '/client/embed/stream'
|
||||
});
|
||||
})
|
||||
.catch((err) => next(err));
|
||||
});
|
||||
|
||||
router.get('/title/:asset_title', (req, res) => {
|
||||
return res.render('article', {
|
||||
title: req.params.asset_title.split('-').join(' '),
|
||||
asset_url: '',
|
||||
body: body,
|
||||
basePath: '/client/embed/stream'
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
+1
-7
@@ -4,6 +4,7 @@ const router = express.Router();
|
||||
router.use('/api/v1', require('./api'));
|
||||
router.use('/admin', require('./admin'));
|
||||
router.use('/embed', require('./embed'));
|
||||
router.use('/assets', require('./assets'));
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
return res.render('article', {
|
||||
@@ -12,11 +13,4 @@ router.get('/', (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
router.get('/assets/:asset_title', (req, res) => {
|
||||
return res.render('article', {
|
||||
title: req.params.asset_title.split('-').join(' '),
|
||||
basePath: '/client/embed/stream'
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
+23
-11
@@ -20,15 +20,7 @@
|
||||
<body>
|
||||
<main>
|
||||
<h1><%= title %></h1>
|
||||
<p>
|
||||
Lorem ipsum dolor sponge amet, consectetur adipiscing clam.
|
||||
Ut lobortis sollicitudin pillar a ornare. Curabitur dignissim
|
||||
vestibulum cay non rhoncus. Cras laoreet ante vel nunc hendrerit,
|
||||
shelf imperdiet neque egestas. Suspendisse aliquet iaculis fermentum.
|
||||
Talk volutpat, tellus posuere laoreet consequat, mi lacus laoreet massa,
|
||||
sed vehicula mauris velit non lectus. Integer non trust nec neque congue
|
||||
faucibus porttitor sit amet elkhorn.
|
||||
</p>
|
||||
<p><%= body %></p>
|
||||
<p><a href="/admin">Visit the moderation console</a></p>
|
||||
<div id='coralStreamEmbed'></div>
|
||||
</main>
|
||||
@@ -36,13 +28,33 @@
|
||||
<script type='text/javascript' src='<%= basePath %>/pym.v1.min.js'></script>
|
||||
<script>
|
||||
var ready = false;
|
||||
var pymParent = new pym.Parent('coralStreamEmbed', '/embed/stream', {title: 'Talk Comments', id:'coralStreamIframe', name: 'coralStreamIframe'});
|
||||
|
||||
// default to using the window.location
|
||||
var url = window.location.protocol + '//' + window.location.host + window.location.pathname;
|
||||
|
||||
// if a url is passed into the template prefer it to the current url
|
||||
<%if (asset_url.length > 0) { %>
|
||||
url = '<%= asset_url %>';
|
||||
<%}%>
|
||||
|
||||
var pymParent = new pym.Parent('coralStreamEmbed', '/embed/stream?asset_url=' + encodeURIComponent(url), {title: 'Talk Comments', id:'coralStreamIframe', name: 'coralStreamIframe', asset_url: url});
|
||||
pymParent.onMessage('height', function(height) {document.querySelector('#coralStreamEmbed iframe').height = height + 'px'})
|
||||
pymParent.onMessage('childReady', function () {
|
||||
var interval = setInterval(function () {
|
||||
if (ready) {
|
||||
window.clearInterval(interval);
|
||||
pymParent.sendMessage('DOMContentLoaded', window.location.hash);
|
||||
|
||||
// default to using the window.location
|
||||
var url = window.location.hash;
|
||||
|
||||
// if a url is passed into the template prefer it to the current url
|
||||
<%if (asset_url.length > 0) { %>
|
||||
url = '<%= asset_url %>';
|
||||
<%}%>
|
||||
|
||||
console.log(url);
|
||||
|
||||
pymParent.sendMessage('DOMContentLoaded', url);
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user