chore: prepare v1.0.0 release
This commit is contained in:
@@ -5,6 +5,7 @@ import { classifyFileChanges } from '@/lib/diff-files'
|
||||
import { getModelFolderPath } from '@/lib/model-paths'
|
||||
import { ensurePreparedStagingAssets } from '@/lib/upload-staging'
|
||||
import { parseStagingRequestBody } from '@/lib/upload-request'
|
||||
import { getErrorMessage } from '@/lib/guards'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
export const dynamic = 'force-dynamic'
|
||||
@@ -23,7 +24,7 @@ export async function POST(req: NextRequest) {
|
||||
const body: unknown = await req.json()
|
||||
stagingId = parseStagingRequestBody(body).stagingId
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Erreur inconnue'
|
||||
const message = getErrorMessage(err)
|
||||
return NextResponse.json({ success: false, error: message }, { status: 400 })
|
||||
}
|
||||
|
||||
@@ -56,7 +57,7 @@ export async function POST(req: NextRequest) {
|
||||
|
||||
return NextResponse.json({ success: true, exists: false })
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Erreur inconnue'
|
||||
const message = getErrorMessage(err)
|
||||
return NextResponse.json({ success: false, error: message }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,33 +9,15 @@ import {
|
||||
} from '@/lib/nextcloud'
|
||||
import { acquireUploadLock, releaseUploadLock } from '@/lib/upload-lock'
|
||||
import { parseDriveRequestBody } from '@/lib/upload-request'
|
||||
import { getErrorMessage } from '@/lib/guards'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// POST /api/upload/drive
|
||||
//
|
||||
// Upload **original** files to Nextcloud Drive.
|
||||
//
|
||||
// JSON body:
|
||||
// - stagingId
|
||||
// - action: "new" | "replace"
|
||||
//
|
||||
// Versioning logic:
|
||||
// VF/{folderName} <- latest version
|
||||
// V1/{folderName} <- first archive, V2/ second, etc.
|
||||
//
|
||||
// action="new" -> just mkdir + upload into VF/
|
||||
// action="replace" -> archive VF -> Vx, then re-upload all files into VF/
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
// --- Auth ---
|
||||
const authError = validateUploadSecret(req)
|
||||
if (authError) return authError
|
||||
|
||||
// --- Check Nextcloud config ---
|
||||
if (!process.env.NEXTCLOUD_URL || !process.env.NEXTCLOUD_SHARE_TOKEN) {
|
||||
return NextResponse.json(
|
||||
{ success: false, error: 'Nextcloud non configure sur le serveur (NEXTCLOUD_URL, NEXTCLOUD_SHARE_TOKEN)' },
|
||||
@@ -43,7 +25,6 @@ export async function POST(req: NextRequest) {
|
||||
)
|
||||
}
|
||||
|
||||
// --- Parse staging request ---
|
||||
let folderName: string
|
||||
let parsedFiles: Awaited<ReturnType<typeof readStagedOriginalFiles>>['files']
|
||||
let action: 'new' | 'replace'
|
||||
@@ -57,7 +38,7 @@ export async function POST(req: NextRequest) {
|
||||
folderName = staged.folderName
|
||||
parsedFiles = staged.files
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Erreur inconnue'
|
||||
const message = getErrorMessage(err)
|
||||
return NextResponse.json({ success: false, error: message }, { status: 400 })
|
||||
}
|
||||
|
||||
@@ -73,23 +54,17 @@ export async function POST(req: NextRequest) {
|
||||
|
||||
try {
|
||||
if (action === 'replace') {
|
||||
// 1. Find the next available Vx
|
||||
const nextVersion = await findNextVersion(basePath, folderName)
|
||||
|
||||
// 2. Ensure Vx/ exists
|
||||
await mkdirRecursive(`${basePath}/${nextVersion}`)
|
||||
|
||||
// 3. Move VF/{folderName} -> Vx/{folderName}
|
||||
await moveFolder(vfFolderPath, `${basePath}/${nextVersion}/${folderName}`)
|
||||
|
||||
// 4. Re-create VF/{folderName}
|
||||
await mkdirRecursive(vfFolderPath)
|
||||
} else {
|
||||
// action === 'new': just ensure VF/{folderName} exists
|
||||
await mkdirRecursive(vfFolderPath)
|
||||
}
|
||||
|
||||
// --- Upload all original files ---
|
||||
for (const pf of parsedFiles) {
|
||||
const remotePath = `${vfFolderPath}/${pf.filename}`
|
||||
await uploadFile(remotePath, pf.buffer)
|
||||
@@ -102,7 +77,7 @@ export async function POST(req: NextRequest) {
|
||||
message: `${parsedFiles.length} fichier(s) envoye(s) sur le Drive.`,
|
||||
})
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Erreur Nextcloud inconnue'
|
||||
const message = getErrorMessage(err, 'Erreur Nextcloud inconnue')
|
||||
return NextResponse.json(
|
||||
{ success: false, error: `Drive echoue: ${message}` },
|
||||
{ status: 500 },
|
||||
|
||||
@@ -7,6 +7,7 @@ import { getModelFolderPath } from '@/lib/model-paths'
|
||||
import { cleanupStagingUpload, ensurePreparedStagingAssets, readStagedManifest } from '@/lib/upload-staging'
|
||||
import { acquireUploadLock, releaseUploadLock } from '@/lib/upload-lock'
|
||||
import { parseStagingRequestBody } from '@/lib/upload-request'
|
||||
import { getErrorMessage } from '@/lib/guards'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
export const dynamic = 'force-dynamic'
|
||||
@@ -16,7 +17,6 @@ export const dynamic = 'force-dynamic'
|
||||
* Upload prepared files and push to GitHub via Octokit.
|
||||
*/
|
||||
export async function POST(req: NextRequest) {
|
||||
// --- Auth ---
|
||||
const authError = validateUploadSecret(req)
|
||||
if (authError) return authError
|
||||
|
||||
@@ -29,7 +29,7 @@ export async function POST(req: NextRequest) {
|
||||
const manifest = await readStagedManifest(stagingId)
|
||||
folderName = manifest.folderName
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Erreur inconnue'
|
||||
const message = getErrorMessage(err)
|
||||
return NextResponse.json({ success: false, error: message }, { status: 400 })
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ export async function POST(req: NextRequest) {
|
||||
}
|
||||
|
||||
try {
|
||||
// --- Process files (preserve model + buffers, compress textures for Git) ---
|
||||
const {
|
||||
filesToPush,
|
||||
modelFilename,
|
||||
@@ -50,7 +49,6 @@ export async function POST(req: NextRequest) {
|
||||
assetSummaries,
|
||||
} = await ensurePreparedStagingAssets(stagingId)
|
||||
|
||||
// --- Detect existing files and classify changes ---
|
||||
const folderPath = getModelFolderPath(folderName)
|
||||
const remote = await getRemoteFolder(folderPath)
|
||||
const remoteFileMap = new Map(remote.files.map((f) => [f.name.toLowerCase(), f.size]))
|
||||
@@ -60,7 +58,6 @@ export async function POST(req: NextRequest) {
|
||||
const { fileChanges, changedFilesToPush, deletedFileNames, deletePaths } =
|
||||
classifyFileChanges(filesToPush, remoteFileMap, folderPath)
|
||||
|
||||
// If nothing changed, don't create an empty commit
|
||||
if (changedFilesToPush.length === 0 && deletePaths.length === 0) {
|
||||
await cleanupStagingUpload(stagingId).catch(() => {})
|
||||
return NextResponse.json({
|
||||
@@ -73,7 +70,6 @@ export async function POST(req: NextRequest) {
|
||||
})
|
||||
}
|
||||
|
||||
// --- Build commit message ---
|
||||
const commitMessage = buildCommitMessage(
|
||||
folderName,
|
||||
modelFilename,
|
||||
@@ -83,7 +79,6 @@ export async function POST(req: NextRequest) {
|
||||
deletedFileNames,
|
||||
)
|
||||
|
||||
// --- Push all in one commit ---
|
||||
try {
|
||||
const { commitUrl } = await pushAllToGitHub(changedFilesToPush, deletePaths, commitMessage)
|
||||
await cleanupStagingUpload(stagingId).catch(() => {})
|
||||
@@ -98,7 +93,7 @@ export async function POST(req: NextRequest) {
|
||||
commitUrl,
|
||||
})
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Erreur GitHub inconnue'
|
||||
const message = getErrorMessage(err, 'Erreur GitHub inconnue')
|
||||
return NextResponse.json(
|
||||
{ success: false, error: `Push GitHub echoue: ${message}` },
|
||||
{ status: 500 },
|
||||
|
||||
@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from 'next/server'
|
||||
import { validateUploadSecret } from '@/lib/auth'
|
||||
import { parseMultiUpload } from '@/lib/parse-upload'
|
||||
import { createStagingUpload } from '@/lib/upload-staging'
|
||||
import { getErrorMessage } from '@/lib/guards'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
export const dynamic = 'force-dynamic'
|
||||
@@ -15,7 +16,7 @@ export async function POST(req: NextRequest) {
|
||||
const staged = await createStagingUpload(parsed.folderName, parsed.files)
|
||||
return NextResponse.json({ success: true, ...staged })
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Erreur inconnue'
|
||||
const message = getErrorMessage(err)
|
||||
return NextResponse.json({ success: false, error: message }, { status: 400 })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user