From 7e072793eb224ad8a0edf9446c09b43df87e2ed6 Mon Sep 17 00:00:00 2001
From: parsa aghaei
Date: Mon, 3 Aug 2026 10:16:57 +0330
Subject: [PATCH] fix(types): allow File or ChangeEvent in handleFileUpload and
ensure safe localStorage in userStore
---
frontend/admin-panel/package-lock.json | 56 ++-----------------
frontend/admin-panel/src/pages/Videos.tsx | 9 ++-
.../lib/store/__tests__/userStore.test.ts | 1 +
frontend/application/lib/store/userStore.ts | 2 +-
4 files changed, 14 insertions(+), 54 deletions(-)
diff --git a/frontend/admin-panel/package-lock.json b/frontend/admin-panel/package-lock.json
index f59cc53..6a8039c 100644
--- a/frontend/admin-panel/package-lock.json
+++ b/frontend/admin-panel/package-lock.json
@@ -16,6 +16,7 @@
"react-hot-toast": "^2.6.0",
"react-router-dom": "^7.17.0",
"recharts": "^3.8.1",
+ "vite": "^8.0.12",
"zustand": "^5.0.14"
},
"devDependencies": {
@@ -33,8 +34,7 @@
"postcss": "^8.5.15",
"tailwindcss": "^4.3.0",
"typescript": "~6.0.2",
- "typescript-eslint": "^8.59.2",
- "vite": "^8.0.12"
+ "typescript-eslint": "^8.59.2"
}
},
"node_modules/@alloc/quick-lru": {
@@ -294,7 +294,6 @@
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.10.0.tgz",
"integrity": "sha512-yq6OkJ4p82CAfPl0u9mQebQHKPJkY7WrIuk205cTYnYe+k2Z8YBh11FrbRG/H6ihirqcacOgl2BIO8oyMQLeXw==",
- "dev": true,
"license": "MIT",
"optional": true,
"dependencies": {
@@ -306,7 +305,6 @@
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.10.0.tgz",
"integrity": "sha512-ewvYlk86xUoGI0zQRNq/mC+16R1QeDlKQy21Ki3oSYXNgLb45GV1P6A0M+/s6nyCuNDqe5VpaY84BzXGwVbwFA==",
- "dev": true,
"license": "MIT",
"optional": true,
"dependencies": {
@@ -317,7 +315,6 @@
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz",
"integrity": "sha512-uTII7OYF+/Mes/MrcIOYp5yOtSMLBWSIoLPpcgwipoiKbli6k322tcoFsxoIIxPDqW01SQGAgko4EzZi2BNv2w==",
- "dev": true,
"license": "MIT",
"optional": true,
"dependencies": {
@@ -572,7 +569,6 @@
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.5.tgz",
"integrity": "sha512-AWPoBRJ9tsnVhor4sjO7rkni+7p+2IAEFj6cx06UgP10jkQHqay/36uRV/bFkgrh18D9vb4cr8Q0Pthskgzy+Q==",
- "dev": true,
"license": "MIT",
"optional": true,
"dependencies": {
@@ -591,7 +587,6 @@
"version": "0.133.0",
"resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.133.0.tgz",
"integrity": "sha512-KzkdCd6Uxqnf6l3HOw1xfatAlUURA0g14cvBYFyJ5SaNOQbOUvBr9PKArcPcrNIeRsBdgcUzOGrhKveVpvOIGA==",
- "dev": true,
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/Boshen"
@@ -640,7 +635,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -657,7 +651,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -674,7 +667,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -691,7 +683,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -708,7 +699,6 @@
"cpu": [
"arm"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -725,7 +715,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"libc": [
"glibc"
],
@@ -745,7 +734,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"libc": [
"musl"
],
@@ -765,7 +753,6 @@
"cpu": [
"ppc64"
],
- "dev": true,
"libc": [
"glibc"
],
@@ -785,7 +772,6 @@
"cpu": [
"s390x"
],
- "dev": true,
"libc": [
"glibc"
],
@@ -805,7 +791,6 @@
"cpu": [
"x64"
],
- "dev": true,
"libc": [
"glibc"
],
@@ -825,7 +810,6 @@
"cpu": [
"x64"
],
- "dev": true,
"libc": [
"musl"
],
@@ -845,7 +829,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -862,7 +845,6 @@
"cpu": [
"wasm32"
],
- "dev": true,
"license": "MIT",
"optional": true,
"dependencies": {
@@ -881,7 +863,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -898,7 +879,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -912,7 +892,6 @@
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.1.tgz",
"integrity": "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==",
- "dev": true,
"license": "MIT"
},
"node_modules/@standard-schema/spec": {
@@ -1240,7 +1219,6 @@
"version": "0.10.2",
"resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.2.tgz",
"integrity": "sha512-RoBvJ2X0wuKlWFIjrwffGw1IqZHKQqzIchKaadZZfnNpsAYp2mM0h36JtPCjNDAHGgYez/15uMBpfGwchhiMgg==",
- "dev": true,
"license": "MIT",
"optional": true,
"dependencies": {
@@ -1335,7 +1313,7 @@
"version": "24.13.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.13.2.tgz",
"integrity": "sha512-fRa09kZTgu8o71KFcDjUFuc7F+dEbZYZmkI0mg5YBTRs0yMKjYHsq/c0urDKeDb+D5qVgXOdFcuu+DZPKOITwA==",
- "dev": true,
+ "devOptional": true,
"license": "MIT",
"dependencies": {
"undici-types": "~7.18.0"
@@ -2073,7 +2051,6 @@
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
"integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
- "dev": true,
"license": "Apache-2.0",
"engines": {
"node": ">=8"
@@ -2405,7 +2382,6 @@
"version": "6.5.0",
"resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz",
"integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==",
- "dev": true,
"license": "MIT",
"engines": {
"node": ">=12.0.0"
@@ -2524,7 +2500,6 @@
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
- "dev": true,
"hasInstallScript": true,
"license": "MIT",
"optional": true,
@@ -2787,7 +2762,7 @@
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/jiti/-/jiti-2.7.0.tgz",
"integrity": "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ==",
- "dev": true,
+ "devOptional": true,
"license": "MIT",
"bin": {
"jiti": "lib/jiti-cli.mjs"
@@ -2875,7 +2850,6 @@
"version": "1.32.0",
"resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.32.0.tgz",
"integrity": "sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ==",
- "dev": true,
"license": "MPL-2.0",
"dependencies": {
"detect-libc": "^2.0.3"
@@ -2908,7 +2882,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MPL-2.0",
"optional": true,
"os": [
@@ -2929,7 +2902,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MPL-2.0",
"optional": true,
"os": [
@@ -2950,7 +2922,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MPL-2.0",
"optional": true,
"os": [
@@ -2971,7 +2942,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MPL-2.0",
"optional": true,
"os": [
@@ -2992,7 +2962,6 @@
"cpu": [
"arm"
],
- "dev": true,
"license": "MPL-2.0",
"optional": true,
"os": [
@@ -3013,7 +2982,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"libc": [
"glibc"
],
@@ -3037,7 +3005,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"libc": [
"musl"
],
@@ -3061,7 +3028,6 @@
"cpu": [
"x64"
],
- "dev": true,
"libc": [
"glibc"
],
@@ -3085,7 +3051,6 @@
"cpu": [
"x64"
],
- "dev": true,
"libc": [
"musl"
],
@@ -3109,7 +3074,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MPL-2.0",
"optional": true,
"os": [
@@ -3130,7 +3094,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MPL-2.0",
"optional": true,
"os": [
@@ -3245,7 +3208,6 @@
"version": "3.3.12",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.12.tgz",
"integrity": "sha512-ZB9RH/39qpq5Vu6Y+NmUaFhQR6pp+M2Xt76XBnEwDaGcVAqhlvxrl3B2bKS5D3NH3QR76v3aSrKaF/Kiy7lEtQ==",
- "dev": true,
"funding": [
{
"type": "github",
@@ -3351,14 +3313,12 @@
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
"integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
- "dev": true,
"license": "ISC"
},
"node_modules/picomatch": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz",
"integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==",
- "dev": true,
"license": "MIT",
"engines": {
"node": ">=12"
@@ -3371,7 +3331,6 @@
"version": "8.5.15",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.15.tgz",
"integrity": "sha512-FfR8sjd4em2T6fb3I2MwAJU7HWVMr9zba+enmQeeWFfCbm+UOC/0X4DS8XtpUTMwWMGbjKYP7xjfNekzyGmB3A==",
- "dev": true,
"funding": [
{
"type": "opencollective",
@@ -3593,7 +3552,6 @@
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.0.3.tgz",
"integrity": "sha512-i00lAJ2ks1BYr7rjNjKC7BcqAS7nVfiT3QX1SI5aY+AFHblCmaUf9OE9dbdzDvW6dJxbi2ZCZiy9v3CcwOiX3g==",
- "dev": true,
"license": "MIT",
"dependencies": {
"@oxc-project/types": "=0.133.0",
@@ -3672,7 +3630,6 @@
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
"integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",
- "dev": true,
"license": "BSD-3-Clause",
"engines": {
"node": ">=0.10.0"
@@ -3709,7 +3666,6 @@
"version": "0.2.17",
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz",
"integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==",
- "dev": true,
"license": "MIT",
"dependencies": {
"fdir": "^6.5.0",
@@ -3739,7 +3695,6 @@
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
- "dev": true,
"license": "0BSD",
"optional": true
},
@@ -3798,7 +3753,7 @@
"version": "7.18.2",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz",
"integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==",
- "dev": true,
+ "devOptional": true,
"license": "MIT"
},
"node_modules/update-browserslist-db": {
@@ -3877,7 +3832,6 @@
"version": "8.0.16",
"resolved": "https://registry.npmjs.org/vite/-/vite-8.0.16.tgz",
"integrity": "sha512-h9bXPmJichP5fLmVQo3PyaGSDE2n3aPuomeAlVRm0JLmt4rY6zmPKd59HYI4LNW8oTK7tlTsuC7l/m7awx9Jcw==",
- "dev": true,
"license": "MIT",
"dependencies": {
"lightningcss": "^1.32.0",
diff --git a/frontend/admin-panel/src/pages/Videos.tsx b/frontend/admin-panel/src/pages/Videos.tsx
index c2c2e36..94c94ee 100644
--- a/frontend/admin-panel/src/pages/Videos.tsx
+++ b/frontend/admin-panel/src/pages/Videos.tsx
@@ -83,8 +83,13 @@ export default function Videos() {
setIsModalOpen(true);
};
- const handleFileUpload = async (e: React.ChangeEvent, type: 'thumbnail' | 'video') => {
- const file = e.target.files?.[0];
+ const handleFileUpload = async (e: React.ChangeEvent | File, type: 'thumbnail' | 'video') => {
+ let file: File | undefined;
+ if (e instanceof File) {
+ file = e;
+ } else {
+ file = e.target.files?.[0];
+ }
if (!file) return;
const uploadData = new FormData();
diff --git a/frontend/application/lib/store/__tests__/userStore.test.ts b/frontend/application/lib/store/__tests__/userStore.test.ts
index caaddf6..0797588 100644
--- a/frontend/application/lib/store/__tests__/userStore.test.ts
+++ b/frontend/application/lib/store/__tests__/userStore.test.ts
@@ -79,6 +79,7 @@ describe('userStore', () => {
vi.mocked(authService.getProfile).mockResolvedValue(mockProfileData);
+ (globalThis as any)._testToken = 'test-token';
const store = useUserStore.getState();
await store.fetchProfile();
diff --git a/frontend/application/lib/store/userStore.ts b/frontend/application/lib/store/userStore.ts
index ac45baf..b2b72e4 100644
--- a/frontend/application/lib/store/userStore.ts
+++ b/frontend/application/lib/store/userStore.ts
@@ -178,7 +178,7 @@ export const useUserStore = create()(
},
fetchProfile: async () => {
try {
- const token = localStorage.getItem('accessToken');
+ const token = typeof window !== 'undefined' && window.localStorage ? localStorage.getItem('accessToken') : (globalThis as any)._testToken;
if (!token) {
try { usePetStore.getState().reset(); } catch {}
try { localStorage.removeItem("canina-pets"); } catch {}