Skip to content

Commit

Permalink
chore: adjust gen dual pdf display
Browse files Browse the repository at this point in the history
  • Loading branch information
cir9no committed Jan 18, 2025
1 parent e6d4426 commit 0e6d63c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions frontend/src/hooks/metadata-ai-operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,20 @@ export const MetadataAIOperationsProvider = ({

const genDualLayerPDF = useCallback(({ parentDir, fileName }, { success_callback, fail_callback } = {}) => {
const filePath = Utils.joinPath(parentDir, fileName);
const inProgressToaster = toaster.notifyInProgress(gettext('Making PDF searchable by AI...'), { duration: null });
const inProgressToaster = toaster.notifyInProgress(gettext('Making PDF searchable by AI...'), { duration: 3 });
metadataAPI.genDualLayerPDF(repoID, filePath).then(res => {
inProgressToaster.close();
if (res.data.task_status === 'processing') {
toaster.notifyInProgress(gettext('The task has been started, perhaps by another user'), { duration: 5 });
} else if (res.data.task_status === 'already_ocr') {
const userConfirmed = window.confirm(gettext('The text has already been OCR processed. Do you want to proceed with OCR again?'));
if (userConfirmed) {
metadataAPI.genDualLayerPDF(repoID, filePath, { force: true }).then(() => {
success_callback && success_callback();
metadataAPI.genDualLayerPDF(repoID, filePath, { force: true }).then(res => {
if (res.data.task_status === 'processing') {
toaster.notifyInProgress(gettext('The task has been started, perhaps by another user'), { duration: 5 });
} else {
success_callback && success_callback();
}
}).catch(() => {
const errorMessage = gettext('Failed to make PDF searchable');
toaster.danger(errorMessage);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/metadata/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class MetadataManagerAPI {
};

genDualLayerPDF = (repoID, filePath, options = {}) => {
const url = this.server + '/api/v2.1/ai/pdf/to-dual-layer/';
const url = this.server + '/api/v2.1/ai/pdf/generate-text-layer/';
const params = {
path: filePath,
repo_id: repoID,
Expand Down
2 changes: 1 addition & 1 deletion seahub/ai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def generate_summary(params):

def generate_dual_layer_pdf(params):
headers = gen_headers()
url = urljoin(SEAFILE_AI_SERVER_URL, '/api/v1/pdf/generate-dual-layer-pdf/')
url = urljoin(SEAFILE_AI_SERVER_URL, '/api/v1/pdf/generate-text-layer/')
resp = requests.post(url, json=params, headers=headers)
return resp

Expand Down
2 changes: 1 addition & 1 deletion seahub/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,5 +1061,5 @@
re_path(r'^api/v2.1/ai/ocr/$', OCR.as_view(), name='api-v2.1-ocr'),
re_path(r'^api/v2.1/ai/translate/$', Translate.as_view(), name='api-v2.1-translate'),
re_path(r'^api/v2.1/ai/writing-assistant/$', WritingAssistant.as_view(), name='api-v2.1-writing-assistant'),
re_path(r'^api/v2.1/ai/pdf/to-dual-layer/$', GenDualLayerPDF.as_view(), name='api-v2.1-pdf-to-dual-layer'),
re_path(r'^api/v2.1/ai/pdf/generate-text-layer/$', GenDualLayerPDF.as_view(), name='api-v2.1-pdf-generate-text-layer'),
]

0 comments on commit 0e6d63c

Please sign in to comment.