fix: fix placeholder image directory path

This commit is contained in:
Hossein Mehrabi 2024-02-02 18:13:52 +03:30
parent 9328d5c99a
commit 5b5b8ea500
No known key found for this signature in database
GPG Key ID: 45C04964191AFAA1
4 changed files with 12 additions and 5 deletions

View File

@ -17,6 +17,7 @@ ARG NEXT_PUBLIC_ASSETS_BASE_URL
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV SOURCE_DIR=/app
COPY . .

View File

@ -56,7 +56,7 @@ export const ResponsiveImage = ({
>
<div className="comment">
<img
src={data.placeholder?.replace('public/', '/')}
src={data.placeholder?.replace('/public/', '/')}
alt={data.alt}
title={data.alt}
/>

View File

@ -1 +1 @@
export const POSTS_IMAGE_PLACEHOLDER_DIR = `./public/images/placeholders`
export const POSTS_IMAGE_PLACEHOLDER_DIR = '/public/images/placeholders'

View File

@ -5,6 +5,7 @@ import {
transformStrapiImageUrl,
} from '@/services/strapi/transformers/utils'
import axios from 'axios'
import path from 'path'
import sharp from 'sharp'
export class PlaceholderService {
@ -33,7 +34,12 @@ export class PlaceholderService {
const thumbnailPath = getStrapiImageUrlBySize('thumbnail', imagePath)
try {
const filePath = `${POSTS_IMAGE_PLACEHOLDER_DIR}/${fileName}`
const relativePath = path.join(POSTS_IMAGE_PLACEHOLDER_DIR, fileName)
const filePath = path.join(
process.env.SOURCE_DIR ?? process.cwd(),
relativePath,
)
const imageUrl = transformStrapiImageUrl(thumbnailPath)
const imageBuffer = (
await axios({ url: imageUrl, responseType: 'arraybuffer' })
@ -51,9 +57,9 @@ export class PlaceholderService {
})
.toFile(filePath)
this.add(fileName, filePath)
this.add(fileName, relativePath)
return filePath
return relativePath
} catch (e) {
console.log(e)
}