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:
parent
3468c06f56
commit
11f45b9a32
2 changed files with 11 additions and 1 deletions
5
.changeset/heavy-lies-cover.md
Normal file
5
.changeset/heavy-lies-cover.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix file system path references
|
|
@ -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;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue