Skip to content

Commit 0f8a37f

Browse files
committed
feat: Upload images to S3 and log success/error messages
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.
1 parent 840aa8b commit 0f8a37f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

server/flowing.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,17 @@ export async function allS3() {
262262
for (const module of modules) {
263263
if (!module.image) continue
264264
try {
265-
console.log(await uploadRemoteImageToS3(module.image, `module/cover/${module.id}`))
265+
await uploadRemoteImageToS3(module.image, `module/cover/${module.id}`)
266266
await prisma.module.update({
267267
where: { id: module.id },
268268
data: {
269269
s3Key: `module/cover/${module.id}`,
270270
},
271271
})
272+
consola.success('Image uploaded to S3: ', module.title)
272273
}
273274
catch (e) {
274-
console.error(e)
275+
consola.error('Error uploading image:', e)
275276
continue
276277
}
277278
}

server/plugins/scheduler.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ export default defineNitroPlugin(() => {
66
})
77

88
function startScheduler() {
9+
const config = useRuntimeConfig()
10+
911
const scheduler = useScheduler()
1012

1113
// fetch every 3 hour
1214
scheduler.run(async () => {
1315
await flowing()
1416
await allSize()
15-
await allS3()
17+
if (config.s3.accessKeyId) {
18+
await allS3()
19+
}
1620
}).everyHours(3)
1721
}

0 commit comments

Comments
 (0)