Skip to content

Commit

Permalink
fxs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fy- committed Nov 6, 2024
1 parent 88181b2 commit 1464b0a
Show file tree
Hide file tree
Showing 47 changed files with 4,989 additions and 3,176 deletions.
8 changes: 4 additions & 4 deletions packages/fws-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fy-/fws-js",
"version": "0.0.22",
"version": "0.0.26",
"description": "FWJS is a framework for building web applications FWS",
"scripts": {
"build": "tsc && node copyPackage.js"
Expand All @@ -12,9 +12,9 @@
},
"devDependencies": {
"@fy-/fws-types": "workspace:*",
"i18next": "^23.7.11",
"rimraf": "^5.0.5",
"typescript": "^5.3.3"
"i18next": "^23.16.4",
"rimraf": "^6.0.1",
"typescript": "^5.6.3"
},
"main": "src/index.ts",
"types": "src/index.d.ts"
Expand Down
57 changes: 41 additions & 16 deletions packages/fws-js/src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,62 +35,87 @@ export class Uploader {

startUpload(endpoint: string = '/Blob/Upload', callback: any = null) {
let uploadCount = 0;

const totalFiles = this.files.length;
const responses = new Array(totalFiles);

this.files.forEach((upload, index) => {
if (upload.state === 'queue') {
this.uploadFile(index, endpoint, () => {
this.uploadFile(index, endpoint, (response) => {
responses[index] = response;
uploadCount++;
if (uploadCount === this.files.length) {
if (uploadCount === totalFiles) {
if (callback) {
callback();
if (totalFiles === 1) {
callback(responses[0]);
} else {
callback(responses);
}
}
}
});
} else {
uploadCount++;
if (uploadCount === this.files.length && callback) {
callback();
if (uploadCount === totalFiles && callback) {
if (totalFiles === 1) {
callback(responses[0]);
} else {
callback(responses);
}
}
}
});
}
private uploadFile(index: number, endpoint: string, uploadCompleteCallback: () => void) {

private uploadFile(index: number, endpoint: string, uploadCompleteCallback: (response: any) => 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();

let response = null;
try {
response = JSON.parse(xhr.responseText);
} catch (e) {
response = xhr.responseText;
}
uploadCompleteCallback(response);
});

xhr.addEventListener('error', () => {
fileUpload.state = 'error';
fileUpload.progress = 100;
uploadCompleteCallback();

let response = null;
try {
response = JSON.parse(xhr.responseText);
} catch (e) {
response = xhr.responseText;
}
uploadCompleteCallback(response);
});

fileUpload.state = 'uploading';
xhr.open('POST', endpoint);
xhr.send(formData);
}


cancelUpload(index: number) {
const fileUpload = this.files[index];
Expand All @@ -103,4 +128,4 @@ export class Uploader {
getFileUploads() {
return this.files;
}
}
}
64 changes: 32 additions & 32 deletions packages/fws-obelix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@
"peerDependencies": {
"@fy-/fws-js": "^0.0.x",
"@fy-/fws-types": "^0.0.x",
"@fy-/fws-vue": "^0.3.x",
"@fy-/head": "^0.0.x",
"@vuelidate/core": "^2.0.x",
"@vuelidate/validators": "^2.0.x",
"@vueuse/core": "^10.x.x",
"markdown-it": "^14.x.x",
"mitt": "^3.0.x",
"pinia": "2.x.x",
"timeago.js": "^4.0.x",
"vue": "^3.3.x",
"vue-router": "^4.1.x",
"@fy-/fws-vue": "^0.3.x",
"markdown-it": "^14.x.x"
"vue-router": "^4.1.x"
},
"scripts": {
"clean": "rimraf dist",
Expand All @@ -53,38 +53,38 @@
"@fy-/fws-js": "workspace:*",
"@fy-/fws-types": "workspace:*",
"@fy-/fws-vue": "workspace:*",
"@fy-/head": "^0.0.39",
"markdown-it": "^14.1.0",
"@headlessui/vue": "^1.7.16",
"@heroicons/vue": "^2.1.1",
"@rushstack/eslint-patch": "^1.6.1",
"@types/node": "^20.10.5",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@vitejs/plugin-vue": "^4.5.2",
"@vitejs/plugin-vue-jsx": "^3.1.0",
"@vue/compiler-sfc": "^3.3.13",
"@vue/eslint-config-prettier": "^8.0.0",
"@vue/runtime-core": "^3.3.13",
"@vue/server-renderer": "^3.3.13",
"@fy-/head": "^0.0.46",
"@headlessui/vue": "^1.7.23",
"@heroicons/vue": "^2.1.5",
"@rushstack/eslint-patch": "^1.10.4",
"@types/node": "^22.8.1",
"@typescript-eslint/eslint-plugin": "^8.11.0",
"@vitejs/plugin-vue": "^5.1.4",
"@vitejs/plugin-vue-jsx": "^4.0.1",
"@vue/compiler-sfc": "^3.5.12",
"@vue/eslint-config-prettier": "^10.1.0",
"@vue/runtime-core": "^3.5.12",
"@vue/server-renderer": "^3.5.12",
"@vuelidate/core": "^2.0.3",
"@vuelidate/validators": "^2.0.4",
"@vueuse/core": "^10.7.0",
"eslint": "^8.56.0",
"eslint-plugin-vue": "^9.19.2",
"i18next": "^23.7.11",
"@vueuse/core": "^11.1.0",
"eslint": "^9.13.0",
"eslint-plugin-vue": "^9.29.1",
"i18next": "^23.16.4",
"markdown-it": "^14.1.0",
"mitt": "^3.0.1",
"pinia": "^2.1.7",
"postcss": "^8.4.32",
"primevue": "^3.51.0",
"rollup": "^4.9.1",
"pinia": "^2.2.4",
"postcss": "^8.4.47",
"primevue": "^4.1.1",
"rollup": "^4.24.2",
"rollup-plugin-copy": "^3.5.0",
"sass": "^1.69.5",
"typescript": "^5.3.3",
"unplugin-vue-components": "^0.26.0",
"vite": "^5.0.10",
"vue": "^3.3.13",
"vue-router": "^4.2.5",
"vue-tsc": "^1.8.26",
"timeago.js": "^4.0.2"
"sass": "^1.80.4",
"timeago.js": "^4.0.2",
"typescript": "^5.6.3",
"unplugin-vue-components": "^0.27.4",
"vite": "^5.4.10",
"vue": "^3.5.12",
"vue-router": "^4.4.5",
"vue-tsc": "^2.1.8"
}
}
6 changes: 3 additions & 3 deletions packages/fws-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fy-/fws-types",
"version": "0.1.1",
"version": "0.1.2",
"description": "Types for FWS",
"types": "./src/index.d.ts",
"scripts": {
Expand All @@ -12,7 +12,7 @@
"author": "Florian 'Fy' Gasquez <m@fy.to>",
"license": "MIT",
"devDependencies": {
"rimraf": "^5.0.5",
"typescript": "^5.3.3"
"rimraf": "^6.0.1",
"typescript": "^5.6.3"
}
}
47 changes: 0 additions & 47 deletions packages/fws-vue/.eslintrc.cjs

This file was deleted.

26 changes: 26 additions & 0 deletions packages/fws-vue/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import antfu from '@antfu/eslint-config'

export default antfu({
ignores: [
'**/histoire-dist/',
'**/generated/',
'**/public/',
'**/.svelte-kit/',
],
}, {
rules: {
'curly': ['error', 'multi-line', 'consistent'],
'antfu/if-newline': 'off',
'antfu/no-import-dist': 'off',
'node/prefer-global/process': 'off',
'no-console': 'warn',
'ts/no-use-before-define': 'warn',
'vue/define-macros-order': 'off', // Bugged
'ts/no-unsafe-function-type': 'off',
},
}, {
files: ['**/*.vue'],
rules: {
'import/first': 'off',
},
})
Loading

0 comments on commit 1464b0a

Please sign in to comment.