Commit cb79f7bf authored by gxkai's avatar gxkai

fix: 添加默认目录

parent 3b44de3c
...@@ -182,7 +182,7 @@ class App { ...@@ -182,7 +182,7 @@ class App {
responseType: 'blob' responseType: 'blob'
}).then(async _ => { }).then(async _ => {
await resetWorkspaces() await resetWorkspaces()
const files = await unZipFile(_.data) const files = await unZipFile(_.data, 'default')
await uploadFile({ files }, '', () => {}) await uploadFile({ files }, '', () => {})
window.parent.postMessage({ event: 'showIframe' }, '\*') window.parent.postMessage({ event: 'showIframe' }, '\*')
}) })
......
...@@ -14,9 +14,9 @@ export const initialState:{[uri: string]: { ...@@ -14,9 +14,9 @@ export const initialState:{[uri: string]: {
language?: string; language?: string;
// model?: Ace.Editor; // model?: Ace.Editor;
model?: Ace.EditSession; model?: Ace.EditSession;
}} = {} }} = {}
export const reducerActions = (models= initialState, action: Action) => { export const reducerActions = (models = initialState, action: Action) => {
const ace = action.ace const ace = action.ace
const editor = action.editor const editor = action.editor
switch (action.type) { switch (action.type) {
...@@ -31,8 +31,6 @@ export const reducerActions = (models= initialState, action: Action) => { ...@@ -31,8 +31,6 @@ export const reducerActions = (models= initialState, action: Action) => {
// @ts-ignore // @ts-ignore
const model = ace.createEditSession(uri, 'ace/mode/solidity') const model = ace.createEditSession(uri, 'ace/mode/solidity')
model.setValue(value) model.setValue(value)
// editor.setValue(value)
// models[uri].model = editor
models[uri].model = model models[uri].model = model
editor.on('change', () => action.payload.events.onDidChangeContent(uri)) editor.on('change', () => action.payload.events.onDidChangeContent(uri))
return models return models
...@@ -41,7 +39,6 @@ export const reducerActions = (models= initialState, action: Action) => { ...@@ -41,7 +39,6 @@ export const reducerActions = (models= initialState, action: Action) => {
const uri = action.payload.uri const uri = action.payload.uri
const model = models[uri]?.model const model = models[uri]?.model
if (model) model.destroy() if (model) model.destroy()
// if (model) model.session.destroy()
delete models[uri] delete models[uri]
return models return models
} }
...@@ -63,7 +60,7 @@ export const reducerActions = (models= initialState, action: Action) => { ...@@ -63,7 +60,7 @@ export const reducerActions = (models= initialState, action: Action) => {
// editor.revealLine(line) // editor.revealLine(line)
editor.moveCursorToPosition({ editor.moveCursorToPosition({
column, column,
row: line, row: line
}) })
// editor.setPosition({ column, lineNumber: line }) // editor.setPosition({ column, lineNumber: line })
return models return models
......
...@@ -5,7 +5,7 @@ import { addInputFieldSuccess, createWorkspaceError, createWorkspaceRequest, cre ...@@ -5,7 +5,7 @@ import { addInputFieldSuccess, createWorkspaceError, createWorkspaceRequest, cre
import { checkSlash, checkSpecialChars } from '@remix-ui/helper' import { checkSlash, checkSpecialChars } from '@remix-ui/helper'
import JSZip from 'jszip' import JSZip from 'jszip'
import FileType from 'file-type/browser' import FileType from 'file-type/browser'
const zip = new JSZip(); const zip = new JSZip()
const examples = require('../../../../../../apps/remix-ide/src/app/editor/examples') const examples = require('../../../../../../apps/remix-ide/src/app/editor/examples')
const QueryParams = require('../../../../../../apps/remix-ide/src/lib/query-params') const QueryParams = require('../../../../../../apps/remix-ide/src/lib/query-params')
const LOCALHOST = ' - connect to localhost - ' const LOCALHOST = ' - connect to localhost - '
...@@ -230,8 +230,8 @@ export const switchToWorkspace = async (name: string) => { ...@@ -230,8 +230,8 @@ export const switchToWorkspace = async (name: string) => {
dispatch(setReadOnlyMode(false)) dispatch(setReadOnlyMode(false))
} }
} }
export const resetWorkspaces = async (name: string = 'default_workspace') => { export const resetWorkspaces = async (name: string = 'default_workspace') => {
const workspaces = await getWorkspaces(); const workspaces = await getWorkspaces()
if (Array.isArray(workspaces)) { if (Array.isArray(workspaces)) {
await Promise.all(workspaces.map(async _ => { await Promise.all(workspaces.map(async _ => {
await deleteWorkspace(_) await deleteWorkspace(_)
...@@ -239,34 +239,34 @@ export const resetWorkspaces = async (name: string = 'default_workspace') => { ...@@ -239,34 +239,34 @@ export const resetWorkspaces = async (name: string = 'default_workspace') => {
} }
await createWorkspace(name) await createWorkspace(name)
} }
export async function getMimeTypeOfFile(blob) { export async function getMimeTypeOfFile (blob) {
const res = await FileType.fromBlob(blob) const res = await FileType.fromBlob(blob)
return res ? res.mime: 'Unknown filetype' return res ? res.mime : 'Unknown filetype'
} }
export const unZipFile = async (file) => { export const unZipFile = async (file, root) => {
const unzipData = await zip.loadAsync(file) const unzipData = await zip.loadAsync(file)
const arr = [] const arr = []
for (let zobj of Object.values(unzipData.files)) { for (const zobj of Object.values(unzipData.files)) {
if (zobj.dir) continue; if (zobj.dir) continue
const zblob = await zobj.async("blob"); const zblob = await zobj.async('blob')
const mimeType = await getMimeTypeOfFile(zblob); const mimeType = await getMimeTypeOfFile(zblob)
const zfile = new File([zblob], zobj.name, { type: mimeType }); const zfile = new File([zblob], root ? root + '/' + zobj.name : zobj.name, { type: mimeType })
arr.push(zfile) arr.push(zfile)
} }
return arr return arr
} }
export const uploadFile = async (target, targetFolder: string, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void, isFolder=false) => { export const uploadFile = async (target, targetFolder: string, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void, isFolder = false) => {
// TODO The file explorer is merely a view on the current state of // TODO The file explorer is merely a view on the current state of
// the files module. Please ask the user here if they want to overwrite // the files module. Please ask the user here if they want to overwrite
// a file and then just use `files.add`. The file explorer will // a file and then just use `files.add`. The file explorer will
// pick that up via the 'fileAdded' event from the files module. // pick that up via the 'fileAdded' event from the files module.
async function iterator (files) { async function iterator (files) {
await Promise.all(Array.from(files).map(async (file: File)=> { await Promise.all(Array.from(files).map(async (file: File) => {
if ( if (
file.type === 'application/zip' file.type === 'application/zip'
) { ) {
return await iterator(await unZipFile(file)) return await iterator(await unZipFile(file))
} }
const workspaceProvider = plugin.fileProviders.workspace const workspaceProvider = plugin.fileProviders.workspace
const loadFile = (name: string): void => { const loadFile = (name: string): void => {
...@@ -309,7 +309,7 @@ export const uploadFile = async (target, targetFolder: string, cb?: (err: Error, ...@@ -309,7 +309,7 @@ export const uploadFile = async (target, targetFolder: string, cb?: (err: Error,
}) })
})) }))
} }
await iterator(target.files ) await iterator(target.files)
} }
export const uploadFolder = async (target, targetFolder: string, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => { export const uploadFolder = async (target, targetFolder: string, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment