@ -2,8 +2,8 @@
var async = require ( 'async' )
var async = require ( 'async' )
var $ = require ( 'jquery' )
var $ = require ( 'jquery' )
var yo = require ( 'yo-yo' )
var yo = require ( 'yo-yo' )
var minixhr = require ( 'minixhr' ) // simple and small cross-browser XMLHttpRequest (XHR)
var remixLib = require ( 'remix-lib' )
var remixLib = require ( 'remix-lib' )
var Gists = require ( 'gists' )
var EventManager = remixLib . EventManager
var EventManager = remixLib . EventManager
var FileExplorer = require ( '../files/file-explorer' )
var FileExplorer = require ( '../files/file-explorer' )
var modalDialog = require ( '../ui/modaldialog' )
var modalDialog = require ( '../ui/modaldialog' )
@ -274,18 +274,16 @@ function filepanel (appAPI, filesProvider) {
// ------------------ gist publish --------------
// ------------------ gist publish --------------
function publishToGist ( fileProviderName ) {
function publishToGist ( fileProviderName ) {
function cb ( data ) {
function cb ( error , data ) {
if ( data instanceof Error ) {
if ( error ) {
console . log ( 'fail' , data . message )
modalDialogCustom . alert ( 'Failed to create gist: ' + error )
modalDialogCustom . alert ( 'Failed to create gist: ' + ( data || 'Unknown transport error' ) )
} else {
} else {
data = JSON . parse ( data )
if ( data . html _url ) {
if ( data . html _url ) {
modalDialogCustom . confirm ( null , ` Created a gist at ${ data . html _url } . Would you like to open it in a new window? ` , ( ) => {
modalDialogCustom . confirm ( null , ` Created a gist at ${ data . html _url } . Would you like to open it in a new window? ` , ( ) => {
window . open ( data . html _url , '_blank' )
window . open ( data . html _url , '_blank' )
} )
} )
} else {
} else {
modalDialogCustom . alert ( data . message + ' ' + data . documentation _url )
modalDialogCustom . alert ( data . message + ' ' + data . documentation _url + ' ' + JSON . stringify ( data . errors , null , '\t' ) )
}
}
}
}
}
}
@ -295,18 +293,23 @@ function filepanel (appAPI, filesProvider) {
if ( error ) {
if ( error ) {
console . log ( error )
console . log ( error )
modalDialogCustom . alert ( 'Failed to create gist: ' + error )
modalDialogCustom . alert ( 'Failed to create gist: ' + error )
} else {
var tokenAccess = appAPI . config . get ( 'settings/gist-access-token' )
if ( ! tokenAccess ) {
modalDialogCustom . alert ( 'Remix requires an access token (which includes gists creation permission). Please go to the settings tab for more information.' )
} else {
} else {
var description = 'Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. \n Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=' + queryParams . get ( ) . version + '&optimize=' + queryParams . get ( ) . optimize + '&gist='
var description = 'Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. \n Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=' + queryParams . get ( ) . version + '&optimize=' + queryParams . get ( ) . optimize + '&gist='
console . log ( packaged )
var gists = new Gists ( {
minixhr ( {
token : tokenAccess
url : 'https://api.github.com/gists' ,
} )
method : 'POST' ,
gists . create ( {
data : JSON . stringify ( {
description : description ,
description : description ,
public : true ,
public : true ,
files : packaged
files : packaged
} , ( error , result ) => {
cb ( error , result )
} )
} )
} , cb )
}
}
}
} )
} )
}
}