Skip to content

Commit

Permalink
fix(web): fix function template's indentation (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk authored May 29, 2023
1 parent 12f48c4 commit 6e79d26
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 73 deletions.
6 changes: 3 additions & 3 deletions web/public/locales/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,12 @@
"contact": "联系我们",
"forum": "开发者社区",
"faq": "FAQ",
"start": "立即体验",
"start": "立即开发",
"stars": "3.9K"
},
"HomePage": {
"slogan": "像写博客一样写代码",
"start": "立即体验",
"start": "立即开发",
"content1": "Laf 是一个集函数、数据库、存储为一体的云开发平台",
"content2": "随时随地,发布上线"
},
Expand Down Expand Up @@ -423,4 +423,4 @@
"LinkCopied": "链接复制成功",
"create success": "创建成功",
"ServerStatus": "服务状态"
}
}
6 changes: 3 additions & 3 deletions web/public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,12 @@
"contact": "联系我们",
"forum": "开发者社区",
"faq": "FAQ",
"start": "立即体验",
"start": "立即开发",
"stars": "3.9K"
},
"HomePage": {
"slogan": "像写博客一样写代码",
"start": "立即体验",
"start": "立即开发",
"content1": "Laf 是一个集函数、数据库、存储为一体的云开发平台",
"content2": "随时随地,发布上线"
},
Expand Down Expand Up @@ -423,4 +423,4 @@
"LinkCopied": "链接复制成功",
"create success": "创建成功",
"ServerStatus": "服务状态"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,83 +15,83 @@ export default async function (ctx: FunctionContext) {
label: t("database example"),
value: `import cloud from '@lafjs/cloud'
export default async function (ctx: FunctionContext) {
const db = cloud.database()
// insert data
await db.collection('test').add({ name: "hello laf" })
// get data
const res = await db.collection('test').getOne()
console.log(res)
return res.data
}
export default async function (ctx: FunctionContext) {
const db = cloud.database()
// insert data
await db.collection('test').add({ name: "hello laf" })
// get data
const res = await db.collection('test').getOne()
console.log(res)
return res.data
}
`,
},
{
label: t("upload example"),
value: `import cloud from '@lafjs/cloud'
import { S3 } from "@aws-sdk/client-s3"
export default async function (ctx: FunctionContext) {
// Create your bucket first
const BUCKET = "kcqcau-test"
const client = new S3({
region: cloud.env.OSS_REGION,
endpoint: cloud.env.OSS_EXTERNAL_ENDPOINT,
credentials: {
accessKeyId: cloud.env.OSS_ACCESS_KEY,
secretAccessKey: cloud.env.OSS_ACCESS_SECRET,
},
forcePathStyle: true,
})
const file = ctx.files[0]
console.log(file)
const stream = require('fs').createReadStream(file.path)
const res = await client.putObject({
Bucket: BUCKET,
Key: ctx.files[0].filename,
Body: stream,
ContentType: file.mimetype,
})
console.log(res)
return res
}
import { S3 } from "@aws-sdk/client-s3"
export default async function (ctx: FunctionContext) {
// Create your bucket first
const BUCKET = "kcqcau-test"
const client = new S3({
region: cloud.env.OSS_REGION,
endpoint: cloud.env.OSS_EXTERNAL_ENDPOINT,
credentials: {
accessKeyId: cloud.env.OSS_ACCESS_KEY,
secretAccessKey: cloud.env.OSS_ACCESS_SECRET,
},
forcePathStyle: true,
})
const file = ctx.files[0]
console.log(file)
const stream = require('fs').createReadStream(file.path)
const res = await client.putObject({
Bucket: BUCKET,
Key: ctx.files[0].filename,
Body: stream,
ContentType: file.mimetype,
})
console.log(res)
return res
}
`,
},
{
label: t("ChatGPT example"),
value: `import cloud from '@lafjs/cloud'
const apiKey = cloud.env.API_KEY
export default async function (ctx: FunctionContext) {
const { ChatGPTAPI } = await import('chatgpt')
const { body, response } = ctx
// get chatgpt api
let api = cloud.shared.get('api')
if (!api) {
api = new ChatGPTAPI({ apiKey })
cloud.shared.set('api', api)
}
// set stream response type
response.setHeader('Content-Type', 'application/octet-stream');
// send message
const res = await api.sendMessage(body.message, {
onProgress: (partialResponse) => {
if (partialResponse?.delta != undefined)
response.write(partialResponse.delta)
},
parentMessageId: body.parentMessageId || ''
})
response.end("--!" + res.id)
}
const apiKey = cloud.env.API_KEY
export default async function (ctx: FunctionContext) {
const { ChatGPTAPI } = await import('chatgpt')
const { body, response } = ctx
// get chatgpt api
let api = cloud.shared.get('api')
if (!api) {
api = new ChatGPTAPI({ apiKey })
cloud.shared.set('api', api)
}
// set stream response type
response.setHeader('Content-Type', 'application/octet-stream');
// send message
const res = await api.sendMessage(body.message, {
onProgress: (partialResponse) => {
if (partialResponse?.delta != undefined)
response.write(partialResponse.delta)
},
parentMessageId: body.parentMessageId || ''
})
response.end("--!" + res.id)
}
`,
},
];
Expand Down

0 comments on commit 6e79d26

Please sign in to comment.