Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Commit

Permalink
add game upload form
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstep committed Sep 26, 2017
1 parent 2bda5ed commit 4907855
Show file tree
Hide file tree
Showing 6 changed files with 376 additions and 6 deletions.
44 changes: 43 additions & 1 deletion public/server.electron.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const _config = require('./config.electron.js')
const http = require('http')
const path = require('path')
const queryp = require('querystring')
const fs = require('fs')

const Gun = require('gun')
Expand All @@ -19,11 +20,34 @@ const filetypes = {
'.wav': 'audio/wav',
}

let server = http.createServer(function (request, response) {
const server = http.createServer(function (request, response) {
if(Gun.serve(request, response)){
return
}

response.setHeader('Access-Control-Allow-Origin', '*')


if (request.method == 'POST' && request.url.indexOf('/upload_game/')>-1) {
console.log( 'upload_game' )

let body = ''
request.on('data', function (data) {
body += data

// Too much POST data, kill the connection!
// 1e6 === 1 * Math.pow(10, 6) === 1 * 1000000 ~~~ 1MB
if (body.length > 1e6) request.connection.destroy()
})

request.on('end', ()=>{
uploadGame(queryp.parse(body), ()=>{
response.end('{"result":"ok"}', 'utf-8')
})
})
}


let filePath = __dirname + request.url
if (filePath == __dirname+'/'){
filePath = __dirname+'/index.html'
Expand Down Expand Up @@ -98,3 +122,21 @@ setTimeout(()=>{
require('./app.background.js')

}, 1000)


const uploadGame = function(data, callback){
console.log( data )
let manifest
for(let k in data){
try {
manifest = JSON.parse(k).manifest
break
} catch(e) {
console.log(e)
}
}

console.log( manifest )

callback()
}
4 changes: 3 additions & 1 deletion src/app.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ if (window) {
}

document.addEventListener('DOMContentLoaded',()=>{
window.DiceGameChannel = DiceGameChannel
if (typeof DiceGameChannel!='undefined') {
window.DiceGameChannel = DiceGameChannel
}

if (process.env.APP_BUILD_FOR_WINSERVER) {
setTimeout(()=>{
Expand Down
48 changes: 47 additions & 1 deletion src/server.electron.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const _config = require('./config.electron.js')
const http = require('http')
const path = require('path')
const queryp = require('querystring')
const fs = require('fs')

const Gun = require('gun')
Expand All @@ -19,11 +20,34 @@ const filetypes = {
'.wav': 'audio/wav',
}

let server = http.createServer(function (request, response) {
const server = http.createServer(function (request, response) {
if(Gun.serve(request, response)){
return
}

response.setHeader('Access-Control-Allow-Origin', '*')


if (request.method == 'POST' && request.url.indexOf('/upload_game/')>-1) {
console.log( 'upload_game' )

let body = ''
request.on('data', function (data) {
body += data

// Too much POST data, kill the connection!
// 1e6 === 1 * Math.pow(10, 6) === 1 * 1000000 ~~~ 1MB
if (body.length > 1e6) request.connection.destroy()
})

request.on('end', ()=>{
uploadGame(queryp.parse(body), ()=>{
response.end('{"result":"ok"}', 'utf-8')
})
})
}


let filePath = __dirname + request.url
if (filePath == __dirname+'/'){
filePath = __dirname+'/index.html'
Expand Down Expand Up @@ -98,3 +122,25 @@ setTimeout(()=>{
require('./app.background.js')

}, 1000)


const uploadGame = function(data, callback){
console.log( data )
let manifest
for(let k in data){
try {
manifest = JSON.parse(k).manifest
break
} catch(e) {
console.log(e)
}
}

// read file
// manifest.path+manifest.name

// copy dir
// manifest.path

callback()
}
9 changes: 7 additions & 2 deletions src/view/components/screens/bankroll/bankroll.tag
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ import './games_list'
<div id="bankroll" class={screen:true, loading:this.loading}>
<div id="loading_status">{loading_status}</div>

<div class="upload-area">
<upload_game></upload_game>
</div>

<games_list></games_list>

<div class="game-add-forms">
<form id="add_game_form" onsubmit={deployGame}>
<!-- <form id="add_game_form" onsubmit={deployGame}>
<fieldset>
<legend>Deploy new game contract</legend>
<select ref="game_name" required>
Expand All @@ -67,7 +71,7 @@ import './games_list'
</select>
<button class="button" id="create_new_game">Create</button>
</fieldset>
</form>
</form> -->
<!-- <form id="add_contract_form" onsubmit={addContract}>
<fieldset>
<legend>or add existing game contract</legend>
Expand All @@ -76,6 +80,7 @@ import './games_list'
</fieldset>
</form> -->
</div>

</div>

<style type="less">
Expand Down
2 changes: 1 addition & 1 deletion src/view/components/screens/bankroll/games_list.tag
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import route from 'riot-route'
this.on('mount', ()=>{

setInterval(()=>{
if (DiceGameChannel.Games) {
if (typeof DiceGameChannel!='undefined' && DiceGameChannel.Games) {
this.dd_games = []
for(let k in DiceGameChannel.Games){
for(let j in DiceGameChannel.Games[k].history){
Expand Down
Loading

0 comments on commit 4907855

Please sign in to comment.