0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -05:00

fix: _image endpoint returning a 404 for local images (#8828)

This commit is contained in:
Rishi Raj Jain 2023-10-17 15:42:01 +05:30 committed by GitHub
parent 3468c06f56
commit 11f45b9a32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
fix file system path references

View file

@ -1,15 +1,20 @@
import { isRemotePath, removeQueryString } from '@astrojs/internal-helpers/path'; import { isRemotePath, removeQueryString } from '@astrojs/internal-helpers/path';
import { readFile } from 'fs/promises'; import { readFile } from 'fs/promises';
import mime from 'mime/lite.js'; import mime from 'mime/lite.js';
import os from 'os';
import type { APIRoute } from '../../@types/astro.js'; import type { APIRoute } from '../../@types/astro.js';
import { getConfiguredImageService, isRemoteAllowed } from '../internal.js'; import { getConfiguredImageService, isRemoteAllowed } from '../internal.js';
import { etag } from '../utils/etag.js'; import { etag } from '../utils/etag.js';
// @ts-expect-error // @ts-expect-error
import { assetsDir, imageConfig } from 'astro:assets'; import { assetsDir, imageConfig } from 'astro:assets';
function replaceFileSystemReferences(src: string) {
return os.platform().includes('win32') ? src.replace(/^\/@fs\//, '') : src.replace(/^\/@fs/, '');
}
async function loadLocalImage(src: string, url: URL) { async function loadLocalImage(src: string, url: URL) {
const filePath = import.meta.env.DEV const filePath = import.meta.env.DEV
? removeQueryString(src.slice('/@fs'.length)) ? removeQueryString(replaceFileSystemReferences(src))
: new URL('.' + src, assetsDir); : new URL('.' + src, assetsDir);
let buffer: Buffer | undefined = undefined; let buffer: Buffer | undefined = undefined;