fixed ocr/tts... caching
This commit is contained in:
@@ -5,6 +5,7 @@ import { useFilesAPI, type DirEntry } from '../../../hooks/useFilesAPI';
|
||||
import { useTasks, type TaskSummary } from '../useTasks';
|
||||
import { useUserState } from 'state/useUserState';
|
||||
import { useAuth } from 'hooks/useAuth';
|
||||
import { usePanelChannel } from 'hooks/usePanelChannel';
|
||||
|
||||
type DefaultSort = {
|
||||
field: 'name' | 'size' | 'type' | 'date';
|
||||
@@ -76,13 +77,15 @@ export const useFileBrowserApp = (basePath: string, rootOverride?: string, initi
|
||||
}
|
||||
};
|
||||
|
||||
const [refreshSignal] = usePanelChannel<number>('files:refresh-signal', 0);
|
||||
|
||||
useEffect(() => {
|
||||
if (basePath !== '/' && !currentPath.startsWith(basePath)) {
|
||||
setCurrentPath(basePath);
|
||||
return;
|
||||
}
|
||||
refresh();
|
||||
}, [currentPath, homeRoot]);
|
||||
}, [currentPath, homeRoot, refreshSignal]);
|
||||
|
||||
useEffect(() => {
|
||||
setSelected(new Set());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useFilesAPI } from '../../hooks/useFilesAPI';
|
||||
import { usePanelChannel } from 'hooks/usePanelChannel';
|
||||
import { toast } from 'sonner';
|
||||
import { getFileType } from './file-types';
|
||||
import { FileViewerContext } from './FileViewerContext';
|
||||
@@ -35,6 +36,7 @@ export const FileViewerProvider = ({
|
||||
const [saveResultLoading, setSaveResultLoading] = useState(false);
|
||||
const [editing, setEditing] = useState(false);
|
||||
const files = useFilesAPI(root);
|
||||
const [, setRefreshSignal] = usePanelChannel<number>('files:refresh-signal', 0);
|
||||
const fileType = getFileType(fileName);
|
||||
const editable = fileType === 'markdown' || fileType === 'code' || fileType === 'text';
|
||||
|
||||
@@ -114,9 +116,7 @@ export const FileViewerProvider = ({
|
||||
}
|
||||
};
|
||||
|
||||
const isCachedResult =
|
||||
root === 'user-data' &&
|
||||
(filePath.startsWith('ocr/') || filePath.startsWith('tts/') || filePath.startsWith('transcriptions/') || filePath.startsWith('audio/'));
|
||||
const isCachedResult = root === 'user-data' && filePath.startsWith('cache/');
|
||||
|
||||
const handleSaveResult = isCachedResult
|
||||
? async () => {
|
||||
@@ -124,6 +124,7 @@ export const FileViewerProvider = ({
|
||||
try {
|
||||
const { savedPath } = await files.saveResult(filePath);
|
||||
const savedName = savedPath.split('/').pop() ?? savedPath;
|
||||
setRefreshSignal((n) => n + 1);
|
||||
toast.success(`Saved as "${savedName}"`);
|
||||
} catch {
|
||||
toast.error('Failed to save file');
|
||||
|
||||
@@ -49,19 +49,19 @@ export const useFilesAPI = (root: string = 'home') => {
|
||||
client.post(withRoot('/file-browser/download-video'), { url, path, audioOnly }),
|
||||
|
||||
tts: (path: string) =>
|
||||
client.post<{ audioPath: string; audioRoot: string }>(withRoot('/file-browser/tts'), { path }),
|
||||
client.post<{ audioPath: string; audioRoot: string }>('/file-browser/tts', { path, root }),
|
||||
|
||||
ocr: (path: string) =>
|
||||
client.post<{ ocrPath: string; ocrRoot: string }>(withRoot('/file-browser/ocr'), { path }),
|
||||
client.post<{ ocrPath: string; ocrRoot: string }>('/file-browser/ocr', { path, root }),
|
||||
|
||||
transcribe: (path: string) =>
|
||||
client.post<{ transcriptionPath: string; transcriptionRoot: string }>(withRoot('/file-browser/transcribe'), { path }),
|
||||
client.post<{ transcriptionPath: string; transcriptionRoot: string }>('/file-browser/transcribe', { path, root }),
|
||||
|
||||
extractAudio: (path: string) =>
|
||||
client.post<{ audioPath: string; audioRoot: string }>(withRoot('/file-browser/extract-audio'), { path }),
|
||||
client.post<{ audioPath: string; audioRoot: string }>('/file-browser/extract-audio', { path, root }),
|
||||
|
||||
extract: (path: string) =>
|
||||
client.post<{ extractedPath: string }>(withRoot('/file-browser/extract'), { path }),
|
||||
client.post<{ extractedPath: string }>('/file-browser/extract', { path, root }),
|
||||
|
||||
saveResult: (path: string) =>
|
||||
client.post<{ savedPath: string }>('/file-browser/save-result', { path }),
|
||||
|
||||
Reference in New Issue
Block a user