getProjectInfo.get.ts 1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
import { TableV1, TableV2 } from "~/server/utils/postgres"

export default defineEventHandler(async (event) => {
  let username = event.context.username
  let docker = createDockerFactory(username)
  const row = await getPgTableData( 'v1', username)
  const info: Partial<TableV1> & { branch: string } = { ...row, branch: '' }
  info.status = row?.status || 'null'
  try {
    let container = await docker.checkContainer(username + '.node')
    if (container) {
      await docker.startContainer({ container })
      let result = await docker.execContainerCommand({ container, cmd: 'git branch', dir: getPlatformRootFolder('v1') })
      const arrays = result.split('\n')
      let currentBranch = arrays.find(o => o.includes('*'))
      currentBranch = currentBranch?.replace(/^.*?\*/, '').trim() || ''
      info.branch = removeUnreadCharacter(currentBranch)
    } else {
      info.branch = '无'
    }
  } catch (err) {
    // 出现任何错误都认为没有未初始化分支
    info.branch = '无'
  }
  return info
})