跳到主要内容

文档说明

判断文档是否存在

async function openPageOrRedirect (url, backupUrl) {
try {
await axios.head(url)
// 如果HEAD请求成功,说明页面存在
window.open(url, '_blank')
} catch (error) {
// 如果HEAD请求失败,说明页面不存在,打开备用页面
window.open(backupUrl, '_blank')
}
}

新建gitlab文件

async function createFileInGitLab (projectId, filePath, branch, content, commitMessage) {
const url = `http://192.168.50.67:32573/api/v4/projects/${encodeURIComponent(projectId)}/repository/files/${encodeURIComponent(filePath)}`

const data = {
branch,
content,
commit_message: commitMessage,
}

const headers = {
'PRIVATE-TOKEN': '1',
}

try {
await axios.post(url, data, { headers })
console.log('File created successfully')
} catch (error) {
console.error('Failed to create file', error)
}
}