Merge branch 'V2' into feature/V2/BulkSelectionPanel

This commit is contained in:
EthanHealy01 2025-09-17 15:44:29 +01:00 committed by GitHub
commit 30072f4289
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 32 additions and 91 deletions

View File

@ -1,22 +0,0 @@
{
"permissions": {
"allow": [
"Bash(chmod:*)",
"Bash(mkdir:*)",
"Bash(./gradlew:*)",
"Bash(grep:*)",
"Bash(cat:*)",
"Bash(find:*)",
"Bash(npm test)",
"Bash(npm test:*)",
"Bash(ls:*)",
"Bash(npx tsc:*)",
"Bash(node:*)",
"Bash(npm run dev:*)",
"Bash(sed:*)",
"Bash(npm run typecheck:*)"
],
"deny": [],
"defaultMode": "acceptEdits"
}
}

View File

@ -89,7 +89,6 @@ return useToolOperation({
endpoint: '/api/v1/misc/compress-pdf',
buildFormData: (params, file: File) => { /* single file */ },
multiFileEndpoint: false,
filePrefix: 'compressed_'
});
```
@ -103,7 +102,7 @@ return useToolOperation({
endpoint: '/api/v1/general/split-pages',
buildFormData: (params, files: File[]) => { /* all files */ },
multiFileEndpoint: true,
filePrefix: 'split_'
filePrefix: 'split_',
});
```
@ -115,7 +114,6 @@ return useToolOperation({
return useToolOperation({
operationType: 'convert',
customProcessor: async (params, files) => { /* custom logic */ },
filePrefix: 'converted_'
});
```

View File

@ -11,6 +11,8 @@ import FileEditorThumbnail from './FileEditorThumbnail';
import FilePickerModal from '../shared/FilePickerModal';
import SkeletonLoader from '../shared/SkeletonLoader';
import { FileId, StirlingFile } from '../../types/fileContext';
import { downloadBlob } from '../../utils/downloadUtils';
interface FileEditorProps {
onOpenPageEditor?: () => void;
@ -278,7 +280,6 @@ const FileEditor = ({
const handleDeleteFile = useCallback((fileId: FileId) => {
const record = activeStirlingFileStubs.find(r => r.id === fileId);
const file = record ? selectors.getFile(record.id) : null;
if (record && file) {
// Remove file from context but keep in storage (close, don't delete)
const contextFileId = record.id;
@ -290,6 +291,14 @@ const FileEditor = ({
}
}, [activeStirlingFileStubs, selectors, removeFiles, setSelectedFiles, selectedFileIds]);
const handleDownloadFile = useCallback((fileId: FileId) => {
const record = activeStirlingFileStubs.find(r => r.id === fileId);
const file = record ? selectors.getFile(record.id) : null;
if (record && file) {
downloadBlob(file, file.name);
}
}, [activeStirlingFileStubs, selectors, setStatus]);
const handleViewFile = useCallback((fileId: FileId) => {
const record = activeStirlingFileStubs.find(r => r.id === fileId);
if (record) {
@ -401,6 +410,7 @@ const FileEditor = ({
onViewFile={handleViewFile}
onSetStatus={setStatus}
onReorderFiles={handleReorderFiles}
onDownloadFile={handleDownloadFile}
toolMode={toolMode}
isSupported={isFileSupported(record.name)}
/>

View File

@ -13,6 +13,7 @@ import { StirlingFileStub } from '../../types/fileContext';
import styles from './FileEditor.module.css';
import { useFileContext } from '../../contexts/FileContext';
import { FileId } from '../../types/file';
import { formatFileSize } from '../../utils/fileUtils';
import ToolChain from '../shared/ToolChain';
@ -28,7 +29,7 @@ interface FileEditorThumbnailProps {
onViewFile: (fileId: FileId) => void;
onSetStatus: (status: string) => void;
onReorderFiles?: (sourceFileId: FileId, targetFileId: FileId, selectedFileIds: FileId[]) => void;
onDownloadFile?: (fileId: FileId) => void;
onDownloadFile: (fileId: FileId) => void;
toolMode?: boolean;
isSupported?: boolean;
}
@ -61,29 +62,6 @@ const FileEditorThumbnail = ({
const pageCount = file.processedFile?.totalPages || 0;
const downloadSelectedFile = useCallback(() => {
// Prefer parent-provided handler if available
if (typeof onDownloadFile === 'function') {
onDownloadFile(file.id);
return;
}
// Fallback: attempt to download using the File object if provided
const maybeFile = (file as unknown as { file?: File }).file;
if (maybeFile instanceof File) {
const link = document.createElement('a');
link.href = URL.createObjectURL(maybeFile);
link.download = maybeFile.name || file.name || 'download';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(link.href);
return;
}
// If we can't find a way to download, surface a status message
onSetStatus?.(typeof t === 'function' ? t('downloadUnavailable', 'Download unavailable for this item') : 'Download unavailable for this item');
}, [file, onDownloadFile, onSetStatus, t]);
const handleRef = useRef<HTMLSpanElement | null>(null);
// ---- Selection ----
@ -91,12 +69,7 @@ const FileEditorThumbnail = ({
// ---- Meta formatting ----
const prettySize = useMemo(() => {
const bytes = file.size ?? 0;
if (bytes === 0) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}`;
return formatFileSize(file.size);
}, [file.size]);
const extUpper = useMemo(() => {
@ -305,7 +278,7 @@ const FileEditorThumbnail = ({
<button
className={styles.actionRow}
onClick={() => { downloadSelectedFile(); setShowActions(false); }}
onClick={() => { onDownloadFile(file.id); setShowActions(false); }}
>
<DownloadOutlinedIcon fontSize="small" />
<span>{t('download', 'Download')}</span>

View File

@ -3,5 +3,5 @@ import { useAppConfig } from '../hooks/useAppConfig';
// Get base URL from app config with fallback
export const getBaseUrl = (): string => {
const { config } = useAppConfig();
return config?.baseUrl || 'https://demo.stirlingpdf.com';
return config?.baseUrl || 'https://stirling.com';
};

View File

@ -81,24 +81,6 @@ describe('useMergeOperation', () => {
expect(formData.get('generateToc')).toBe('false');
});
test('should handle response correctly', () => {
renderHook(() => useMergeOperation());
const config = getToolConfig();
const mockBlob = new Blob(['merged content'], { type: 'application/pdf' });
const mockFiles = [
new File(['content1'], 'file1.pdf', { type: 'application/pdf' }),
new File(['content2'], 'file2.pdf', { type: 'application/pdf' })
];
const result = config.responseHandler!(mockBlob, mockFiles) as File[];
expect(result).toHaveLength(1);
expect(result[0].name).toBe('merged_file1.pdf');
expect(result[0].type).toBe('application/pdf');
expect(result[0].size).toBe(mockBlob.size);
});
test('should return the hook result from useToolOperation', () => {
const { result } = renderHook(() => useMergeOperation());

View File

@ -1,5 +1,5 @@
import { useTranslation } from 'react-i18next';
import { useToolOperation, ResponseHandler, ToolOperationConfig, ToolType } from '../shared/useToolOperation';
import { useToolOperation, ToolOperationConfig, ToolType } from '../shared/useToolOperation';
import { createStandardErrorHandler } from '../../../utils/toolErrorHandler';
import { MergeParameters } from './useMergeParameters';
@ -16,11 +16,6 @@ const buildFormData = (parameters: MergeParameters, files: File[]): FormData =>
return formData;
};
const mergeResponseHandler: ResponseHandler = (blob: Blob, originalFiles: File[]): File[] => {
const filename = `merged_${originalFiles[0].name}`
return [new File([blob], filename, { type: 'application/pdf' })];
};
// Operation configuration for automation
export const mergeOperationConfig: ToolOperationConfig<MergeParameters> = {
toolType: ToolType.multiFile,
@ -28,7 +23,6 @@ export const mergeOperationConfig: ToolOperationConfig<MergeParameters> = {
operationType: 'merge',
endpoint: '/api/v1/general/merge-pdfs',
filePrefix: 'merged_',
responseHandler: mergeResponseHandler,
};
export const useMergeOperation = () => {

View File

@ -31,7 +31,10 @@ interface BaseToolOperationConfig<TParams> {
/** Operation identifier for tracking and logging */
operationType: string;
/** Prefix added to processed filenames (e.g., 'compressed_', 'split_') */
/**
* Prefix added to processed filenames (e.g., 'compressed_', 'split_').
* Only generally useful for multiFile interfaces.
*/
filePrefix?: string;
/**
@ -68,6 +71,9 @@ export interface MultiFileToolOperationConfig<TParams> extends BaseToolOperation
/** This tool processes multiple files at once. */
toolType: ToolType.multiFile;
/** Prefix added to processed filename (e.g., 'merged_', 'split_') */
filePrefix: string;
/** Builds FormData for API request. */
buildFormData: ((params: TParams, files: File[]) => FormData);
@ -214,9 +220,9 @@ export const useToolOperation = <TParams>(
processedFiles = await config.responseHandler(response.data, filesForAPI);
} else if (response.data.type === 'application/pdf' ||
(response.headers && response.headers['content-type'] === 'application/pdf')) {
// Single PDF response (e.g. split with merge option) - use original filename
const originalFileName = filesForAPI[0]?.name || 'document.pdf';
const singleFile = new File([response.data], originalFileName, { type: 'application/pdf' });
// Single PDF response (e.g. split with merge option) - add prefix to first original filename
const filename = `${config.filePrefix}${filesForAPI[0]?.name || 'document.pdf'}`;
const singleFile = new File([response.data], filename, { type: 'application/pdf' });
processedFiles = [singleFile];
} else {
// Default: assume ZIP response for multi-file endpoints