Skip to content

Commit

Permalink
fix: get record
Browse files Browse the repository at this point in the history
  • Loading branch information
guz86 committed Sep 24, 2024
1 parent ae8af6e commit 7478199
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 35 deletions.
12 changes: 7 additions & 5 deletions app/src/components/AudioRow/AudioRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@ import { getCallRecord } from '../../utils/apiGetRecord';
interface AudioRowProps {
length: string;
isHovered: boolean;
recordId: number;
partnershipId: string;
record: string;
partnership_id: string;
}

const AudioRow: React.FC<AudioRowProps> = ({
length,
isHovered,
recordId,
partnershipId,
record,
partnership_id,
}) => {
if (!length) {
return null;
}

const handlePlay = async () => {
try {
const audioUrl = await getCallRecord({ recordId, partnershipId });
const audioUrl = await getCallRecord({ record, partnership_id });
console.log(audioUrl);
const newAudio = new Audio(audioUrl);

newAudio.play();
} catch (error) {
console.error('Ошибка при воспроизведении записи:', error);
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ interface TableRowData {
source: string;
score: string;
length: string;
id: number;
partnershipId: string;
record: string;
partnership_id: string;
}

interface TableProps {
Expand Down
12 changes: 6 additions & 6 deletions app/src/components/TableRow/TableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ interface TableRowProps {
source: string;
score: string;
length: string;
id: number;
partnershipId: string;
record: string;
partnership_id: string;
}

const TableRow: React.FC<TableRowProps> = ({
Expand All @@ -22,8 +22,8 @@ const TableRow: React.FC<TableRowProps> = ({
source,
score,
length,
id,
partnershipId,
record,
partnership_id,
}) => {
const [isHovered, setIsHovered] = useState(false);

Expand All @@ -49,8 +49,8 @@ const TableRow: React.FC<TableRowProps> = ({
<AudioRow
length={length}
isHovered={isHovered}
recordId={id}
partnershipId={partnershipId}
record={record}
partnership_id={partnership_id}
/>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import axios, { AxiosError } from 'axios';

export interface Call {
id: number;
partnershipId: string;
record: string;
partnership_id: string;
date: string;
time: number;
from_number: string;
Expand Down
46 changes: 27 additions & 19 deletions app/src/utils/apiGetRecord.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
import axios from 'axios';
import axios, { AxiosError } from 'axios';

const BASE_URL = 'https://api.skilla.ru/mango/getRecord';
const token = 'testtoken';

interface GetCallRecordParams {
recordId: number;
partnershipId: string;
record: string;
partnership_id: string;
}

interface ApiError {
description: string;
}

export const getCallRecord = async ({
recordId,
partnershipId,
record,
partnership_id,
}: GetCallRecordParams): Promise<string> => {
const requestBody = {
record: recordId,
partnership_id: partnershipId,
};

try {
const response = await axios.post(BASE_URL, requestBody, {
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
responseType: 'blob',
});
const url = `${BASE_URL}?record=${encodeURIComponent(record)}&partnership_id=${encodeURIComponent(partnership_id)}`;

const response = await axios.post<Blob>(
url,
{},
{
headers: {
Authorization: `Bearer ${token}`,
},
responseType: 'blob',
}
);

const audioUrl = URL.createObjectURL(response.data);
return audioUrl;
} catch (error) {
} catch (err) {
const error = err as AxiosError<ApiError>;
console.error('Ошибка при получении записи звонка:', error);
throw error;
const errorMessage = error.response?.data
? error.response.data.description
: 'Ошибка сети';
throw new Error(errorMessage);
}
};
4 changes: 2 additions & 2 deletions app/src/utils/formatCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const formatCalls = (calls: Call[]) => {
source: call.source || '',
score: 'Отлично',
length: callLength,
id: call.id,
partnershipId: call.partnershipId,
record: call.record,
partnership_id: call.partnership_id,
};
});
};

0 comments on commit 7478199

Please sign in to comment.