add pice check for file upload
This commit is contained in:
@@ -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'
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user