Skip to content

Commit

Permalink
Final updates
Browse files Browse the repository at this point in the history
* Fixing mobile side menu css
* Reverting callasync change due to browser crypto incompatibility
* Modifying userpic to return null on error
* Replace steemit's old cryptosession with golos' code
  • Loading branch information
smoke-indica committed Oct 27, 2020
1 parent 03300a4 commit cba28ff
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 25,264 deletions.
15,732 changes: 0 additions & 15,732 deletions package-lock.json

This file was deleted.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "git",
"url": "https://github.com/smokenetwork/webapp.git"
},
"version": "0.1.1",
"version": "0.1.2",
"description": "smoke.io is the koa web server & middleware and react.js in-browser code for the world's first blockchain content + social media monetization platform!",
"main": "index.js",
"scripts": {
Expand All @@ -23,8 +23,7 @@
"license": "MIT",
"dependencies": {
"@sendgrid/mail": "^6.2.1",
"@smokenetwork/smoke-js": "^0.1.4",
"@steem/crypto-session": "git+https://github.com/steemit/crypto-session.git#83a90b319ce5bc6a70362d52a15a815de7e729bb",
"@smokenetwork/smoke-js": "^0.1.5",
"assert": "^1.3.0",
"autoprefixer-loader": "^3.2.0",
"aws-sdk": "^2.409.0",
Expand Down Expand Up @@ -83,6 +82,8 @@
"koa-router": "^5.4.0",
"koa-session": "^3.3.1",
"koa-static-cache": "^3.1.2",
"libsodium": "0.4.8",
"libsodium-wrappers": "0.4.8",
"lodash.debounce": "^4.0.7",
"medium-editor-insert-plugin": "^2.3.2",
"mem-stat": "^1.0.5",
Expand Down
5 changes: 4 additions & 1 deletion src/app/components/elements/DropdownMenu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@

> .VerticalMobileMenu {
visibility: hidden;
min-width: 100vw;
min-width: 100%;
max-width: 100%;
z-index: 1000;
display: block;
border-radius: $global-radius;
Expand All @@ -43,6 +44,7 @@
justify-content: center;
height: 100vh;
z-index: 9999;
box-sizing: border-box;
}

&.show > .VerticalMenu {
Expand Down Expand Up @@ -78,3 +80,4 @@
}
}
}

16 changes: 9 additions & 7 deletions src/app/components/elements/Userpic.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,24 @@ class Userpic extends Component {
return null;
}

let profileImageUrl = `/images/smoke_user.png`;

let profileImageUrl;
// try to extract image url from users metaData
try {
const metadata = JSON.parse(json_metadata);
if (rep >= 20 && metadata.profile.profile_image) {
if (metadata.profile.profile_image && rep >= 20) {
if (/^(https?:)\/\//.test(metadata.profile.profile_image)) {
// hack to get profile images to display. This doesn't work if there is no metadata
profileImageUrl = `${imageProxy()}64x64/${metadata.profile.profile_image}`;
// hack to get profile images to display. This doesn't work if there is no metadata
profileImageUrl = `${imageProxy()}64x64/${metadata.profile.profile_image}`;
}
} else {
profileImageUrl = `/images/smoke_user.png`;
}
} catch (error) {
// commented out to hide invalid profile pics
//profileImageUrl = `${PROFILE_IMAGE_URL_PREFIX}/${account}`;
return null;
}

return (<div className="Userpic" style={{backgroundImage: `url(${profileImageUrl})`}}/>)
return (<div className="Userpic" style={{backgroundImage: `url(${profileImageUrl})`}}/>);
}
}

Expand All @@ -55,6 +56,7 @@ Userpic.propTypes = {
export default connect(
(state, ownProps) => {
const {account, hideIfDefault} = ownProps;

return {
account,
json_metadata: state.global.getIn(['accounts', account, 'json_metadata']),
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/elements/VerticalMenu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}

.float-right {
float:right;
float: right;
text-align: right;
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/components/elements/VerticalMobileMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class VerticalMobileMenu extends React.Component {
render() {
const {items, title, className, hideValue} = this.props;
return <div className={'VerticalMobileMenu menu vertical' + (className ? ' ' + className : '')}>
{title && <div className="tops"><div className="title float-left">{title}</div><div onClick={this.closeMenu} className="title float-right">X</div></div>}
{title && <div className="tops"><div onClick={this.closeMenu} className="title float-right">X</div><div className="title">{title}</div></div>}
{
items.map(i => {
if (i.value === hideValue) return null
Expand Down
14 changes: 9 additions & 5 deletions src/app/utils/ServerApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function markNotificationRead(account, fields) {

let last_page, last_views, last_page_promise;

export function recordPageView(page, referer, account) {
export function recordPageView(page, ref, account) {
if (last_page_promise && page === last_page) return last_page_promise;
if (!process.env.BROWSER) return Promise.resolve(0);

Expand All @@ -63,10 +63,14 @@ export function recordPageView(page, referer, account) {
window.ga('send', 'pageview');
}

last_page_promise = api.callAsync('overseer.pageview', {
page,
referer,
account,
api.call('overseer.pageview', {page, referer: ref, account}, (error) => {
// if (error) console.warn('overseer error', error, error.data);
});
if (!process.env.BROWSER || window.$STM_ServerBusy) return Promise.resolve(0);
const request = Object.assign({}, request_base, {body: JSON.stringify({csrf: $STM_csrf, page, ref})});
last_page_promise = fetch(`/api/v1/page_view`, request).then(r => r.json()).then(res => {
last_views = res.views;
return last_views;
});
last_page = page;
return last_page_promise;
Expand Down
2 changes: 1 addition & 1 deletion src/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import useEnterAndConfirmMobilePages from './sign_up_pages/enter_confirm_mobile'
import useUserJson from './json/user_json';
import usePostJson from './json/post_json';
import isBot from 'koa-isbot';
import session from '@steem/crypto-session';
import session from './utils/cryptoSession';
import csrf from 'koa-csrf';
import flash from 'koa-flash';
import minimist from 'minimist';
Expand Down
95 changes: 95 additions & 0 deletions src/server/utils/cryptoSession.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
'use strict'

const sodium = require('libsodium-wrappers')
const session = require('koa-session')

module.exports = function(app, opts) {
opts = opts || {}

if (opts.signed === undefined) {
opts.signed = true
}

let secret;
try {
secret = new Buffer(opts.crypto_key, 'base64')
if (secret.length !== sodium.crypto_secretbox_KEYBYTES)
throw new Error(`Crypto key should decode to ${sodium.crypto_secretbox_KEYBYTES} bytes in length`)
}
catch(error) {
throw new Error('Missing or invalid options.crypto_key', error)
}

opts.encode = encode
opts.decode = decode

app.use(session(app, opts))

function encode(body) {
try {
body = JSON.stringify(body)
const plainbuf = new Buffer(body)
const cipherbuf = encrypt(plainbuf, secret)
return `crypto-session:${cipherbuf.toString('base64')}`
}
catch(err) {
console.error('Crypto-session: encode error resetting session', body, err, (err ? err.stack : undefined));
return encrypt(new Buffer('').toString('base64'), secret);
}
}

function decode(text) {
try {
if (!/^crypto-session:/.test(text))
throw 'Unrecognized encrypted session format.'

text = text.substring('crypto-session:'.length)
const buf = new Buffer(text, 'base64')
const body = decrypt(buf, secret).toString('utf8')
const json = JSON.parse(body)

// check if the cookie is expired
if (!json._expire) return null
if (json._expire < Date.now()) return null

return json
}
catch(err) {
console.log(err)
try {
const jsonString = new Buffer(text, 'base64').toString('utf8')
JSON.parse(jsonString)
// Already JSON
console.log('Crypto-session: Encrypting plaintext session.', jsonString)
return text
}
catch(error2) {// debug('decode %j error: %s', json, err);
// throw new Error('Crypto-session: Discarding session: ' + text)
console.error('Crypto-session: Discarding session', text, error2);
return {};
}
console.error('Crypto-session: decode error resetting session', text, err, (err ? err.stack : undefined));
return {};
}
}
}

/**
* @arg {Buffer} buf
* @return {Buffer}
*/
function encrypt(buf, secret) {
const nonce = Buffer.from(sodium.randombytes_buf(sodium.crypto_box_NONCEBYTES))
const ciphertext = sodium.crypto_secretbox_easy(buf, nonce, secret)
return Buffer.concat([nonce, Buffer.from(ciphertext)])
}

/**
* @arg {Buffer} buf
* @return Buffer
*/
function decrypt(buf, secret) {
const nonce = buf.slice(0, sodium.crypto_box_NONCEBYTES);
const cipherbuf = buf.slice(sodium.crypto_box_NONCEBYTES);
return sodium.crypto_secretbox_open_easy(cipherbuf, nonce, secret, 'text');
}
Loading

0 comments on commit cba28ff

Please sign in to comment.