Compare commits
2 Commits
v0.2.1-dev
..
v0.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 9bc3c7c8fc | |||
| 0476315322 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "backend",
|
"name": "backend",
|
||||||
"version": "0.2.1",
|
"version": "0.3.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -532,7 +532,6 @@ export const validateImportedDrawing = (data: any): boolean => {
|
|||||||
// CSRF Protection
|
// CSRF Protection
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
const CSRF_TOKEN_LENGTH = 32;
|
|
||||||
const CSRF_TOKEN_HEADER = "x-csrf-token";
|
const CSRF_TOKEN_HEADER = "x-csrf-token";
|
||||||
const CSRF_TOKEN_EXPIRY_MS = 24 * 60 * 60 * 1000; // 24 hours
|
const CSRF_TOKEN_EXPIRY_MS = 24 * 60 * 60 * 1000; // 24 hours
|
||||||
const CSRF_TOKEN_FUTURE_SKEW_MS = 5 * 60 * 1000; // 5 minutes clock skew tolerance
|
const CSRF_TOKEN_FUTURE_SKEW_MS = 5 * 60 * 1000; // 5 minutes clock skew tolerance
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "frontend",
|
"name": "frontend",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.2.1",
|
"version": "0.3.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export const UploadProvider: React.FC<{ children: ReactNode }> = ({ children })
|
|||||||
|
|
||||||
const uploadFiles = useCallback(async (files: File[], targetCollectionId: string | null) => {
|
const uploadFiles = useCallback(async (files: File[], targetCollectionId: string | null) => {
|
||||||
const newTasks: UploadTask[] = files.map(f => ({
|
const newTasks: UploadTask[] = files.map(f => ({
|
||||||
id: Math.random().toString(36).substring(2, 11),
|
id: crypto.randomUUID(),
|
||||||
fileName: f.name,
|
fileName: f.name,
|
||||||
status: 'pending',
|
status: 'pending',
|
||||||
progress: 0
|
progress: 0
|
||||||
@@ -56,12 +56,12 @@ export const UploadProvider: React.FC<{ children: ReactNode }> = ({ children })
|
|||||||
|
|
||||||
setTasks(prev => [...newTasks, ...prev]);
|
setTasks(prev => [...newTasks, ...prev]);
|
||||||
|
|
||||||
// Map file names to task IDs for progress callbacks
|
// Map file index to task ID for progress callbacks (handles duplicate filenames)
|
||||||
const fileTaskMap = new Map<string, string>();
|
const indexToTaskId = new Map<number, string>();
|
||||||
newTasks.forEach(t => fileTaskMap.set(t.fileName, t.id));
|
newTasks.forEach((t, index) => indexToTaskId.set(index, t.id));
|
||||||
|
|
||||||
const handleProgress = (fileName: string, status: UploadStatus, progress: number, error?: string) => {
|
const handleProgress = (fileIndex: number, status: UploadStatus, progress: number, error?: string) => {
|
||||||
const taskId = fileTaskMap.get(fileName);
|
const taskId = indexToTaskId.get(fileIndex);
|
||||||
if (taskId) {
|
if (taskId) {
|
||||||
updateTask(taskId, { status, progress, error });
|
updateTask(taskId, { status, progress, error });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export const importDrawings = async (
|
|||||||
targetCollectionId: string | null,
|
targetCollectionId: string | null,
|
||||||
onSuccess?: () => void | Promise<void>,
|
onSuccess?: () => void | Promise<void>,
|
||||||
onProgress?: (
|
onProgress?: (
|
||||||
fileName: string,
|
fileIndex: number,
|
||||||
status: UploadStatus,
|
status: UploadStatus,
|
||||||
progress: number,
|
progress: number,
|
||||||
error?: string
|
error?: string
|
||||||
@@ -25,12 +25,20 @@ export const importDrawings = async (
|
|||||||
let failCount = 0;
|
let failCount = 0;
|
||||||
const errors: string[] = [];
|
const errors: string[] = [];
|
||||||
|
|
||||||
|
// Build a map from drawingFile index to original file index for progress reporting
|
||||||
|
const originalIndexMap = new Map<number, number>();
|
||||||
|
drawingFiles.forEach((df, i) => {
|
||||||
|
const originalIndex = files.indexOf(df);
|
||||||
|
originalIndexMap.set(i, originalIndex);
|
||||||
|
});
|
||||||
|
|
||||||
// We process files in parallel (Promise.all) but we could limit concurrency if needed.
|
// We process files in parallel (Promise.all) but we could limit concurrency if needed.
|
||||||
// For now, full parallel is fine as browser limits connection count anyway.
|
// For now, full parallel is fine as browser limits connection count anyway.
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
drawingFiles.map(async (file) => {
|
drawingFiles.map(async (file, drawingIndex) => {
|
||||||
|
const fileIndex = originalIndexMap.get(drawingIndex) ?? drawingIndex;
|
||||||
try {
|
try {
|
||||||
if (onProgress) onProgress(file.name, 'processing', 0); // Parsing phase
|
if (onProgress) onProgress(fileIndex, 'processing', 0); // Parsing phase
|
||||||
|
|
||||||
const text = await file.text();
|
const text = await file.text();
|
||||||
const data = JSON.parse(text);
|
const data = JSON.parse(text);
|
||||||
@@ -61,7 +69,7 @@ export const importDrawings = async (
|
|||||||
preview: svg.outerHTML,
|
preview: svg.outerHTML,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (onProgress) onProgress(file.name, 'uploading', 0);
|
if (onProgress) onProgress(fileIndex, 'uploading', 0);
|
||||||
|
|
||||||
await api.post("/drawings", payload, {
|
await api.post("/drawings", payload, {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -73,12 +81,12 @@ export const importDrawings = async (
|
|||||||
const percentCompleted = Math.round(
|
const percentCompleted = Math.round(
|
||||||
(progressEvent.loaded * 100) / progressEvent.total
|
(progressEvent.loaded * 100) / progressEvent.total
|
||||||
);
|
);
|
||||||
onProgress(file.name, 'uploading', percentCompleted);
|
onProgress(fileIndex, 'uploading', percentCompleted);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (onProgress) onProgress(file.name, 'success', 100);
|
if (onProgress) onProgress(fileIndex, 'success', 100);
|
||||||
successCount++;
|
successCount++;
|
||||||
|
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
@@ -90,7 +98,7 @@ export const importDrawings = async (
|
|||||||
err?.message ||
|
err?.message ||
|
||||||
"Upload failed";
|
"Upload failed";
|
||||||
errors.push(`${file.name}: ${errorMessage}`);
|
errors.push(`${file.name}: ${errorMessage}`);
|
||||||
if (onProgress) onProgress(file.name, 'error', 0, errorMessage);
|
if (onProgress) onProgress(fileIndex, 'error', 0, errorMessage);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,19 +15,16 @@ try {
|
|||||||
console.warn("Unable to read VERSION file:", error);
|
console.warn("Unable to read VERSION file:", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
const appVersion = process.env.VITE_APP_VERSION?.trim() || versionFromFile;
|
||||||
!process.env.VITE_APP_VERSION ||
|
const buildLabel = process.env.VITE_APP_BUILD_LABEL?.trim() || "local development build";
|
||||||
process.env.VITE_APP_VERSION.trim().length === 0
|
|
||||||
) {
|
|
||||||
process.env.VITE_APP_VERSION = versionFromFile;
|
|
||||||
if (!process.env.VITE_APP_BUILD_LABEL) {
|
|
||||||
process.env.VITE_APP_BUILD_LABEL = "local development build";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
|
define: {
|
||||||
|
'import.meta.env.VITE_APP_VERSION': JSON.stringify(appVersion),
|
||||||
|
'import.meta.env.VITE_APP_BUILD_LABEL': JSON.stringify(buildLabel),
|
||||||
|
},
|
||||||
server: {
|
server: {
|
||||||
proxy: {
|
proxy: {
|
||||||
"/api": {
|
"/api": {
|
||||||
|
|||||||
Reference in New Issue
Block a user