mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
improvement(api): deprecated /db from /api and moved all routes to their relevant domain location. updated all references to old routes (#191)
This commit is contained in:
@@ -25,6 +25,7 @@ const QueryParamsSchema = z.object({
|
||||
endDate: z.string().optional(),
|
||||
})
|
||||
|
||||
// Used to retrieve and display workflow logs
|
||||
export async function GET(request: NextRequest) {
|
||||
const requestId = crypto.randomUUID().slice(0, 8)
|
||||
|
||||
+15
-21
@@ -3,9 +3,9 @@ import { eq } from 'drizzle-orm'
|
||||
import { z } from 'zod'
|
||||
import { getSession } from '@/lib/auth'
|
||||
import { createLogger } from '@/lib/logs/console-logger'
|
||||
import { Variable } from '@/stores/panel/variables/types'
|
||||
import { db } from '@/db'
|
||||
import { workflow } from '@/db/schema'
|
||||
import { Variable } from '@/stores/panel/variables/types'
|
||||
|
||||
const logger = createLogger('WorkflowVariablesAPI')
|
||||
|
||||
@@ -22,10 +22,7 @@ const VariablesSchema = z.object({
|
||||
),
|
||||
})
|
||||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
export async function POST(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
const requestId = crypto.randomUUID().slice(0, 8)
|
||||
const workflowId = (await params).id
|
||||
|
||||
@@ -90,17 +87,11 @@ export async function POST(
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`[${requestId}] Error updating workflow variables`, error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to update workflow variables' },
|
||||
{ status: 500 }
|
||||
)
|
||||
return NextResponse.json({ error: 'Failed to update workflow variables' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
export async function GET(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
const requestId = crypto.randomUUID().slice(0, 8)
|
||||
const workflowId = (await params).id
|
||||
|
||||
@@ -132,20 +123,23 @@ export async function GET(
|
||||
}
|
||||
|
||||
// Return variables if they exist
|
||||
const variables = workflowRecord[0].variables as Record<string, Variable> || {}
|
||||
|
||||
const variables = (workflowRecord[0].variables as Record<string, Variable>) || {}
|
||||
|
||||
// Add cache headers to prevent frequent reloading
|
||||
const headers = new Headers({
|
||||
'Cache-Control': 'max-age=60, stale-while-revalidate=300', // Cache for 1 minute, stale for 5
|
||||
'ETag': `"${requestId}-${Object.keys(variables).length}"`,
|
||||
ETag: `"${requestId}-${Object.keys(variables).length}"`,
|
||||
})
|
||||
|
||||
return NextResponse.json({ data: variables }, {
|
||||
status: 200,
|
||||
headers,
|
||||
})
|
||||
return NextResponse.json(
|
||||
{ data: variables },
|
||||
{
|
||||
status: 200,
|
||||
headers,
|
||||
}
|
||||
)
|
||||
} catch (error: any) {
|
||||
logger.error(`[${requestId}] Workflow variables fetch error`, error)
|
||||
return NextResponse.json({ error: error.message }, { status: 500 })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ export function ControlBar() {
|
||||
const fetchLogs = async () => {
|
||||
try {
|
||||
// Include workflow data in the response
|
||||
const response = await fetch('/api/db/workflow-logs?includeWorkflow=true')
|
||||
const response = await fetch('/api/logs?includeWorkflow=true')
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error fetching logs: ${response.statusText}`)
|
||||
|
||||
@@ -132,7 +132,7 @@ export default function Logs() {
|
||||
try {
|
||||
setLoading(true)
|
||||
// Include workflow data in the response
|
||||
const response = await fetch('/api/db/workflow-logs?includeWorkflow=true')
|
||||
const response = await fetch('/api/logs?includeWorkflow=true')
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error fetching logs: ${response.statusText}`)
|
||||
|
||||
@@ -5,10 +5,11 @@ export const STORAGE_KEYS = {
|
||||
}
|
||||
|
||||
export const API_ENDPOINTS = {
|
||||
WORKFLOW: '/api/db/workflow',
|
||||
ENVIRONMENT: '/api/db/environment',
|
||||
WORKFLOW: '/api/workflows/sync',
|
||||
ENVIRONMENT: '/api/environment',
|
||||
SCHEDULE: '/api/schedules/schedule',
|
||||
WORKFLOW_VARIABLES: '/api/db/workflow/variables',
|
||||
SETTINGS: '/api/settings',
|
||||
WORKFLOW_VARIABLES: '/api/workflows/[id]/variables',
|
||||
}
|
||||
|
||||
export const SYNC_INTERVALS = {
|
||||
|
||||
Reference in New Issue
Block a user