Datei-Uploads funktionieren wieder mit Adressen ohne Domain
Der lokale Dateianbieter baut die Adresse mit new URL(backend_url) und scheiterte an "/static" mit "Invalid URL" – jeder Upload brach ab, auch Produktbilder im Admin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -96,7 +96,9 @@ module.exports = defineConfig({
|
||||
options: {
|
||||
providers: [
|
||||
{
|
||||
resolve: "@medusajs/file-local",
|
||||
// Wie @medusajs/file-local, nur mit Adressen ohne Domain —
|
||||
// siehe src/modules/file-relative.
|
||||
resolve: "./src/modules/file-relative",
|
||||
id: "local",
|
||||
options: {
|
||||
// Bewusst ohne Domain: Die Adresse landet so in der Datenbank,
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"@medusajs/cli": "2.17.2",
|
||||
"@medusajs/dashboard": "2.17.2",
|
||||
"@medusajs/draft-order": "2.17.2",
|
||||
"@medusajs/file-local": "2.17.2",
|
||||
"@medusajs/framework": "2.17.2",
|
||||
"@medusajs/loyalty-plugin": "2.17.2",
|
||||
"@medusajs/medusa": "2.17.2",
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { ModuleProvider, Modules } from "@medusajs/framework/utils";
|
||||
import { LocalFileService } from "@medusajs/file-local";
|
||||
|
||||
/**
|
||||
* Lokale Dateiablage mit Adressen ohne Domain (/static/…).
|
||||
*
|
||||
* Der Standardanbieter baut die Adresse mit `new URL(backend_url)` und
|
||||
* scheitert an einem relativen Pfad mit "Invalid URL" — jeder Upload brach
|
||||
* ab, auch Produktbilder im Admin. Hier entsteht die Adresse ohne URL-Objekt;
|
||||
* alles andere bleibt beim Original.
|
||||
*/
|
||||
class RelativeLocalFileService extends LocalFileService {
|
||||
static identifier = "localfs-relative";
|
||||
|
||||
constructor(deps: any, options: any) {
|
||||
super(deps, options);
|
||||
const basis = String(options?.backend_url ?? "/static").replace(/\/+$/, "");
|
||||
(this as any).getUploadFileUrl = (fileKey: string) =>
|
||||
`${basis}/${fileKey.split("/").map(encodeURIComponent).join("/")}`;
|
||||
}
|
||||
}
|
||||
|
||||
export default ModuleProvider(Modules.FILE, {
|
||||
services: [RelativeLocalFileService],
|
||||
});
|
||||
Reference in New Issue
Block a user