From fda6d1e4751d1d41493caf80317dbbc8b3271f60 Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Sun, 19 May 2019 01:34:08 +0200 Subject: [PATCH] Added release page. --- .eslintrc | 1 + assets/views/home.jsx | 25 ++++++++--- assets/views/layout.jsx | 12 +++++- assets/views/release.jsx | 93 ++++++++++++++++++++++++++++++++++++++++ public/css/style.css | 4 ++ src/releases.js | 6 ++- src/web/releases.js | 12 ++++++ src/web/server.js | 3 +- 8 files changed, 145 insertions(+), 11 deletions(-) create mode 100644 assets/views/release.jsx diff --git a/.eslintrc b/.eslintrc index 988dbb89..9da6c77b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -18,5 +18,6 @@ "react/jsx-uses-vars": 2, "react/jsx-indent": ["error", 4], "react/jsx-indent-props": ["error", 4], + "react/jsx-one-expression-per-line": "off", } } diff --git a/assets/views/home.jsx b/assets/views/home.jsx index 779857be..0c06fe77 100644 --- a/assets/views/home.jsx +++ b/assets/views/home.jsx @@ -17,6 +17,8 @@ const Home = ({ releases }) => ( @@ -33,16 +35,23 @@ const Home = ({ releases }) => ( - {release.id} + + {release.id} +
( > {actor.name} @@ -80,6 +91,8 @@ const Home = ({ releases }) => ( > {tag.tag} diff --git a/assets/views/layout.jsx b/assets/views/layout.jsx index 8c8cf07a..b4d94336 100644 --- a/assets/views/layout.jsx +++ b/assets/views/layout.jsx @@ -3,10 +3,13 @@ const React = require('react'); const PropTypes = require('prop-types'); -const Layout = ({ children }) => ( +const Layout = ({ children, title }) => ( - Porn Radar + {title + ? Porn Radar | {title} + : Porn Radar + } @@ -25,6 +28,11 @@ const Layout = ({ children }) => ( Layout.propTypes = { children: PropTypes.node.isRequired, + title: PropTypes.string, +}; + +Layout.defaultProps = { + title: null, }; module.exports = Layout; diff --git a/assets/views/release.jsx b/assets/views/release.jsx new file mode 100644 index 00000000..c1dc7540 --- /dev/null +++ b/assets/views/release.jsx @@ -0,0 +1,93 @@ +'use strict'; + +const React = require('react'); +const PropTypes = require('prop-types'); +const moment = require('moment'); + +const Layout = require('./layout.jsx'); + +const Release = ({ release, thumbnails }) => ( + +
+

{release.title}

+

{moment(release.date).format('MMMM DD, YYYY')}

+

{release.shootId}

+ +

+ + {release.site.name} + +

+ +

{release.network.name}

+ +

+ + View on {new URL(release.site.url).host.replace('www.', '')} + +

+ + + +

{release.description}

+ + + + {thumbnails.map((thumbnail, index) => ( + {`Thumbnail + ))} +
+ +); + +Release.propTypes = { + release: PropTypes.object, + thumbnails: PropTypes.arrayOf(PropTypes.string), +}; + +Release.defaultProps = { + release: null, + thumbnails: [], +}; + +module.exports = Release; diff --git a/public/css/style.css b/public/css/style.css index 321e2bbd..046795fe 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -132,3 +132,7 @@ body { .tag-link { color: #000; } + +.thumbnail { + width: 300px; +} diff --git a/src/releases.js b/src/releases.js index ea4defe1..6e102234 100644 --- a/src/releases.js +++ b/src/releases.js @@ -32,6 +32,7 @@ async function curateRelease(release) { site: { id: release.site_id, name: release.site_name, + url: release.site_url, }, network: { id: release.network_id, @@ -45,9 +46,10 @@ function curateReleases(releases) { return Promise.all(releases.map(async release => curateRelease(release))); } -async function fetchReleases() { +async function fetchReleases(releaseId) { const releases = await knex('releases') - .select('releases.*', 'sites.name as site_name', 'sites.network_id', 'networks.name as network_name', 'networks.url as network_url') + .where(releaseId ? { 'releases.id': releaseId } : {}) + .select('releases.*', 'sites.name as site_name', 'sites.url as site_url', 'sites.network_id', 'networks.name as network_name', 'networks.url as network_url') .leftJoin('sites', 'releases.site_id', 'sites.id') .leftJoin('networks', 'sites.network_id', 'networks.id') .orderBy('date', 'desc') diff --git a/src/web/releases.js b/src/web/releases.js index 7fdd1f5a..529fb717 100644 --- a/src/web/releases.js +++ b/src/web/releases.js @@ -1,5 +1,9 @@ 'use strict'; +const config = require('config'); +const fs = require('fs').promises; +const path = require('path'); + const { fetchReleases } = require('../releases'); async function fetchReleasesApi(req, res) { @@ -8,6 +12,14 @@ async function fetchReleasesApi(req, res) { res.render('home', { releases }); } +async function fetchReleaseApi(req, res) { + const [release] = await fetchReleases(req.params.id); + const thumbnails = await fs.readdir(path.join(config.thumbnailPath, release.site.id.toString(), release.id.toString())); + + res.render('release', { release, thumbnails }); +} + module.exports = { fetchReleases: fetchReleasesApi, + fetchRelease: fetchReleaseApi, }; diff --git a/src/web/server.js b/src/web/server.js index c7145dec..138a0351 100644 --- a/src/web/server.js +++ b/src/web/server.js @@ -6,7 +6,7 @@ const express = require('express'); const Router = require('express-promise-router'); const { createEngine } = require('express-react-views'); -const { fetchReleases } = require('./releases'); +const { fetchReleases, fetchRelease } = require('./releases'); function initServer() { const app = express(); @@ -20,6 +20,7 @@ function initServer() { app.engine('jsx', createEngine()); router.get('/', fetchReleases); + router.get('/scene/:id', fetchRelease); app.use(router);