Skip to content

Commit

Permalink
feat: Upload images to S3 and log success/error messages
Browse files Browse the repository at this point in the history
Uploaded images to S3 in 'allS3' function and added success and error messages using 'consola'. Added conditional check in 'startScheduler' to only run 'allS3' if S3 access key is provided.
  • Loading branch information
nexmoe committed May 4, 2024
1 parent 840aa8b commit 0f8a37f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions server/flowing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,17 @@ export async function allS3() {
for (const module of modules) {
if (!module.image) continue
try {
console.log(await uploadRemoteImageToS3(module.image, `module/cover/${module.id}`))
await uploadRemoteImageToS3(module.image, `module/cover/${module.id}`)
await prisma.module.update({
where: { id: module.id },
data: {
s3Key: `module/cover/${module.id}`,
},
})
consola.success('Image uploaded to S3: ', module.title)
}
catch (e) {
console.error(e)
consola.error('Error uploading image:', e)
continue
}
}
Expand Down
6 changes: 5 additions & 1 deletion server/plugins/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ export default defineNitroPlugin(() => {
})

function startScheduler() {
const config = useRuntimeConfig()

const scheduler = useScheduler()

// fetch every 3 hour
scheduler.run(async () => {
await flowing()
await allSize()
await allS3()
if (config.s3.accessKeyId) {
await allS3()
}
}).everyHours(3)
}

0 comments on commit 0f8a37f

Please sign in to comment.