Server can be configured on another machine and/or port
This commit is contained in:
parent
f02b398cef
commit
2cf2f11a00
16 changed files with 74 additions and 48 deletions
1
.env
Normal file
1
.env
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
VITE_SERVER_ORIGIN=http://localhost:3001
|
||||||
7
.gitignore
vendored
7
.gitignore
vendored
|
|
@ -15,13 +15,6 @@ data/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
# Environment variables
|
|
||||||
.env
|
|
||||||
.env.local
|
|
||||||
.env.development.local
|
|
||||||
.env.test.local
|
|
||||||
.env.production.local
|
|
||||||
|
|
||||||
# Vite / IDE
|
# Vite / IDE
|
||||||
.vscode/
|
.vscode/
|
||||||
.idea/
|
.idea/
|
||||||
|
|
|
||||||
34
server.js
34
server.js
|
|
@ -96,7 +96,15 @@ import {
|
||||||
} from './wikiStorage.js';
|
} from './wikiStorage.js';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = 3001;
|
const PORT = Number(process.env.PORT) || 3001;
|
||||||
|
|
||||||
|
// Build the externally-reachable base URL ("http://host:port") from the
|
||||||
|
// incoming request so generated asset/media URLs point back at whatever host
|
||||||
|
// and port the client actually used to reach us — works on another machine or
|
||||||
|
// another port without baking "localhost" into responses.
|
||||||
|
function getRequestBaseUrl(req) {
|
||||||
|
return `${req.protocol}://${req.get('host')}`;
|
||||||
|
}
|
||||||
const IMAGE_EXTENSIONS = new Set(['.png', '.jpg', '.jpeg', '.webp', '.gif', '.bmp']);
|
const IMAGE_EXTENSIONS = new Set(['.png', '.jpg', '.jpeg', '.webp', '.gif', '.bmp']);
|
||||||
const MESH_EXTENSIONS = new Set(['.glb', '.gltf', '.obj', '.fbx', '.stl', '.ply']);
|
const MESH_EXTENSIONS = new Set(['.glb', '.gltf', '.obj', '.fbx', '.stl', '.ply']);
|
||||||
const comfyProgressSubscribers = new Map();
|
const comfyProgressSubscribers = new Map();
|
||||||
|
|
@ -538,7 +546,7 @@ app.post('/api/wiki/media', requireWikiAuthor, wikiMediaUpload.single('file'), a
|
||||||
|
|
||||||
const isVideo = ['.mp4', '.webm', '.ogg', '.mov', '.m4v'].includes(extension);
|
const isVideo = ['.mp4', '.webm', '.ogg', '.mov', '.m4v'].includes(extension);
|
||||||
res.status(201).json({
|
res.status(201).json({
|
||||||
url: `http://localhost:${PORT}/wiki-media/${encodeURIComponent(uniqueName)}`,
|
url: `${getRequestBaseUrl(req)}/wiki-media/${encodeURIComponent(uniqueName)}`,
|
||||||
kind: isVideo ? 'video' : 'image',
|
kind: isVideo ? 'video' : 'image',
|
||||||
name: req.file.originalname
|
name: req.file.originalname
|
||||||
});
|
});
|
||||||
|
|
@ -3159,7 +3167,7 @@ app.post('/api/comfyui/workflows/run', workflowExecutionUpload.any(), async (req
|
||||||
: await createProjectAsset(generatedAssetPayload);
|
: await createProjectAsset(generatedAssetPayload);
|
||||||
generatedAssets.push({
|
generatedAssets.push({
|
||||||
...persistedAsset,
|
...persistedAsset,
|
||||||
url: `http://localhost:${PORT}/assets/${encodeURI(toAssetUrlPath(storedFilePath))}`,
|
url: `${getRequestBaseUrl(req)}/assets/${encodeURI(toAssetUrlPath(storedFilePath))}`,
|
||||||
outputKey: workflowFile.outputKey,
|
outputKey: workflowFile.outputKey,
|
||||||
outputNodeId: workflowFile.nodeId,
|
outputNodeId: workflowFile.nodeId,
|
||||||
expectedType: workflowFile.expectedType,
|
expectedType: workflowFile.expectedType,
|
||||||
|
|
@ -4313,9 +4321,9 @@ app.delete('/api/graph/connections', async (req, res) => {
|
||||||
app.get('/api/assets/library', async (req, res) => {
|
app.get('/api/assets/library', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const [images, meshes, brushes] = await Promise.all([
|
const [images, meshes, brushes] = await Promise.all([
|
||||||
listLibraryAssetsByType('image', PORT),
|
listLibraryAssetsByType('image', getRequestBaseUrl(req)),
|
||||||
listLibraryAssetsByType('mesh', PORT),
|
listLibraryAssetsByType('mesh', getRequestBaseUrl(req)),
|
||||||
listLibraryAssetsByType('brush', PORT)
|
listLibraryAssetsByType('brush', getRequestBaseUrl(req))
|
||||||
]);
|
]);
|
||||||
res.json({ images, meshes, brushes });
|
res.json({ images, meshes, brushes });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -4549,20 +4557,20 @@ app.post('/api/assets/library/brush-edits', libraryImportUpload.any(), async (re
|
||||||
// Paint documents — sidecar layer data for painted meshes
|
// Paint documents — sidecar layer data for painted meshes
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
function buildPaintDocumentResponse(doc, assetId) {
|
function buildPaintDocumentResponse(doc, assetId, baseUrl) {
|
||||||
if (!doc) return null;
|
if (!doc) return null;
|
||||||
const baseUrl = doc.baseFilePath
|
const baseTextureUrl = doc.baseFilePath
|
||||||
? `http://localhost:${PORT}/assets/${encodeURI(doc.baseFilePath.replace(/^data\/assets\//, ''))}`
|
? `${baseUrl}/assets/${encodeURI(doc.baseFilePath.replace(/^data\/assets\//, ''))}`
|
||||||
: null;
|
: null;
|
||||||
return {
|
return {
|
||||||
assetId,
|
assetId,
|
||||||
textureWidth: doc.textureWidth,
|
textureWidth: doc.textureWidth,
|
||||||
textureHeight: doc.textureHeight,
|
textureHeight: doc.textureHeight,
|
||||||
base: doc.baseFilePath ? { filePath: doc.baseFilePath, url: baseUrl } : null,
|
base: doc.baseFilePath ? { filePath: doc.baseFilePath, url: baseTextureUrl } : null,
|
||||||
layers: (doc.layers || []).map(layer => ({
|
layers: (doc.layers || []).map(layer => ({
|
||||||
...layer,
|
...layer,
|
||||||
url: layer.filePath
|
url: layer.filePath
|
||||||
? `http://localhost:${PORT}/assets/${encodeURI(layer.filePath.replace(/^data\/assets\//, ''))}`
|
? `${baseUrl}/assets/${encodeURI(layer.filePath.replace(/^data\/assets\//, ''))}`
|
||||||
: null
|
: null
|
||||||
})),
|
})),
|
||||||
updatedAt: doc.updatedAt
|
updatedAt: doc.updatedAt
|
||||||
|
|
@ -4581,7 +4589,7 @@ app.get('/api/assets/:assetId/paint-document', async (req, res) => {
|
||||||
return res.status(404).json({ error: 'Paint document not found' });
|
return res.status(404).json({ error: 'Paint document not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json(buildPaintDocumentResponse(doc, assetId));
|
res.json(buildPaintDocumentResponse(doc, assetId, getRequestBaseUrl(req)));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load paint document:', err);
|
console.error('Failed to load paint document:', err);
|
||||||
res.status(500).json({ error: err.message || 'Failed to load paint document' });
|
res.status(500).json({ error: err.message || 'Failed to load paint document' });
|
||||||
|
|
@ -4695,7 +4703,7 @@ app.put('/api/assets/:assetId/paint-document', paintDocumentUpload.any(), async
|
||||||
layers: persistedLayers
|
layers: persistedLayers
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(200).json(buildPaintDocumentResponse(saved, assetId));
|
res.status(200).json(buildPaintDocumentResponse(saved, assetId, getRequestBaseUrl(req)));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to save paint document:', err);
|
console.error('Failed to save paint document:', err);
|
||||||
res.status(500).json({ error: err.message || 'Failed to save paint document' });
|
res.status(500).json({ error: err.message || 'Failed to save paint document' });
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// components/AssetSelectorModal.jsx
|
// components/AssetSelectorModal.jsx
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
import { useProjects } from '../context/ProjectContext';
|
import { useProjects } from '../context/ProjectContext';
|
||||||
|
import { assetUrl } from '../config';
|
||||||
import './AssetSelectorModal.css'; // we'll create a separate CSS or reuse AssetsPage.css
|
import './AssetSelectorModal.css'; // we'll create a separate CSS or reuse AssetsPage.css
|
||||||
|
|
||||||
function formatDimensions(width, height) {
|
function formatDimensions(width, height) {
|
||||||
|
|
@ -10,7 +11,7 @@ function formatDimensions(width, height) {
|
||||||
|
|
||||||
function getAssetPreviewUrl(filename) {
|
function getAssetPreviewUrl(filename) {
|
||||||
if (!filename) return null;
|
if (!filename) return null;
|
||||||
return `http://localhost:3001/assets/${encodeURI(filename)}`;
|
return assetUrl(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ASSETS_PER_PAGE = 20;
|
const ASSETS_PER_PAGE = 20;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
|
import { API_BASE } from '../config'
|
||||||
import './Footer.css'
|
import './Footer.css'
|
||||||
|
|
||||||
export default function Footer({ variant = 'default', onChangeLogClick }) {
|
export default function Footer({ variant = 'default', onChangeLogClick }) {
|
||||||
|
|
@ -7,7 +8,7 @@ export default function Footer({ variant = 'default', onChangeLogClick }) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchStats = async () => {
|
const fetchStats = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('http://localhost:3001/api/system/stats');
|
const response = await fetch(`${API_BASE}/system/stats`);
|
||||||
if (!response.ok) return; // stats not ready yet — keep showing previous value
|
if (!response.ok) return; // stats not ready yet — keep showing previous value
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setStats(data);
|
setStats(data);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||||
import { useSettings } from '../context/SettingsContext.shared'
|
import { useSettings } from '../context/SettingsContext.shared'
|
||||||
import './SetupWizardModal.css'
|
import './SetupWizardModal.css'
|
||||||
|
import { API_BASE } from '../config'
|
||||||
const API_BASE = 'http://localhost:3001/api'
|
|
||||||
|
|
||||||
const STEPS = [
|
const STEPS = [
|
||||||
{ id: 'comfy-path', label: 'ComfyUI' },
|
{ id: 'comfy-path', label: 'ComfyUI' },
|
||||||
|
|
|
||||||
19
src/config.js
Normal file
19
src/config.js
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
// Central place to resolve where the backend (server.js) lives.
|
||||||
|
//
|
||||||
|
// Set VITE_SERVER_ORIGIN in a .env file to point the frontend at a backend on
|
||||||
|
// another computer or port, e.g.
|
||||||
|
// VITE_SERVER_ORIGIN=http://192.168.1.50:3001
|
||||||
|
// Leave it as an empty string ("") to use the same origin the app was served
|
||||||
|
// from — useful once Express serves the built UI itself (single origin).
|
||||||
|
// When unset, it defaults to the local dev backend.
|
||||||
|
const rawOrigin = import.meta.env.VITE_SERVER_ORIGIN
|
||||||
|
|
||||||
|
export const SERVER_ORIGIN = (rawOrigin === undefined ? 'http://localhost:3001' : rawOrigin)
|
||||||
|
.replace(/\/$/, '')
|
||||||
|
|
||||||
|
export const API_BASE = `${SERVER_ORIGIN}/api`
|
||||||
|
|
||||||
|
// Build a URL to a static asset served from the backend's /assets mount.
|
||||||
|
export function assetUrl(pathOrFilename) {
|
||||||
|
return `${SERVER_ORIGIN}/assets/${encodeURI(pathOrFilename)}`
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
/* eslint-disable react-refresh/only-export-components */
|
/* eslint-disable react-refresh/only-export-components */
|
||||||
import { createContext, useContext, useState, useEffect, useCallback } from 'react'
|
import { createContext, useContext, useState, useEffect, useCallback } from 'react'
|
||||||
|
import { API_BASE } from '../config'
|
||||||
|
|
||||||
const ProjectContext = createContext(null)
|
const ProjectContext = createContext(null)
|
||||||
const API_BASE = 'http://localhost:3001/api'
|
|
||||||
|
|
||||||
export function ProjectProvider({ children }) {
|
export function ProjectProvider({ children }) {
|
||||||
const [projects, setProjects] = useState([])
|
const [projects, setProjects] = useState([])
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { useState, useEffect, useCallback } from 'react'
|
import { useState, useEffect, useCallback } from 'react'
|
||||||
import { SettingsContext } from './SettingsContext.shared'
|
import { SettingsContext } from './SettingsContext.shared'
|
||||||
|
import { API_BASE } from '../config'
|
||||||
|
|
||||||
const API_BASE = 'http://localhost:3001/api'
|
|
||||||
const DEFAULT_CUSTOM_API_TYPE = 'image-generation'
|
const DEFAULT_CUSTOM_API_TYPE = 'image-generation'
|
||||||
|
|
||||||
function normalizeCustomApiType(type) {
|
function normalizeCustomApiType(type) {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import SettingsModal from '../components/SettingsModal'
|
||||||
import { createMeshThumbnailFile } from '../utils/meshThumbnail'
|
import { createMeshThumbnailFile } from '../utils/meshThumbnail'
|
||||||
import './KanbanPage.css'
|
import './KanbanPage.css'
|
||||||
import AssetSelectorModal from '../components/AssetSelectorModal';
|
import AssetSelectorModal from '../components/AssetSelectorModal';
|
||||||
|
import { assetUrl } from '../config'
|
||||||
import KanbanImageCard from '../components/kanban/KanbanImageCard'
|
import KanbanImageCard from '../components/kanban/KanbanImageCard'
|
||||||
import MeshGenApiOptions from '../components/kanban/MeshGenApiOptions'
|
import MeshGenApiOptions from '../components/kanban/MeshGenApiOptions'
|
||||||
import ComfyTextButton from '../components/comfy/ComfyTextButton'
|
import ComfyTextButton from '../components/comfy/ComfyTextButton'
|
||||||
|
|
@ -283,8 +284,8 @@ export default function KanbanPage() {
|
||||||
return asset
|
return asset
|
||||||
}
|
}
|
||||||
|
|
||||||
const assetUrl = `http://localhost:3001/assets/${encodeURI(asset.filename)}`
|
const meshAssetUrl = assetUrl(asset.filename)
|
||||||
const response = await fetch(assetUrl)
|
const response = await fetch(meshAssetUrl)
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Failed to download generated mesh ${asset.name || asset.filename}`)
|
throw new Error(`Failed to download generated mesh ${asset.name || asset.filename}`)
|
||||||
|
|
@ -1598,7 +1599,7 @@ export default function KanbanPage() {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return `http://localhost:3001/assets/${encodeURI(filename)}`
|
return assetUrl(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatAssetDimensions = (width, height) => {
|
const formatAssetDimensions = (width, height) => {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import SettingsModal from '../components/SettingsModal'
|
||||||
import { useProjects } from '../context/ProjectContext'
|
import { useProjects } from '../context/ProjectContext'
|
||||||
import { useNotifications } from '../context/NotificationContext'
|
import { useNotifications } from '../context/NotificationContext'
|
||||||
import { createMeshThumbnailFile } from '../utils/meshThumbnail'
|
import { createMeshThumbnailFile } from '../utils/meshThumbnail'
|
||||||
|
import { assetUrl } from '../config'
|
||||||
import {
|
import {
|
||||||
bridgeSelectedHoleSegments,
|
bridgeSelectedHoleSegments,
|
||||||
bridgeAndFillSelectedHole,
|
bridgeAndFillSelectedHole,
|
||||||
|
|
@ -658,7 +659,7 @@ export default function MeshEditorPage() {
|
||||||
if (paintBrushSource === 'asset' && paintBrushAsset) {
|
if (paintBrushSource === 'asset' && paintBrushAsset) {
|
||||||
sourceUrl = paintBrushAsset.url
|
sourceUrl = paintBrushAsset.url
|
||||||
|| (paintBrushAsset.filename
|
|| (paintBrushAsset.filename
|
||||||
? `http://localhost:3001/assets/${encodeURI(paintBrushAsset.filename)}`
|
? assetUrl(paintBrushAsset.filename)
|
||||||
: null);
|
: null);
|
||||||
} else if (paintBrushSource === 'computer' && paintBrushFile) {
|
} else if (paintBrushSource === 'computer' && paintBrushFile) {
|
||||||
objectUrl = URL.createObjectURL(paintBrushFile);
|
objectUrl = URL.createObjectURL(paintBrushFile);
|
||||||
|
|
@ -1433,7 +1434,7 @@ export default function MeshEditorPage() {
|
||||||
if (sculptStampSource === 'asset' && sculptStampAsset) {
|
if (sculptStampSource === 'asset' && sculptStampAsset) {
|
||||||
sourceUrl = sculptStampAsset.url
|
sourceUrl = sculptStampAsset.url
|
||||||
|| (sculptStampAsset.filename
|
|| (sculptStampAsset.filename
|
||||||
? `http://localhost:3001/assets/${encodeURI(sculptStampAsset.filename)}`
|
? assetUrl(sculptStampAsset.filename)
|
||||||
: null);
|
: null);
|
||||||
} else if (sculptStampSource === 'computer' && sculptStampFile) {
|
} else if (sculptStampSource === 'computer' && sculptStampFile) {
|
||||||
objectUrl = URL.createObjectURL(sculptStampFile);
|
objectUrl = URL.createObjectURL(sculptStampFile);
|
||||||
|
|
@ -3892,8 +3893,8 @@ export default function MeshEditorPage() {
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const assetUrl = savedAsset?.filename ? `http://localhost:3001/assets/${encodeURI(savedAsset.filename)}` : ''
|
const savedAssetUrl = savedAsset?.filename ? assetUrl(savedAsset.filename) : ''
|
||||||
const response = assetUrl ? await fetch(assetUrl) : null
|
const response = savedAssetUrl ? await fetch(savedAssetUrl) : null
|
||||||
if (response?.ok) {
|
if (response?.ok) {
|
||||||
const blob = await response.blob()
|
const blob = await response.blob()
|
||||||
const meshFile = new File([blob], savedAsset.filename?.split('/').pop() || `${savedAsset.name || 'mesh'}.glb`, {
|
const meshFile = new File([blob], savedAsset.filename?.split('/').pop() || `${savedAsset.name || 'mesh'}.glb`, {
|
||||||
|
|
@ -3968,7 +3969,7 @@ export default function MeshEditorPage() {
|
||||||
if (saveMode === 'version' && savedAsset?.id) {
|
if (saveMode === 'version' && savedAsset?.id) {
|
||||||
const nextSearchParams = new URLSearchParams(searchParams)
|
const nextSearchParams = new URLSearchParams(searchParams)
|
||||||
const savedFilename = savedAsset.filename || (savedAsset.filePath ? savedAsset.filePath.replace(/^data\/assets\//, '') : '')
|
const savedFilename = savedAsset.filename || (savedAsset.filePath ? savedAsset.filePath.replace(/^data\/assets\//, '') : '')
|
||||||
const savedUrl = savedFilename ? `http://localhost:3001/assets/${encodeURI(savedFilename)}` : modelUrl
|
const savedUrl = savedFilename ? assetUrl(savedFilename) : modelUrl
|
||||||
|
|
||||||
nextSearchParams.set('assetId', String(savedAsset.id))
|
nextSearchParams.set('assetId', String(savedAsset.id))
|
||||||
nextSearchParams.set('filePath', savedAsset.filePath || '')
|
nextSearchParams.set('filePath', savedAsset.filePath || '')
|
||||||
|
|
@ -5141,7 +5142,7 @@ export default function MeshEditorPage() {
|
||||||
let file = null;
|
let file = null;
|
||||||
if (config.type === 'asset') {
|
if (config.type === 'asset') {
|
||||||
// Build asset URL
|
// Build asset URL
|
||||||
const url = config.filePath ? `http://localhost:3001/assets/${encodeURI(config.filePath.replace(/^data\/assets\//, ''))}` : null;
|
const url = config.filePath ? assetUrl(config.filePath.replace(/^data\/assets\//, '')) : null;
|
||||||
if (!url) throw new Error(`Asset ${config.assetName} has no file path`);
|
if (!url) throw new Error(`Asset ${config.assetName} has no file path`);
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
if (!response.ok) throw new Error(`Failed to load asset ${config.assetName}`);
|
if (!response.ok) throw new Error(`Failed to load asset ${config.assetName}`);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
// Pure helpers and config constants for the node-graph editor (GraphPage).
|
// Pure helpers and config constants for the node-graph editor (GraphPage).
|
||||||
// Extracted from GraphPage.jsx — no React, no component state.
|
// Extracted from GraphPage.jsx — no React, no component state.
|
||||||
|
import { assetUrl } from '../config'
|
||||||
|
|
||||||
export const DEFAULT_OUTPUT_ID = 'output-0'
|
export const DEFAULT_OUTPUT_ID = 'output-0'
|
||||||
export const DEFAULT_INPUT_ID = 'input-0'
|
export const DEFAULT_INPUT_ID = 'input-0'
|
||||||
|
|
@ -324,7 +325,7 @@ export function getAssetPreviewUrl(filename) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return `http://localhost:3001/assets/${encodeURI(filename)}`
|
return assetUrl(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function appendCacheBust(url, cacheKey) {
|
export function appendCacheBust(url, cacheKey) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
// Pure helpers and config constants for the Kanban board page (KanbanPage).
|
// Pure helpers and config constants for the Kanban board page (KanbanPage).
|
||||||
// Extracted from KanbanPage.jsx — no React, no component state.
|
// Extracted from KanbanPage.jsx — no React, no component state.
|
||||||
|
import { assetUrl } from '../config'
|
||||||
|
|
||||||
export const IMAGE_API_LIST = [
|
export const IMAGE_API_LIST = [
|
||||||
{ id: 'nanobana', name: 'Nanobana' },
|
{ id: 'nanobana', name: 'Nanobana' },
|
||||||
|
|
@ -156,7 +157,7 @@ export function buildMeshEditorPath(asset, projectId, returnTo) {
|
||||||
const query = new URLSearchParams({
|
const query = new URLSearchParams({
|
||||||
assetId: String(asset?.id || ''),
|
assetId: String(asset?.id || ''),
|
||||||
filePath: asset?.filePath || asset?.filename || '',
|
filePath: asset?.filePath || asset?.filename || '',
|
||||||
url: asset?.filename ? `http://localhost:3001/assets/${encodeURI(asset.filename)}` : '',
|
url: asset?.filename ? assetUrl(asset.filename) : '',
|
||||||
name: asset?.name || 'Mesh',
|
name: asset?.name || 'Mesh',
|
||||||
projectId: projectId ? String(projectId) : '',
|
projectId: projectId ? String(projectId) : '',
|
||||||
returnTo: returnTo || ''
|
returnTo: returnTo || ''
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,7 @@ import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter.js'
|
||||||
import { OBJExporter } from 'three/examples/jsm/exporters/OBJExporter.js'
|
import { OBJExporter } from 'three/examples/jsm/exporters/OBJExporter.js'
|
||||||
import { PLYExporter } from 'three/examples/jsm/exporters/PLYExporter.js'
|
import { PLYExporter } from 'three/examples/jsm/exporters/PLYExporter.js'
|
||||||
import { STLExporter } from 'three/examples/jsm/exporters/STLExporter.js'
|
import { STLExporter } from 'three/examples/jsm/exporters/STLExporter.js'
|
||||||
|
import { API_BASE } from '../config'
|
||||||
const API_BASE = 'http://localhost:3001/api'
|
|
||||||
|
|
||||||
// Formats we can reliably serialize with three.js. FBX has no official
|
// Formats we can reliably serialize with three.js. FBX has no official
|
||||||
// exporter, so it is intentionally excluded.
|
// exporter, so it is intentionally excluded.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import * as THREE from 'three'
|
import * as THREE from 'three'
|
||||||
|
import { assetUrl } from '../config'
|
||||||
import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter.js'
|
import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter.js'
|
||||||
import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js'
|
import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js'
|
||||||
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
|
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
|
||||||
|
|
@ -1484,7 +1485,7 @@ export function buildAssetUrl(asset) {
|
||||||
.replace(/^data\/assets\//, '')
|
.replace(/^data\/assets\//, '')
|
||||||
.replace(/^assets\//, '')
|
.replace(/^assets\//, '')
|
||||||
|
|
||||||
return `http://localhost:3001/assets/${encodeURI(normalizedPath)}`
|
return assetUrl(normalizedPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createTexturePaintWorkflowDraft(workflow) {
|
export function createTexturePaintWorkflowDraft(workflow) {
|
||||||
|
|
|
||||||
16
storage.js
16
storage.js
|
|
@ -516,18 +516,18 @@ async function migrateLegacyAssetEditsToAssets(db) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function groupChildAssetsByParentFilePath(rows = [], port = null) {
|
function groupChildAssetsByParentFilePath(rows = [], baseUrl = null) {
|
||||||
return rows.reduce((accumulator, row) => {
|
return rows.reduce((accumulator, row) => {
|
||||||
if (!accumulator[row.parentFilePath]) {
|
if (!accumulator[row.parentFilePath]) {
|
||||||
accumulator[row.parentFilePath] = [];
|
accumulator[row.parentFilePath] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const childAsset = mapChildAssetRow(row);
|
const childAsset = mapChildAssetRow(row);
|
||||||
const childWithUrl = port
|
const childWithUrl = baseUrl
|
||||||
? {
|
? {
|
||||||
...childAsset,
|
...childAsset,
|
||||||
url: `http://localhost:${port}/assets/${encodeURI(childAsset.filename)}`,
|
url: `${baseUrl}/assets/${encodeURI(childAsset.filename)}`,
|
||||||
thumbnailUrl: childAsset.thumbnail ? `http://localhost:${port}/assets/${encodeURI(childAsset.thumbnail)}` : null
|
thumbnailUrl: childAsset.thumbnail ? `${baseUrl}/assets/${encodeURI(childAsset.thumbnail)}` : null
|
||||||
}
|
}
|
||||||
: childAsset;
|
: childAsset;
|
||||||
|
|
||||||
|
|
@ -3145,7 +3145,7 @@ export async function getWikiPage(id) {
|
||||||
return row ? mapWikiPageRow(row) : null;
|
return row ? mapWikiPageRow(row) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listLibraryAssetsByType(type, port) {
|
export async function listLibraryAssetsByType(type, baseUrl) {
|
||||||
const db = await getDb();
|
const db = await getDb();
|
||||||
const assetDirectory = getAssetDirectory(type);
|
const assetDirectory = getAssetDirectory(type);
|
||||||
await fs.mkdir(assetDirectory, { recursive: true });
|
await fs.mkdir(assetDirectory, { recursive: true });
|
||||||
|
|
@ -3225,7 +3225,7 @@ export async function listLibraryAssetsByType(type, port) {
|
||||||
|
|
||||||
const childAssetRows = await listChildAssetsByParentFilePaths(db, candidateStoredPaths, normalizeAssetTypeName(type));
|
const childAssetRows = await listChildAssetsByParentFilePaths(db, candidateStoredPaths, normalizeAssetTypeName(type));
|
||||||
|
|
||||||
const childrenBySourceFilePath = groupChildAssetsByParentFilePath(childAssetRows, port);
|
const childrenBySourceFilePath = groupChildAssetsByParentFilePath(childAssetRows, baseUrl);
|
||||||
|
|
||||||
const dbAssets = rows.reduce((accumulator, row) => {
|
const dbAssets = rows.reduce((accumulator, row) => {
|
||||||
const filename = toAssetUrlPath(row.filePath);
|
const filename = toAssetUrlPath(row.filePath);
|
||||||
|
|
@ -3261,11 +3261,11 @@ export async function listLibraryAssetsByType(type, port) {
|
||||||
projectIds: projectIdsByFilePath[row.filePath] || [],
|
projectIds: projectIdsByFilePath[row.filePath] || [],
|
||||||
type,
|
type,
|
||||||
extension: path.extname(filename).replace('.', '').toUpperCase() || type.toUpperCase(),
|
extension: path.extname(filename).replace('.', '').toUpperCase() || type.toUpperCase(),
|
||||||
url: `http://localhost:${port}/assets/${encodeURI(filename)}`,
|
url: `${baseUrl}/assets/${encodeURI(filename)}`,
|
||||||
width: canonicalAsset?.width ?? row.width ?? 0,
|
width: canonicalAsset?.width ?? row.width ?? 0,
|
||||||
height: canonicalAsset?.height ?? row.height ?? 0,
|
height: canonicalAsset?.height ?? row.height ?? 0,
|
||||||
thumbnailPath,
|
thumbnailPath,
|
||||||
thumbnailUrl: thumbnailFilename ? `http://localhost:${port}/assets/${encodeURI(thumbnailFilename)}` : null,
|
thumbnailUrl: thumbnailFilename ? `${baseUrl}/assets/${encodeURI(thumbnailFilename)}` : null,
|
||||||
children: assetChildren,
|
children: assetChildren,
|
||||||
childCount: assetChildren.length,
|
childCount: assetChildren.length,
|
||||||
edits: assetChildren,
|
edits: assetChildren,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue