diff --git a/src/main/app.ts b/src/main/app.ts index e2e5356a..9baea84b 100644 --- a/src/main/app.ts +++ b/src/main/app.ts @@ -285,7 +285,7 @@ if (!gotTheLock) { { type: 'radio', checked: urlMode === 'scheme', - label: '正式端口(Schema)', + label: '正式端口(Scheme)', click: () => { urlMode = 'scheme' reload() diff --git a/src/main/server/file.ts b/src/main/server/file.ts index a0cc3f43..4116c334 100644 --- a/src/main/server/file.ts +++ b/src/main/server/file.ts @@ -88,9 +88,9 @@ const checkHash = (repo: string, p: string, oldHash: string) => { return oldHash === hash(repo, p) } -const upload = (repo: string, file: any, path: string) => { +const upload = (repo: string, buffer: Buffer, path: string) => { if (readonly) throw new Error('只读模式') - write(repo, path, fs.readFileSync(file.path)) + write(repo, path, buffer) } const travels = (location: string, repo: string, basePath: string, markedFiles: MarkedFile[] | null = null): any => { diff --git a/src/main/server/index.ts b/src/main/server/index.ts index e410c1f8..9d7a3032 100644 --- a/src/main/server/index.ts +++ b/src/main/server/index.ts @@ -63,7 +63,9 @@ const attachment = async (ctx: any, next: any) => { if (ctx.method === 'POST') { const path = ctx.request.body.path const repo = ctx.request.body.repo - file.upload(repo, ctx.request.files.attachment, path) + const attachment = ctx.request.body.attachment + const buffer = Buffer.from(attachment.substring(attachment.indexOf(',') + 1), 'base64') + file.upload(repo, buffer, path) ctx.body = result('ok', '上传成功', path) } else if (ctx.method === 'GET') { ctx.type = mime.getType(ctx.query.path) @@ -251,7 +253,10 @@ const server = (port = 3000) => { multipart: true, formLimit: '20mb', jsonLimit: '20mb', - textLimit: '20mb' + textLimit: '20mb', + formidable: { + maxFieldsSize: 268435456 + } })) app.use(async (ctx: any, next: any) => await wrapper(ctx, next, fileContent)) diff --git a/src/renderer/useful/file.ts b/src/renderer/useful/file.ts index 5d592656..8583487f 100644 --- a/src/renderer/useful/file.ts +++ b/src/renderer/useful/file.ts @@ -137,7 +137,7 @@ const search = async (repo: string, text: string) => { const upload = async (repo: string, belongPath: string, uploadFile: any, name: string | null = null): Promise<{repo: string; path: string; relativePath: string}> => { return new Promise((resolve, reject) => { const fr = new FileReader() - fr.readAsBinaryString(uploadFile) + fr.readAsDataURL(uploadFile) fr.onloadend = async () => { try { const filename = name || Crypto.binMd5(fr.result).substr(0, 8) + extname(uploadFile.name) @@ -152,7 +152,7 @@ const upload = async (repo: string, belongPath: string, uploadFile: any, name: s ) formData.append('repo', repo) formData.append('path', path) - formData.append('attachment', uploadFile) + formData.append('attachment', fr.result as string) await fetchHttp('/api/attachment', { method: 'POST', body: formData })