chore: something changed, commit before reorg

This commit is contained in:
Daniil
2026-04-27 23:28:28 +03:00
parent 46f34bdcac
commit 20928e9a60
16 changed files with 1967 additions and 1262 deletions
+11 -57
View File
@@ -32,7 +32,7 @@ import {
import cs from "classnames"
import api, { fetchClient } from "@shared/api"
import api from "@shared/api"
import { useWizard } from "@shared/context/WizardContext"
import { useTaskProgressState } from "@shared/hooks/useTaskProgressState"
import { Badge, Button, CircularProgress } from "@shared/ui"
@@ -55,19 +55,16 @@ export const VerifyStep: FunctionComponent<IVerifyStepProps> = ({
className,
}): JSX.Element => {
const {
projectId,
primaryFileKey,
videoUrl,
originalFileName,
activeJobId,
activeJobType,
goBack,
goNext,
goToStep,
markStepCompleted,
confirmVerify,
setFileKey,
setActiveJob,
startProcessingJob,
startMediaConvert,
} = useWizard()
const [convertError, setConvertError] = useState<string | null>(null)
@@ -113,27 +110,11 @@ export const VerifyStep: FunctionComponent<IVerifyStepProps> = ({
/* ---- Conversion logic ---- */
const convertMutation = api.useMutation("post", "/api/tasks/media-convert/", {
onSuccess: (data) => {
startProcessingJob(data.job_id, "MEDIA_CONVERT", "verify")
setConvertError(null)
},
onError: () => {
setConvertError(ERROR_CONVERT_FAILED)
},
})
const handleConvert = useCallback(() => {
if (!primaryFileKey) return
convertMutation.mutate({
body: {
file_key: primaryFileKey,
out_folder: `projects/${projectId}`,
output_format: "mp4",
project_id: projectId,
},
void startMediaConvert().catch(() => {
setConvertError(ERROR_CONVERT_FAILED)
})
}, [convertMutation, primaryFileKey, projectId])
}, [startMediaConvert])
const {
progressPct: convertProgressPct,
@@ -149,47 +130,20 @@ export const VerifyStep: FunctionComponent<IVerifyStepProps> = ({
useEffect(() => {
if (!convertJobId || convertStatus !== "converting") return
if (convertTaskStatus === "DONE") {
fetchConvertedFileFromJob(convertJobId)
}
if (convertTaskStatus === "FAILED") {
setActiveJob(null)
setConvertError(convertErrorMessage ?? "Ошибка конвертации")
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [convertErrorMessage, convertJobId, convertStatus, convertTaskStatus])
const fetchConvertedFileFromJob = useCallback(
async (jobId: string) => {
const { data: taskStatus } = await fetchClient.GET(
"/api/tasks/status/{job_id}/",
{ params: { path: { job_id: jobId } } },
)
const outputData = taskStatus?.output_data as {
file_id?: string
file_path?: string
} | null
if (outputData?.file_id && outputData?.file_path) {
const convertedName = outputData.file_path.split("/").pop() ?? null
setFileKey(outputData.file_path, outputData.file_id, convertedName)
setActiveJob(null)
}
},
[setFileKey, setActiveJob],
)
}, [convertErrorMessage, convertJobId, convertStatus, convertTaskStatus, setActiveJob])
/* ---- Handlers ---- */
const handleReplace = () => {
setFileKey(null, null, null)
goToStep("upload")
void setFileKey(null, null, null)
}
const handleNext = () => {
markStepCompleted("verify")
goNext()
void confirmVerify()
}
/* ---- Converting view ---- */
@@ -266,7 +220,7 @@ export const VerifyStep: FunctionComponent<IVerifyStepProps> = ({
variant="primary"
size="sm"
onClick={handleConvert}
disabled={convertMutation.isPending}
disabled={!primaryFileKey}
>
Конвертировать в MP4
</Button>
@@ -357,7 +311,7 @@ export const VerifyStep: FunctionComponent<IVerifyStepProps> = ({
variant="primary"
size="sm"
onClick={handleConvert}
disabled={convertMutation.isPending}
disabled={!primaryFileKey}
>
Конвертировать в MP4
</Button>