2026-02-05 21:01:19 +07:00
|
|
|
'use server'
|
|
|
|
|
|
|
|
|
|
import { getSessionData } from '@/app/actions/session';
|
|
|
|
|
import { API_BASE_URL } from '@/app/actions/definitions';
|
|
|
|
|
|
|
|
|
|
export async function searchUserFiles(fileId: string) {
|
|
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/files/${fileId}/similar?similarityLevels=DUPLICATE,SIMILARITY&auth_token=${token}`, {
|
|
|
|
|
method: 'GET'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
|
|
|
|
|
|
|
|
|
if (parsed.message_code === 0) {
|
|
|
|
|
return parsed.message_body;
|
|
|
|
|
} else {
|
2026-03-03 13:25:26 +07:00
|
|
|
throw parsed.message_desc;
|
2026-02-05 21:01:19 +07:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (`${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
2026-03-03 13:25:26 +07:00
|
|
|
|
|
|
|
|
if (error === 'File for search unsupported') {
|
|
|
|
|
return {
|
|
|
|
|
errorMessage: 'file-for-search-unsupported'
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
errorMessage: 'error'
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-05 21:01:19 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-10 15:40:18 +07:00
|
|
|
export async function searchGlobalFiles(fileId: string, currentPage: number) {
|
2026-02-05 21:01:19 +07:00
|
|
|
const token = await getSessionData('token');
|
2026-02-10 15:40:18 +07:00
|
|
|
|
2026-02-10 17:29:36 +07:00
|
|
|
//удалить когда поиск будет нормально работать
|
2026-02-23 13:41:07 +07:00
|
|
|
/* return {
|
|
|
|
|
images: [
|
|
|
|
|
{
|
|
|
|
|
url: 'string1',
|
|
|
|
|
pageTitle: `string1 from page ${currentPage}`,
|
|
|
|
|
height: 100,
|
|
|
|
|
width: 100,
|
|
|
|
|
host: 'string1',
|
|
|
|
|
pageUrl: 'string1'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
url: 'string1',
|
|
|
|
|
pageTitle: `string2 from page ${currentPage}`,
|
|
|
|
|
height: 100,
|
|
|
|
|
width: 100,
|
|
|
|
|
host: 'string1',
|
|
|
|
|
pageUrl: 'string1'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
url: 'string1',
|
|
|
|
|
pageTitle: `string3 from page ${currentPage}`,
|
|
|
|
|
height: 100,
|
|
|
|
|
width: 100,
|
|
|
|
|
host: 'string1',
|
|
|
|
|
pageUrl: 'string1'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
page: 0,
|
|
|
|
|
pageSize: 0,
|
|
|
|
|
totalPages: 11,
|
|
|
|
|
totalResults: 100,
|
|
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
/* return {
|
|
|
|
|
images: [],
|
|
|
|
|
page: 0,
|
|
|
|
|
pageSize: 0,
|
|
|
|
|
totalPages: 0,
|
|
|
|
|
totalResults: 0
|
|
|
|
|
} */
|
2026-02-05 21:01:19 +07:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
|
|
|
|
msg_id: 20007,
|
|
|
|
|
message_body: {
|
|
|
|
|
file_id: fileId,
|
2026-02-10 16:24:56 +07:00
|
|
|
page: currentPage,
|
2026-02-05 21:01:19 +07:00
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
|
|
|
|
|
|
|
|
|
if (parsed.message_code === 0) {
|
|
|
|
|
return parsed.message_body;
|
|
|
|
|
} else {
|
|
|
|
|
throw parsed;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2026-02-23 13:53:36 +07:00
|
|
|
throw 'error';
|
2026-02-05 21:01:19 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
2026-03-26 11:56:36 +07:00
|
|
|
let errorMessage: string = 'error';
|
|
|
|
|
if (error) {
|
|
|
|
|
const typedError = error as any;
|
|
|
|
|
switch (typedError.message_desc) {
|
|
|
|
|
case 'No results found':
|
|
|
|
|
errorMessage = 'no-similar-files-title'
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
errorMessage = 'error'
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 13:41:07 +07:00
|
|
|
return {
|
|
|
|
|
images: [],
|
|
|
|
|
page: 0,
|
|
|
|
|
pageSize: 0,
|
|
|
|
|
totalPages: 0,
|
|
|
|
|
totalResults: 0,
|
2026-03-26 11:56:36 +07:00
|
|
|
error: errorMessage
|
2026-02-23 13:41:07 +07:00
|
|
|
}
|
2026-02-05 21:01:19 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getSearchStats() {
|
|
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/check/file_stats`, {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json',
|
|
|
|
|
'Authorization': `Bearer ${token}`,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
|
|
|
|
return parsed;
|
2026-02-13 14:16:39 +07:00
|
|
|
} else {
|
|
|
|
|
return null;
|
2026-02-05 21:01:19 +07:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
2026-02-13 14:16:39 +07:00
|
|
|
return null;
|
2026-02-05 21:01:19 +07:00
|
|
|
}
|
|
|
|
|
}
|