-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
190 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './fws-wrapper' | ||
export * from './i18n-backend' | ||
export * from './rest'; | ||
export * from "./helpers"; | ||
export * from "./helpers"; | ||
export * from "./upload"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
export type FileUploadState = 'queue' | 'uploading' | 'success' | 'error'; | ||
|
||
export interface FileUpload { | ||
file: File; | ||
progress: number; | ||
state: FileUploadState; | ||
cancelController?: AbortController; | ||
} | ||
|
||
export class Uploader { | ||
public files: FileUpload[] = []; | ||
|
||
addFile(file: File) { | ||
this.files.push({ | ||
file, | ||
progress: 0, | ||
state: 'queue', | ||
}); | ||
} | ||
|
||
clearFiles() { | ||
for (let i = 0; i < this.files.length; i++) { | ||
if (this.files[i].state === 'queue') { | ||
this.cancelUpload(i); | ||
} | ||
} | ||
this.files = []; | ||
} | ||
|
||
addFiles(files: FileList) { | ||
for (let i = 0; i < files.length; i++) { | ||
this.addFile(files[i]); | ||
} | ||
} | ||
|
||
startUpload(endpoint: string = '/Blob/Upload', callback: any = null) { | ||
let uploadCount = 0; | ||
|
||
this.files.forEach((upload, index) => { | ||
if (upload.state === 'queue') { | ||
this.uploadFile(index, endpoint, () => { | ||
uploadCount++; | ||
if (uploadCount === this.files.length) { | ||
if (callback) { | ||
callback(); | ||
} | ||
} | ||
}); | ||
} else { | ||
uploadCount++; | ||
if (uploadCount === this.files.length && callback) { | ||
callback(); | ||
} | ||
} | ||
}); | ||
} | ||
private uploadFile(index: number, endpoint: string, uploadCompleteCallback: () => void) { | ||
const fileUpload = this.files[index]; | ||
const formData = new FormData(); | ||
formData.append('file', fileUpload.file); | ||
|
||
const xhr = new XMLHttpRequest(); | ||
const cancelController = new AbortController(); | ||
fileUpload.cancelController = { abort: () => xhr.abort(), signal: cancelController.signal }; | ||
|
||
xhr.upload.addEventListener('progress', (event) => { | ||
if (event.lengthComputable) { | ||
const progress = Math.round((event.loaded / event.total) * 100); | ||
fileUpload.progress = progress; | ||
} | ||
}); | ||
|
||
xhr.addEventListener('load', () => { | ||
if (xhr.status >= 200 && xhr.status < 300) { | ||
fileUpload.state = 'success'; | ||
} else { | ||
fileUpload.state = 'error'; | ||
} | ||
fileUpload.progress = 100; | ||
uploadCompleteCallback(); | ||
}); | ||
|
||
xhr.addEventListener('error', () => { | ||
fileUpload.state = 'error'; | ||
fileUpload.progress = 100; | ||
uploadCompleteCallback(); | ||
}); | ||
|
||
fileUpload.state = 'uploading'; | ||
xhr.open('POST', endpoint); | ||
xhr.send(formData); | ||
} | ||
|
||
|
||
cancelUpload(index: number) { | ||
const fileUpload = this.files[index]; | ||
if (fileUpload.cancelController) { | ||
fileUpload.cancelController.abort(); | ||
fileUpload.state = 'error'; | ||
} | ||
} | ||
|
||
getFileUploads() { | ||
return this.files; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<script setup lang="ts"> | ||
import { ref, onMounted } from "vue"; | ||
import { useTranslation, useRest, useEventBus } from "@fy-/fws-vue"; | ||
import { getLocales } from "@fy-/fws-js"; | ||
const translate = useTranslation(); | ||
const maxValue = ref(0); | ||
const rest = useRest(); | ||
const stats = ref<any>(); | ||
const getProcess = async () => { | ||
const data = await rest(`JS`, "GET"); | ||
if (data && data.result == "success") { | ||
stats.value = data.data; | ||
} | ||
}; | ||
const eventBus = useEventBus(); | ||
onMounted(async () => { | ||
eventBus.emit("main-loading", true); | ||
await getProcess(); | ||
eventBus.emit("main-loading", false); | ||
}); | ||
</script> | ||
<template> | ||
<div class="container xl:max-w-6xl mx-auto px-4 mt-8"> | ||
<h1 class="text-3xl mb-6"> | ||
JS Workers | ||
<small class="text-sm italic" | ||
>(π requests, π» restarts, π queue size)</small | ||
> | ||
</h1> | ||
<div v-for="(v, k) in stats" :key="v.Name"> | ||
<h3 class="text-xl font-bold">{{ k }}</h3> | ||
<div class="p-6 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4"> | ||
<div | ||
class="flex flex-row items-center justify-between bg-gray-100 p-3 rounded-full py-2" | ||
v-for="p in v" | ||
> | ||
<div class="text-sm font-bold"> | ||
{{ p.IsReady ? "β " : "β οΈ" }} {{ p.Name.replace(k, "") }} | ||
</div> | ||
<div class="text-sm">{{ p.Latency }}ms</div> | ||
<div class="text-sm">{{ p.RequestsHandled }} π</div> | ||
<div class="text-sm">{{ p.Restarts }} π»</div> | ||
<div class="text-sm">{{ p.InputQueue }} π</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters