Commit cb79f7bf authored by gxkai's avatar gxkai

fix: 添加默认目录

parent 3b44de3c
......@@ -182,7 +182,7 @@ class App {
responseType: 'blob'
}).then(async _ => {
await resetWorkspaces()
const files = await unZipFile(_.data)
const files = await unZipFile(_.data, 'default')
await uploadFile({ files }, '', () => {})
window.parent.postMessage({ event: 'showIframe' }, '\*')
})
......
......@@ -16,7 +16,7 @@ export const initialState:{[uri: string]: {
model?: Ace.EditSession;
}} = {}
export const reducerActions = (models= initialState, action: Action) => {
export const reducerActions = (models = initialState, action: Action) => {
const ace = action.ace
const editor = action.editor
switch (action.type) {
......@@ -31,8 +31,6 @@ export const reducerActions = (models= initialState, action: Action) => {
// @ts-ignore
const model = ace.createEditSession(uri, 'ace/mode/solidity')
model.setValue(value)
// editor.setValue(value)
// models[uri].model = editor
models[uri].model = model
editor.on('change', () => action.payload.events.onDidChangeContent(uri))
return models
......@@ -41,7 +39,6 @@ export const reducerActions = (models= initialState, action: Action) => {
const uri = action.payload.uri
const model = models[uri]?.model
if (model) model.destroy()
// if (model) model.session.destroy()
delete models[uri]
return models
}
......@@ -63,7 +60,7 @@ export const reducerActions = (models= initialState, action: Action) => {
// editor.revealLine(line)
editor.moveCursorToPosition({
column,
row: line,
row: line
})
// editor.setPosition({ column, lineNumber: line })
return models
......
......@@ -5,7 +5,7 @@ import { addInputFieldSuccess, createWorkspaceError, createWorkspaceRequest, cre
import { checkSlash, checkSpecialChars } from '@remix-ui/helper'
import JSZip from 'jszip'
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 QueryParams = require('../../../../../../apps/remix-ide/src/lib/query-params')
const LOCALHOST = ' - connect to localhost - '
......@@ -231,7 +231,7 @@ export const switchToWorkspace = async (name: string) => {
}
}
export const resetWorkspaces = async (name: string = 'default_workspace') => {
const workspaces = await getWorkspaces();
const workspaces = await getWorkspaces()
if (Array.isArray(workspaces)) {
await Promise.all(workspaces.map(async _ => {
await deleteWorkspace(_)
......@@ -239,30 +239,30 @@ export const resetWorkspaces = async (name: string = 'default_workspace') => {
}
await createWorkspace(name)
}
export async function getMimeTypeOfFile(blob) {
export async function getMimeTypeOfFile (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 arr = []
for (let zobj of Object.values(unzipData.files)) {
if (zobj.dir) continue;
const zblob = await zobj.async("blob");
const mimeType = await getMimeTypeOfFile(zblob);
const zfile = new File([zblob], zobj.name, { type: mimeType });
for (const zobj of Object.values(unzipData.files)) {
if (zobj.dir) continue
const zblob = await zobj.async('blob')
const mimeType = await getMimeTypeOfFile(zblob)
const zfile = new File([zblob], root ? root + '/' + zobj.name : zobj.name, { type: mimeType })
arr.push(zfile)
}
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
// 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
// pick that up via the 'fileAdded' event from the files module.
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 (
file.type === 'application/zip'
) {
......@@ -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) => {
......
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