在1.0中创建函数,并把以下内容复制过去,填写其中appid和token运行即可将函数迁移到1.0
import cloud from '@lafjs/cloud'
export async function main(ctx: FunctionContext) {
const oldAppID = '' // 0.8 app id
const oldToken = '' // 0.8 token,复制header里面的authorization值
const newAppID = '' 1.0 app id
const newToken = '' // 1.0 token,复制header里面的authorization值
const res = await cloud.fetch.get(`https://console.lafyun.com/sys-api/apps/${oldAppID}/function?status=1&page=1&limit=10000`, {
headers: {
'authorization': oldToken,
}
})
const createFuncDtoList = []
for(let func of res.data.data) {
createFuncDtoList.push({
name: func.name,
code: func.code.replace(`@/cloud-sdk`, '@lafjs/cloud'),
description: func.description,
methods: ["GET", "POST", "DELETE", "PUT"],
tags: func.tags,
websocket: false
})
}
for (let createDto of createFuncDtoList) {
const createRes = await cloud.fetch.post(`https://laf.dev/v1/apps/${newAppID}/functions`, createDto, {
headers: {
'authorization': newToken,
}
})
if (createRes.data.error) {
console.log(`function ${createDto.name} migrate failed: ${createRes.data.error}`)
} else {
console.log(`function ${createDto.name} migrate success`)
}
}
}