Preview: Dev-Modus nur mit dev-Skript waehlbar
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a5cb668853
commit
04b45e4207
5 files changed
+159
-7
No files matched your search
@@ -9,12 +9,14 @@ import * as runnerClient from '../../services/previewRunnerClient.js'
|
||||
import { runDeploy, fetchPreviewConfig } from '../../services/previewDeploy.js'
|
||||
import { withLocks } from '../../services/keyedLock.js'
|
||||
import { getRepoInfo } from '../../services/giteaAdmin.js'
|
||||
import { repoHasDevScript } from '../../services/previewDevScript.js'
|
||||
|
||||
const router = Router()
|
||||
router.use(requireAppwriteStaff)
|
||||
|
||||
const BUSY = 'Server ausgelastet, versuche es gleich noch mal'
|
||||
const MODES = ['auto', 'build', 'dev', 'off']
|
||||
const NO_DEV = 'Dieses Projekt hat kein dev-Skript. Reines HTML braucht keinen Dev-Server – Änderungen erscheinen nach jedem Push automatisch.'
|
||||
const SHA_RE = /^[0-9a-f]{7,40}$/
|
||||
|
||||
function fail(status, message) {
|
||||
@@ -62,10 +64,14 @@ async function view(doc) {
|
||||
}
|
||||
}
|
||||
|
||||
async function previewBranchOf(doc) {
|
||||
return doc.previewBranch || (await getRepoInfo(doc.repoFullName).catch(() => null))?.defaultBranch || 'main'
|
||||
}
|
||||
|
||||
// Neubau anstossen (wie beim Bearbeiten/Reaktivieren eines Projekts)
|
||||
async function triggerRebuild(doc) {
|
||||
const repo = doc.repoFullName
|
||||
const branch = doc.previewBranch || (await getRepoInfo(repo).catch(() => null))?.defaultBranch || 'main'
|
||||
const branch = await previewBranchOf(doc)
|
||||
const found = await fetchPreviewConfig(repo, branch).catch(() => null)
|
||||
const cfg = {
|
||||
enabled: true,
|
||||
@@ -93,7 +99,11 @@ const wrap = (fn) => async (req, res) => {
|
||||
}
|
||||
|
||||
router.get('/:id/preview', wrap(async (req, res) => {
|
||||
res.json(await view(await loadProject(req.params.id)))
|
||||
const doc = await loadProject(req.params.id)
|
||||
const devAvailable = doc.repoFullName
|
||||
? await repoHasDevScript(doc.repoFullName, await previewBranchOf(doc)).catch(() => null)
|
||||
: null
|
||||
res.json({ ...(await view(doc)), devAvailable })
|
||||
}))
|
||||
|
||||
router.patch('/:id/preview', wrap(async (req, res) => {
|
||||
@@ -110,6 +120,10 @@ router.patch('/:id/preview', wrap(async (req, res) => {
|
||||
}
|
||||
return res.json(await view(await getDocument(col(), doc.$id)))
|
||||
}
|
||||
if (mode === 'dev' && doc.repoFullName) {
|
||||
const has = await repoHasDevScript(doc.repoFullName, await previewBranchOf(doc)).catch(() => null)
|
||||
if (has === false) throw fail(400, NO_DEV)
|
||||
}
|
||||
const updated = await updateDocument(col(), doc.$id, { previewMode: mode })
|
||||
await triggerRebuild(updated)
|
||||
res.json(await view(await getDocument(col(), doc.$id)))
|
||||
|
||||
Reference in new issue
Block a user