Skip to content

Commit 3f0343b

Browse files
authored
Merge pull request #364 from qa-guru/QAGDEV-681
QAGDEV-681 - Подключение проекта к S3 v2.0
2 parents f7e31ed + edc0e02 commit 3f0343b

File tree

6 files changed

+57
-18
lines changed

6 files changed

+57
-18
lines changed

src/api/rest/homework-file-service.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
HOMEWORK_FILE_UPLOAD_URI,
66
} from "config";
77

8+
import { createUrlWithParams } from "shared/utils";
9+
810
export interface HomeworkFileResponse {
911
id: string;
1012
fileName: string;
@@ -21,11 +23,9 @@ export default class HomeworkFileService {
2123
const formData = new FormData();
2224
formData.append("file", file);
2325

24-
const uploadFileUrl = HOMEWORK_FILE_UPLOAD_URI.replace(
25-
// eslint-disable-next-line sonarjs/no-duplicate-string
26-
":homeWorkId",
27-
homeWorkId
28-
);
26+
const uploadFileUrl = createUrlWithParams(HOMEWORK_FILE_UPLOAD_URI, {
27+
homeWorkId,
28+
});
2929

3030
return axios({
3131
method: "POST",
@@ -39,10 +39,10 @@ export default class HomeworkFileService {
3939
homeWorkId: string,
4040
fileId: string
4141
): Promise<AxiosResponse<Blob>> {
42-
const getFileUrl = HOMEWORK_FILE_GET_URI.replace(
43-
":homeWorkId",
44-
homeWorkId
45-
).replace(":fileId", fileId);
42+
const getFileUrl = createUrlWithParams(HOMEWORK_FILE_GET_URI, {
43+
homeWorkId,
44+
fileId,
45+
});
4646

4747
return axios({
4848
method: "GET",
@@ -52,10 +52,9 @@ export default class HomeworkFileService {
5252
}
5353

5454
static deleteFile(homeWorkId: string): Promise<AxiosResponse<void>> {
55-
const deleteUrl = HOMEWORK_FILE_DELETE_URI.replace(
56-
":homeWorkId",
57-
homeWorkId
58-
);
55+
const deleteUrl = createUrlWithParams(HOMEWORK_FILE_DELETE_URI, {
56+
homeWorkId,
57+
});
5958

6059
return axios({
6160
method: "DELETE",

src/api/rest/training-upload-service.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import axios, { type AxiosResponse } from "axios";
22

3+
import { createUrlWithParams } from "shared/utils";
4+
35
import { TRAINING_DELETE_URI, TRAINING_UPLOAD_URI } from "../../config";
46

57
export interface TrainingUploadResponse {
@@ -15,7 +17,9 @@ export default class TrainingUploadService {
1517

1618
formData.append("file", file);
1719

18-
const uploadUrl = TRAINING_UPLOAD_URI.replace(":id", trainingId);
20+
const uploadUrl = createUrlWithParams(TRAINING_UPLOAD_URI, {
21+
id: trainingId,
22+
});
1923

2024
return axios({
2125
method: "POST",
@@ -26,7 +30,10 @@ export default class TrainingUploadService {
2630
}
2731

2832
static delete(trainingId: string): Promise<AxiosResponse<void>> {
29-
const deleteUrl = TRAINING_DELETE_URI.replace(":id", trainingId);
33+
const deleteUrl = createUrlWithParams(TRAINING_DELETE_URI, {
34+
id: trainingId,
35+
});
36+
3037
return axios({
3138
method: "DELETE",
3239
url: deleteUrl,

src/shared/components/text-editor/editor/editor.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { Box, Stack } from "@mui/material";
33
import type { EditorOptions } from "@tiptap/core";
44
import { FC, useCallback, useState } from "react";
55
import { useSnackbar } from "notistack";
6+
import { HOMEWORK_FILE_GET_URI } from "config";
67

8+
import { createUrlWithParams } from "shared/utils";
79
import { insertFiles, insertImages } from "shared/lib/mui-tiptap/utils";
810
import { LinkBubbleMenu, RichTextEditor } from "shared/lib/mui-tiptap";
911
import { TableBubbleMenu, MenuButton } from "shared/lib/mui-tiptap/controls";
@@ -36,7 +38,10 @@ const Editor: FC<ITextEditor> = ({ rteRef, content, homeWorkId }) => {
3638
const uploadedFile = await uploadHomeworkFile(file, homeWorkId);
3739

3840
if (uploadedFile) {
39-
const serverUrl = `/homework/${homeWorkId}/file/${uploadedFile.id}`;
41+
const serverUrl = createUrlWithParams(HOMEWORK_FILE_GET_URI, {
42+
homeWorkId,
43+
fileId: uploadedFile.id,
44+
});
4045

4146
return {
4247
src: serverUrl,
@@ -77,7 +82,10 @@ const Editor: FC<ITextEditor> = ({ rteRef, content, homeWorkId }) => {
7782
const uploadedFile = await uploadHomeworkFile(file, homeWorkId);
7883

7984
if (uploadedFile) {
80-
const serverUrl = `/homework/${homeWorkId}/file/${uploadedFile.id}`;
85+
const serverUrl = createUrlWithParams(HOMEWORK_FILE_GET_URI, {
86+
homeWorkId,
87+
fileId: uploadedFile.id,
88+
});
8189

8290
return {
8391
href: serverUrl,

src/shared/components/text-editor/hooks/use-extensions.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,20 @@ const CustomParagraph = Paragraph.extend({
188188
content: "inline*", // Поддержка всех inline-узлов, включая file
189189
});
190190

191+
const CustomResizableImage = ResizableImage.extend({
192+
addAttributes() {
193+
return {
194+
...this.parent?.(),
195+
width: {
196+
default: "300px",
197+
},
198+
height: {
199+
default: "auto",
200+
},
201+
};
202+
},
203+
});
204+
191205
export default function useExtensions({
192206
placeholder,
193207
}: UseExtensionsOptions = {}): EditorOptions["extensions"] {
@@ -238,7 +252,7 @@ export default function useExtensions({
238252
Highlight.configure({ multicolor: true }),
239253
HorizontalRule,
240254

241-
ResizableImage.configure({
255+
CustomResizableImage.configure({
242256
allowBase64: true,
243257
}),
244258

src/shared/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { createUrlWithParams } from "./url-utils";

src/shared/utils/url-utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const createUrlWithParams = (
2+
urlTemplate: string,
3+
params: Record<string, string | number>
4+
): string => {
5+
let url = urlTemplate;
6+
for (const [key, value] of Object.entries(params)) {
7+
url = url.replace(`:${key}`, encodeURIComponent(String(value)));
8+
}
9+
return url;
10+
};

0 commit comments

Comments
 (0)