suppress error. publish Files to Gist

pull/5065/head
Joseph Izang 4 months ago committed by Aniket
parent 3663320776
commit 3bb5002b7b
  1. 1
      apps/remix-ide/src/app/plugins/remixd-handle.tsx
  2. 51
      libs/remix-ui/workspace/src/lib/actions/index.ts
  3. 61
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -43,6 +43,7 @@ export class RemixdHandle extends WebsocketPlugin {
await this.appManager.deactivatePlugin(plugin)
}
}
//@ts-ignore
if (super.socket) super.deactivate()
// this.appManager.deactivatePlugin('git') // plugin call doesn't work.. see issue https://github.com/ethereum/remix-plugin/issues/342
this.localhostProvider.close((error) => {

@ -260,10 +260,56 @@ export type SolidityConfiguration = {
runs: string
}
const buildGistPayload = (selectedFiles: { key: string, type: 'file' | 'folder', content: string }[]) => {
if (!selectedFiles || selectedFiles.length === 0) return
const files: { [key: string]: { content: string }} = {}
for (const file of selectedFiles) {
files[file.key] = { content: file.content }
}
return files
}
export const publishFilesToGist = (arrayOfSelectedFiles: any) => {
const gistPayload = buildGistPayload(arrayOfSelectedFiles)
if (!gistPayload) {
console.error('No files to publish');
return;
}
console.log('primed and ready', gistPayload)
const config = plugin.registry.get('config').api
const accessToken = config.get('settings/gist-access-token')
if (!accessToken) {
dispatch(displayNotification('Authorize Token', 'Remix requires an access token (which includes gists creation permission). Please go to the settings tab to create one.', 'Close', null, () => { }))
return
}
try {
const params = queryParams.get() as SolidityConfiguration
const 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=' + params.version + '&optimize=' + params.optimize + '&runs=' + params.runs + '&gist='
const gists = new Gists({ token: accessToken })
dispatch(displayPopUp('Creating a new gist ...'))
// console.log('checking this', { gistPayload, gists, params })
// return
gists.create({
description: description,
public: true,
files: gistPayload
}, (error, result) => {
console.log('what comes back from gist creation', { error, result })
handleGistResponse(error, result)
// throw new Error('Thing didn\'t work as expected!')
})
console.log('publishFilesToGistIsDone')
} catch (error) {
console.log('There was an error', error)
}
}
export const publishToGist = async (path?: string) => {
// If 'id' is not defined, it is not a gist update but a creation so we have to take the files from the browser explorer.
const folder = path || '/'
try {
let id
if (path) {
@ -274,6 +320,7 @@ export const publishToGist = async (path?: string) => {
id = await plugin.call('filePanel', 'isGist')
}
const packaged = await packageGistFiles(folder)
console.log('packed files', packaged)
// check for token
const config = plugin.registry.get('config').api
const accessToken = config.get('settings/gist-access-token')
@ -325,6 +372,7 @@ export const publishToGist = async (path?: string) => {
public: true,
files: packaged
}, (error, result) => {
console.log('what comes back from gist creation', { error, result })
handleGistResponse(error, result)
})
}
@ -539,6 +587,7 @@ export const restoreBackupZip = async () => {
const packageGistFiles = async (directory) => {
const workspaceProvider = plugin.fileProviders.workspace
const isFile = await workspaceProvider.isFile(directory)
console.log('here is the state of things in packageGistFiles', { directory, isFile })
return new Promise((resolve, reject) => {
const ret = {}

@ -18,6 +18,7 @@ import { appPlatformTypes, platformContext } from '@remix-ui/app'
import { ElectronMenu } from './components/electron-menu'
import { ElectronWorkspaceName } from './components/electron-workspace-name'
import { branch } from '@remix-ui/git'
import { publishFilesToGist } from './actions'
const _paq = (window._paq = window._paq || [])
@ -155,31 +156,67 @@ export function Workspace() {
})
}
const nameGistFolder = (filePath: string) => {
const prepend = `Gist_${filePath}`
const append = `${prepend}-folder`
return append
}
/**
* Void action to ensure multiselected files are published
* folders are not handled
*/
const handlePublishingMultiSelectedFilesToGist = async () => {
const tempFolderName = '.gistTemp'
// first create a temporary folder to populate selected files
try {
await global.dispatchCreateNewFolder(tempFolderName, ROOT_PATH)
feTarget.filter(feObject => feObject.type !== 'folder')
.forEach(async feFile => {
await copyFile(feFile.key, tempFolderName)
})
await global.dispatchPublishToGist(tempFolderName)
global.plugin.on('finishedGistPublish', async (folderName) => {
console.log('name of folder', folderName)
if (folderName === tempFolderName)
await global.dispatchDeletePath(folderName)
})
// await global.dispatchCreateNewFolder(tempFolderName, ROOT_PATH)
// const selectedFiles = []
// for (const one of feTarget) {
// if (one.type === 'folder') return
// const content = await global.plugin.call('fileManager', 'readFile', one.key)
// selectedFiles.push({ key: one.key, type: one.type, content: content })
// }
// console.log('Files selected', selectedFiles)
// publishFilesToGist(selectedFiles)
// console.log('completed')
// await global.dispatchPublishToGist(ROOT_PATH)
// global.plugin.on('finishedGistPublish', async (folderName) => {
// console.log('name of folder', folderName)
// if (folderName === tempFolderName)
// await global.dispatchDeletePath(folderName)
// })
const selectedFiles = []
let gistFolder = ''
let tempFolderName = ''
for (const one of feTarget) {
if (one.type === 'folder') return
// const content = await global.plugin.call('fileManager', 'readFile', one.key)
// selectedFiles.push({ key: one.key, type: one.type, content: content })
tempFolderName += one.key
}
gistFolder = nameGistFolder(tempFolderName)
await global.dispatchCreateNewFolder(gistFolder, ROOT_PATH)
for (const one of feTarget) {
await copyFile(one.key, gistFolder)
}
publishFolderToGist(gistFolder)
console.log('check this out', { selectedFiles, gistFolder })
setTimeout(async () => {
// await global.dispatchDeletePath([gistFolder])
await deletePath([gistFolder])
}, 500)
} catch (error) {
await global.plugin.call('notification', 'toast', 'Could not publish files to gist. There was an error')
await global.plugin.call('notification', 'toast', typeof(error) === 'string' ? error : `${console.log(error)} check the console for more details`)
}
}
useEffect(() => {
global.plugin.on('finishedGistPublish', (folderName) => {
console.log('finished publishing to gist', folderName)
})
}, [])
const showFullMessage = async (title: string, loadItem: string, examples: Array<string>, prefix = '') => {
setModalState((prevState) => {
return {

Loading…
Cancel
Save