add pice check for file upload

This commit is contained in:
smanylov
2026-03-04 19:21:44 +07:00
parent 0351c561b5
commit 640f167e4b
4 changed files with 106 additions and 18 deletions
+46 -1
View File
@@ -12,7 +12,7 @@ interface initMessageBody {
file_size: number | string,
action?: string,
token?: string,
convertTo? : string | undefined | null
convertTo?: string | undefined | null
}
export async function fileUpload(messageBody: initMessageBody, convertTo?: string | null | undefined) {
@@ -228,4 +228,49 @@ export async function getAllowedFilesExtensions(type: string) {
} catch (error) {
return error
}
}
export async function checkOperationPrice(action: string, filesCount: number, fileType: string) {
const token = await getSessionData('token');
try {
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
method: 'POST',
body: JSON.stringify({
version: 1,
msg_id: 30008,
message_body: {
auth_token: token,
action: action,
file_type: fileType,
count_files: filesCount
}
}),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});
if (response.ok) {
let parsed = await response.json();
console.log(parsed);
if (parsed.message_code === 0) {
return parsed.message_body;
} else {
throw parsed;
}
} else {
throw (`${response.status}`);
}
} catch (error) {
return {
cost: 0,
success: false,
tokens_count: 0,
error: 'error'
}
}
}