|
|
@@ -2,7 +2,7 @@ import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
|
|
import Banner from 'App/Models/Banner'
|
|
|
import PaginationService from 'App/Services/PaginationService'
|
|
|
import { schema } from '@ioc:Adonis/Core/Validator'
|
|
|
-import FilesService from 'App/Services/FilesService'
|
|
|
+import Drive from '@ioc:Adonis/Core/Drive'
|
|
|
|
|
|
export default class BannersController {
|
|
|
private paginationService = new PaginationService(Banner)
|
|
|
@@ -11,13 +11,9 @@ export default class BannersController {
|
|
|
await Promise.all(
|
|
|
result.map(async (banner) => {
|
|
|
if (banner.img) {
|
|
|
- try {
|
|
|
- const url = new URL(banner.img)
|
|
|
- const filePath = url.pathname.replace(/^\//, '')
|
|
|
- banner.img = await FilesService.generateThumbnailUrl(filePath)
|
|
|
- } catch (e) {
|
|
|
- // ignore invalid url
|
|
|
- }
|
|
|
+ const url = new URL(banner.img)
|
|
|
+ const filePath = url.pathname.replace(/^\//, '')
|
|
|
+ banner.img = await Drive.getSignedUrl(filePath)
|
|
|
}
|
|
|
})
|
|
|
)
|
|
|
@@ -41,6 +37,11 @@ export default class BannersController {
|
|
|
|
|
|
public async show({ params }: HttpContextContract) {
|
|
|
const banner = await Banner.findOrFail(params.id)
|
|
|
+ if (banner.img) {
|
|
|
+ const url = new URL(banner.img)
|
|
|
+ const filePath = url.pathname.replace(/^\//, '')
|
|
|
+ banner.img = await Drive.getSignedUrl(filePath)
|
|
|
+ }
|
|
|
return banner
|
|
|
}
|
|
|
|