fix(api): увеличить лимит размера тела запроса и улучшить обработку URL для API
Docker images / prepare-release (push) Successful in 6s
Docker images / backend-image (push) Successful in 1m36s
Docker images / frontend-image (push) Successful in 1m40s
Docker images / updater-image (push) Successful in 38s
Docker images / notify-webhook (push) Has been skipped
Docker images / publish-release (push) Successful in 6s
Docker images / prepare-release (push) Successful in 6s
Docker images / backend-image (push) Successful in 1m36s
Docker images / frontend-image (push) Successful in 1m40s
Docker images / updater-image (push) Successful in 38s
Docker images / notify-webhook (push) Has been skipped
Docker images / publish-release (push) Successful in 6s
This commit is contained in:
@@ -27,6 +27,7 @@ import { refreshScheduler, stopScheduler } from "./services/scheduler.js"
|
|||||||
// ── app factory ────────────────────────────────────────────────────────────────
|
// ── app factory ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
const app = Fastify({
|
const app = Fastify({
|
||||||
|
bodyLimit: 512 * 1024 * 1024,
|
||||||
logger: {
|
logger: {
|
||||||
transport: {
|
transport: {
|
||||||
target: "pino-pretty",
|
target: "pino-pretty",
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ const backendInternalUrl = (process.env.BACKEND_INTERNAL_URL ?? "http://127.0.0.
|
|||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
output: "standalone",
|
output: "standalone",
|
||||||
|
experimental: {
|
||||||
|
proxyClientMaxBodySize: "512mb",
|
||||||
|
},
|
||||||
async rewrites() {
|
async rewrites() {
|
||||||
return [
|
return [
|
||||||
{ source: "/health", destination: `${backendInternalUrl}/health` },
|
{ source: "/health", destination: `${backendInternalUrl}/health` },
|
||||||
|
|||||||
@@ -1,9 +1,19 @@
|
|||||||
import { ApiClientError } from "@/shared/api/http-client"
|
import { ApiClientError } from "@/shared/api/http-client"
|
||||||
|
import { configuredBackendUrl } from "@/lib/backend-url"
|
||||||
|
|
||||||
|
const MAX_RESTORE_BYTES = 512 * 1024 * 1024
|
||||||
|
|
||||||
function trimBaseUrl(baseUrl: string): string {
|
function trimBaseUrl(baseUrl: string): string {
|
||||||
return baseUrl.replace(/\/$/, "")
|
return baseUrl.replace(/\/$/, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveDatabaseApiUrl(baseUrl: string, path: string): string {
|
||||||
|
if (configuredBackendUrl().kind === "same-origin") {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
return `${trimBaseUrl(baseUrl)}${path}`
|
||||||
|
}
|
||||||
|
|
||||||
function parseFilename(contentDisposition: string | null, fallback: string): string {
|
function parseFilename(contentDisposition: string | null, fallback: string): string {
|
||||||
if (!contentDisposition) return fallback
|
if (!contentDisposition) return fallback
|
||||||
const utfMatch = /filename\*=UTF-8''([^;]+)/i.exec(contentDisposition)
|
const utfMatch = /filename\*=UTF-8''([^;]+)/i.exec(contentDisposition)
|
||||||
@@ -22,7 +32,7 @@ function parseFilename(contentDisposition: string | null, fallback: string): str
|
|||||||
export async function downloadSystemDatabaseBackup(
|
export async function downloadSystemDatabaseBackup(
|
||||||
baseUrl: string,
|
baseUrl: string,
|
||||||
): Promise<{ blob: Blob; filename: string }> {
|
): Promise<{ blob: Blob; filename: string }> {
|
||||||
const res = await fetch(`${trimBaseUrl(baseUrl)}/api/system/database/backup`)
|
const res = await fetch(resolveDatabaseApiUrl(baseUrl, "/api/system/database/backup"))
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const payload = await res.json().catch(() => undefined)
|
const payload = await res.json().catch(() => undefined)
|
||||||
const msg =
|
const msg =
|
||||||
@@ -40,8 +50,14 @@ export async function downloadSystemDatabaseBackup(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function restoreSystemDatabaseBackup(baseUrl: string, file: File): Promise<void> {
|
export async function restoreSystemDatabaseBackup(baseUrl: string, file: File): Promise<void> {
|
||||||
|
if (file.size > MAX_RESTORE_BYTES) {
|
||||||
|
throw new ApiClientError(
|
||||||
|
`Файл больше ${MAX_RESTORE_BYTES / (1024 * 1024)} МБ — уменьшите бэкап или обратитесь к администратору`,
|
||||||
|
413,
|
||||||
|
)
|
||||||
|
}
|
||||||
const body = await file.arrayBuffer()
|
const body = await file.arrayBuffer()
|
||||||
const res = await fetch(`${trimBaseUrl(baseUrl)}/api/system/database/restore`, {
|
const res = await fetch(resolveDatabaseApiUrl(baseUrl, "/api/system/database/restore"), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/octet-stream" },
|
headers: { "Content-Type": "application/octet-stream" },
|
||||||
body,
|
body,
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user