added refresh token

This commit is contained in:
SlimusMinus
2026-08-03 02:44:57 +03:00
parent b6c61c72d9
commit abbcc330e7
16 changed files with 210 additions and 135 deletions

View File

@@ -5,8 +5,17 @@ import { getImageUrl } from "../config/authConstants";
const MAX_SIZE_MB = 5;
export const ACCEPT = "image/jpeg,image/png,image/webp";
let idCounter = 0;
const nextId = () => `img-${++idCounter}-${Date.now()}`;
/**
* Генератор уникального id для превью изображения.
* crypto.randomUUID доступен во всех современных браузерах;
* для страховки — fallback на timestamp + random.
*/
function generateImageId() {
if (typeof crypto !== "undefined" && crypto.randomUUID) {
return `img-${crypto.randomUUID()}`;
}
return `img-${Date.now()}-${Math.random().toString(36).slice(2)}`;
}
export function useImageUpload(existingUrls = []) {
const [images, setImages] = useState([]);
@@ -49,7 +58,7 @@ export function useImageUpload(existingUrls = []) {
try {
const compressedFiles = await Promise.all(files.map(f => compressImage(f)));
const newImages = compressedFiles.map(file => ({
id: nextId(),
id: generateImageId(),
file,
preview: URL.createObjectURL(file),
isExisting: false,
@@ -103,4 +112,4 @@ export function useImageUpload(existingUrls = []) {
getFilesForUpload,
getExistingUrlsToKeep,
};
}
}