Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions SparkyFitnessServer/SparkyFitnessServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ app.use((req, _res, next) => {
next();
});
// Serve static files from the 'uploads' directory
const UPLOADS_BASE_DIR = path.join(__dirname, 'uploads');
const UPLOADS_BASE_DIR = process.env.SPARKY_FITNESS_CUSTOM_UPLOADS_DIRECTORY
? path.resolve(process.env.SPARKY_FITNESS_CUSTOM_UPLOADS_DIRECTORY)
: path.join(__dirname, 'uploads');
Comment thread
Sim-sat marked this conversation as resolved.
Comment thread
Sim-sat marked this conversation as resolved.

console.log('SparkyFitnessServer UPLOADS_BASE_DIR:', UPLOADS_BASE_DIR);
// Mount at both paths for compatibility during transition
app.use('/api/uploads', express.static(UPLOADS_BASE_DIR));
Expand Down Expand Up @@ -247,8 +250,8 @@ app.get(
async (req, res, _next) => {
const { exerciseId, imageFileName } = req.params;
const localImagePath = path.join(
__dirname,
'uploads/exercises',
UPLOADS_BASE_DIR,
'exercises',
// @ts-expect-error TS2345
exerciseId,
imageFileName
Expand All @@ -275,13 +278,8 @@ app.get(
const externalImageUrl = freeExerciseDBService.getExerciseImageUrl(
originalRelativeImagePath
);
const downloadedLocalPath = await downloadImage(
externalImageUrl,
exerciseId
);
// @ts-expect-error TS2345
const finalImagePath = path.join(__dirname, downloadedLocalPath);
res.sendFile(finalImagePath);
await downloadImage(externalImageUrl, exerciseId);
res.sendFile(localImagePath);
} catch (error) {
// @ts-expect-error TS18046
log('error', `Error serving image: ${error.message}`);
Expand Down
13 changes: 11 additions & 2 deletions SparkyFitnessServer/routes/exerciseRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ import multer from 'multer';
import path from 'path';
import fs from 'fs';
import { ExternalProviderType } from 'types/externalProvider.ts';

import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const router = express.Router();

const baseUploadsDir = process.env.SPARKY_FITNESS_CUSTOM_UPLOADS_DIRECTORY
? path.resolve(process.env.SPARKY_FITNESS_CUSTOM_UPLOADS_DIRECTORY)
: path.join(__dirname, '../uploads');
// Setup Multer for file uploads
const storage = multer.diskStorage({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -17,8 +26,8 @@ const storage = multer.diskStorage({
? JSON.parse(req.body.exerciseData).name
: 'unknown-exercise';
const uploadPath = path.join(
__dirname,
'../uploads/exercises',
baseUploadsDir,
'exercises',
exerciseName.replace(/[^a-zA-Z0-9]/g, '_')
);
fs.mkdirSync(uploadPath, { recursive: true });
Expand Down
9 changes: 7 additions & 2 deletions SparkyFitnessServer/services/backupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ const __dirname = path.dirname(__filename);

const fsp = { promises }.promises; // Use fsp for promise-based fs operations
// const { configureSessionMiddleware } = require('../SparkyFitnessServer'); // Removed to fix circular dependency
const BACKUP_DIR = process.env.BACKUP_DIR || path.join(__dirname, '../backup');
const UPLOADS_BASE_DIR = path.join(__dirname, '../uploads');
const BACKUP_DIR = process.env.SPARKY_FITNESS_CUSTOM_BACKUP_DIRECTORY
? path.resolve(process.env.SPARKY_FITNESS_CUSTOM_BACKUP_DIRECTORY)
: process.env.BACKUP_DIR || path.join(__dirname, '../backup');

const UPLOADS_BASE_DIR = process.env.SPARKY_FITNESS_CUSTOM_UPLOADS_DIRECTORY
? path.resolve(process.env.SPARKY_FITNESS_CUSTOM_UPLOADS_DIRECTORY)
: path.join(__dirname, '../uploads');
// Ensure backup directory exists
async function ensureBackupDirectory() {
try {
Expand Down
6 changes: 5 additions & 1 deletion SparkyFitnessServer/utils/imageDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const fsp = { promises }.promises; // Import fs.promises as fsp
const UPLOADS_DIR = path.join(__dirname, '../uploads/exercises'); // Relative to SparkyFitnessServer
const baseUploadsDir = process.env.SPARKY_FITNESS_CUSTOM_UPLOADS_DIRECTORY
? path.resolve(process.env.SPARKY_FITNESS_CUSTOM_UPLOADS_DIRECTORY)
: path.join(__dirname, '../uploads');

const UPLOADS_DIR = path.join(baseUploadsDir, 'exercises');
/**
* Ensures the upload directory exists.
*/
Expand Down
5 changes: 4 additions & 1 deletion docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ SPARKY_FITNESS_DISABLE_SIGNUP=false
# SPARKY_FITNESS_OIDC_USERINFO_SIGNED_ALG=none
# SPARKY_FITNESS_OIDC_TIMEOUT=30000


# Set custom uploads and backups directory. Only needed for standalone installation
# SPARKY_FITNESS_CUSTOM_UPLOADS_DIRECTORY=
# SPARKY_FITNESS_CUSTOM_BACKUP_DIRECTORY=
#
# --- Login Management Fail-Safe ---
# Set to 'true' to force email/password login to be enabled, overriding any in-app settings.
# This is a fail-safe to prevent being locked out if OIDC is misconfigured.
Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile.backend.dev
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ RUN corepack enable

WORKDIR /app

RUN apk add --no-cache postgresql-client
# Copy workspace root files for pnpm resolution
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./

Expand Down
Loading