|
| 1 | +/* |
| 2 | + * Copyright Contributors to the OpenCue Project |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { fetchObjectFromRestGateway } from '@/app/utils/api_utils'; |
| 18 | +import { NextRequest, NextResponse } from "next/server"; |
| 19 | + |
| 20 | +// Mirrors cuegui.JobActions.viewDepends -> DependDialog |
| 21 | +// (cuegui/cuegui/MenuActions.py, cuegui/cuegui/DependDialog.py). Returns |
| 22 | +// the depend.DependSeq for the job so the View Dependencies dialog can |
| 23 | +// render the Type / Target / Active / OnJob / OnLayer / OnFrame table. |
| 24 | +export async function POST(request: NextRequest) { |
| 25 | + const endpoint = "/job.JobInterface/GetDepends"; |
| 26 | + const method = request.method; |
| 27 | + if (method !== 'POST') { |
| 28 | + return NextResponse.json({ error: 'Invalid method. Only POST is allowed.' }, { status: 405 }); |
| 29 | + } |
| 30 | + |
| 31 | + let jsonBody: any; |
| 32 | + try { |
| 33 | + jsonBody = await request.json(); |
| 34 | + } catch { |
| 35 | + return NextResponse.json({ error: 'Invalid JSON body' }, { status: 400 }); |
| 36 | + } |
| 37 | + if (!jsonBody || typeof jsonBody !== 'object' || Array.isArray(jsonBody) || !jsonBody.job) { |
| 38 | + return NextResponse.json({ error: 'Invalid request body (need {job})' }, { status: 400 }); |
| 39 | + } |
| 40 | + |
| 41 | + const response = await fetchObjectFromRestGateway(endpoint, method, JSON.stringify(jsonBody)); |
| 42 | + const responseData = await response.json(); |
| 43 | + |
| 44 | + if (!response.ok) { |
| 45 | + return NextResponse.json( |
| 46 | + { error: responseData?.error ?? 'Upstream error' }, |
| 47 | + { status: response.status }, |
| 48 | + ); |
| 49 | + } |
| 50 | + return NextResponse.json({ data: responseData.data }, { status: response.status }); |
| 51 | +} |
0 commit comments