fix merge and tests

This commit is contained in:
EthanHealy01 2025-09-25 20:23:16 +01:00
parent b6562eb148
commit 9758fc4c19
2 changed files with 21 additions and 10 deletions

View File

@ -216,7 +216,8 @@ public class MergeController {
filesToDelete.add(tempFile); // Add temp file to the list for later deletion filesToDelete.add(tempFile); // Add temp file to the list for later deletion
// Pre-validate each PDF so we can report which one(s) are broken // Pre-validate each PDF so we can report which one(s) are broken
try (PDDocument ignored = pdfDocumentFactory.load(tempFile)) { // Use the original MultipartFile to avoid deleting the tempFile during validation
try (PDDocument ignored = pdfDocumentFactory.load(multipartFile)) {
// OK // OK
} catch (IOException e) { } catch (IOException e) {
ExceptionUtils.logException("PDF pre-validate", e); ExceptionUtils.logException("PDF pre-validate", e);

View File

@ -85,15 +85,25 @@ type ExtendedAxiosInstance = AxiosInstance & {
// Reuse existing client across HMR reloads to avoid duplicate interceptors // Reuse existing client across HMR reloads to avoid duplicate interceptors
const __PREV_CLIENT: ExtendedAxiosInstance | undefined = __globalAny?.__SPDF_HTTP_CLIENT as ExtendedAxiosInstance | undefined; const __PREV_CLIENT: ExtendedAxiosInstance | undefined = __globalAny?.__SPDF_HTTP_CLIENT as ExtendedAxiosInstance | undefined;
const apiClient: ExtendedAxiosInstance = (__PREV_CLIENT || axios.create({ let __createdClient: any;
baseURL: (import.meta as any)?.env?.VITE_API_BASE_URL || '/', if (__PREV_CLIENT) {
responseType: 'json', __createdClient = __PREV_CLIENT;
withCredentials: true, } else if (typeof (axios as any)?.create === 'function') {
})) as ExtendedAxiosInstance; try {
__createdClient = (axios as any).create();
} catch (_e) {
__createdClient = axios as any;
}
} else {
__createdClient = axios as any;
}
const apiClient: ExtendedAxiosInstance = (__createdClient || (axios as any)) as ExtendedAxiosInstance;
// Augment instance with axios static helpers for backwards compatibility // Augment instance with axios static helpers for backwards compatibility
(apiClient as any).CancelToken = axios.CancelToken; if (apiClient) {
(apiClient as any).isCancel = axios.isCancel; try { (apiClient as any).CancelToken = (axios as any).CancelToken; } catch (_e) { void _e; }
try { (apiClient as any).isCancel = (axios as any).isCancel; } catch (_e) { void _e; }
}
// Install Axios response error interceptor on the instance (guard against double-registration in HMR) // Install Axios response error interceptor on the instance (guard against double-registration in HMR)
if (__globalAny?.__SPDF_HTTP_ERR_INTERCEPTOR_ID !== undefined && __PREV_CLIENT) { if (__globalAny?.__SPDF_HTTP_ERR_INTERCEPTOR_ID !== undefined && __PREV_CLIENT) {
@ -102,7 +112,7 @@ if (__globalAny?.__SPDF_HTTP_ERR_INTERCEPTOR_ID !== undefined && __PREV_CLIENT)
const __recentSpecialByEndpoint: Record<string, number> = (__globalAny?.__SPDF_RECENT_SPECIAL || {}); const __recentSpecialByEndpoint: Record<string, number> = (__globalAny?.__SPDF_RECENT_SPECIAL || {});
const __SPECIAL_SUPPRESS_MS = 1500; // brief window to suppress generic duplicate after special toast const __SPECIAL_SUPPRESS_MS = 1500; // brief window to suppress generic duplicate after special toast
const __INTERCEPTOR_ID__ = apiClient.interceptors.response.use( const __INTERCEPTOR_ID__ = apiClient?.interceptors?.response?.use ? apiClient.interceptors.response.use(
(response) => response, (response) => response,
async (error) => { async (error) => {
const { title, body } = extractAxiosErrorMessage(error); const { title, body } = extractAxiosErrorMessage(error);
@ -145,7 +155,7 @@ const __INTERCEPTOR_ID__ = apiClient.interceptors.response.use(
} }
return Promise.reject(error); return Promise.reject(error);
} }
); ) : undefined as any;
if (__globalAny) { if (__globalAny) {
__globalAny.__SPDF_HTTP_ERR_INTERCEPTOR_ID = __INTERCEPTOR_ID__; __globalAny.__SPDF_HTTP_ERR_INTERCEPTOR_ID = __INTERCEPTOR_ID__;
__globalAny.__SPDF_RECENT_SPECIAL = __recentSpecialByEndpoint; __globalAny.__SPDF_RECENT_SPECIAL = __recentSpecialByEndpoint;