Skip to content

Commit

Permalink
♻️ #13 upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Feb 17, 2019
1 parent 205d65b commit b2cd6f4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ts/toolbar/Record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class Record extends MenuItemClass {
if (mediaRecorder.isRecording) {
mediaRecorder.stopRecording()
vditor.upload.element.className = 'vditor-upload'
const file = new File([mediaRecorder.buildWavFileBlob()],
const file:File = new File([mediaRecorder.buildWavFileBlob()],
`record${(new Date()).getTime()}.wav`, {type: 'video/webm'})
uploadFiles(vditor, [file])
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/ts/toolbar/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class Upload extends MenuItemClass {
}

_bindEvent(vditor: Vditor) {
this.element.querySelector('input').addEventListener('change', (event: any) => {
this.element.querySelector('input').addEventListener('change', (event: HTMLInputEvent) => {
if (event.target.files.length === 0) {
return
}
Expand Down
6 changes: 5 additions & 1 deletion src/ts/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ declare module 'turndown-plugin-gfm/lib/turndown-plugin-gfm.es.js'
declare var webkitAudioContext: {
prototype: AudioContext;
new(contextOptions?: AudioContextOptions): AudioContext;
};
}

interface HTMLInputEvent extends Event {
target: HTMLInputElement & EventTarget;
}

interface I18nLang {
en_US: string;
Expand Down
10 changes: 7 additions & 3 deletions src/ts/upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ class UploadClass {
}
}

const genUploadingLabel = (vditor: Vditor, files: any): string => {
const genUploadingLabel = (vditor: Vditor, files: DataTransferItemList | FileList | File[]): string => {
let uploadingStr = ''
for (let iMax = files.length, i = 0; i < iMax; i++) {
const file = files[i].getAsFile ? files[i].getAsFile() : files[i]
let file = files[i]
if (file instanceof DataTransferItem) {
file = file.getAsFile()
}

const tag = file.type.indexOf('image') === -1 ? '' : '!'
if (!file.name) {
return ''
Expand Down Expand Up @@ -72,7 +76,7 @@ const genUploadedLabel = (editorElement: HTMLTextAreaElement, responseText: stri
})
}

const uploadFiles = (vditor: Vditor, files: any, element?: HTMLInputElement) => {
const uploadFiles = (vditor: Vditor, files: FileList | DataTransferItemList | File[], element?: HTMLInputElement) => {
const formData = new FormData()
const uploadFiles = []
for (let i = 0; i < files.length; i++) {
Expand Down

0 comments on commit b2cd6f4

Please sign in to comment.