|
@@ -7,6 +7,7 @@ import {
|
|
|
Post,
|
|
Post,
|
|
|
Query,
|
|
Query,
|
|
|
} from '@nestjs/common';
|
|
} from '@nestjs/common';
|
|
|
|
|
+import * as path from 'path';
|
|
|
import { AppService } from './app.service';
|
|
import { AppService } from './app.service';
|
|
|
import { EventsGateway } from './events.gateway';
|
|
import { EventsGateway } from './events.gateway';
|
|
|
|
|
|
|
@@ -130,31 +131,74 @@ export class AppController {
|
|
|
@Param('file') file: string,
|
|
@Param('file') file: string,
|
|
|
@Body('preset') preset?: string,
|
|
@Body('preset') preset?: string,
|
|
|
) {
|
|
) {
|
|
|
- const fileRecord = this.appService.findFile(dataset, file) as FileRecord;
|
|
|
|
|
- if (!fileRecord) {
|
|
|
|
|
- throw new Error(`File not found: ${dataset}/${file}`);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Get dataset configuration to find the preset for this dataset
|
|
|
|
|
|
|
+ // Get dataset configuration to find the preset and output configuration
|
|
|
const datasetConfig = this.appService.getDatasetConfig();
|
|
const datasetConfig = this.appService.getDatasetConfig();
|
|
|
let processingPreset = preset;
|
|
let processingPreset = preset;
|
|
|
|
|
+ let output: string;
|
|
|
|
|
+
|
|
|
|
|
+ // Try to find existing file record first
|
|
|
|
|
+ const fileRecord = this.appService.findFile(dataset, file) as FileRecord;
|
|
|
|
|
+
|
|
|
|
|
+ if (fileRecord) {
|
|
|
|
|
+ // Use existing file record
|
|
|
|
|
+ output = fileRecord.output;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // No existing file record - determine output path from dataset config
|
|
|
|
|
+ let destination: string | undefined;
|
|
|
|
|
+ let ext = '.mkv'; // Default extension
|
|
|
|
|
+
|
|
|
|
|
+ if (datasetConfig[dataset]) {
|
|
|
|
|
+ const datasetObj = datasetConfig[dataset];
|
|
|
|
|
+
|
|
|
|
|
+ // Find the path configuration that matches this file
|
|
|
|
|
+ for (const pathKey of Object.keys(datasetObj)) {
|
|
|
|
|
+ if (pathKey !== 'enabled' && file.startsWith(pathKey)) {
|
|
|
|
|
+ const pathConfig = datasetObj[pathKey];
|
|
|
|
|
+ if (pathConfig) {
|
|
|
|
|
+ if (pathConfig.preset && !processingPreset) {
|
|
|
|
|
+ processingPreset = pathConfig.preset;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (pathConfig.destination) {
|
|
|
|
|
+ destination = pathConfig.destination;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (pathConfig.ext) {
|
|
|
|
|
+ ext = pathConfig.ext.startsWith('.')
|
|
|
|
|
+ ? pathConfig.ext
|
|
|
|
|
+ : '.' + pathConfig.ext;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (!processingPreset && datasetConfig[dataset]) {
|
|
|
|
|
- // Find the preset for this dataset by looking at the first path's preset
|
|
|
|
|
- const datasetObj = datasetConfig[dataset];
|
|
|
|
|
- for (const pathKey of Object.keys(datasetObj)) {
|
|
|
|
|
- if (
|
|
|
|
|
- pathKey !== 'enabled' &&
|
|
|
|
|
- datasetObj[pathKey] &&
|
|
|
|
|
- datasetObj[pathKey].preset
|
|
|
|
|
- ) {
|
|
|
|
|
- processingPreset = datasetObj[pathKey].preset;
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ // Fallback to old format
|
|
|
|
|
+ if (!processingPreset && datasetObj.preset) {
|
|
|
|
|
+ processingPreset = datasetObj.preset;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!destination && datasetObj.destination) {
|
|
|
|
|
+ destination = datasetObj.destination;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (ext === '.mkv' && datasetObj.ext) {
|
|
|
|
|
+ ext = datasetObj.ext.startsWith('.')
|
|
|
|
|
+ ? datasetObj.ext
|
|
|
|
|
+ : '.' + datasetObj.ext;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Determine output path
|
|
|
|
|
+ if (destination) {
|
|
|
|
|
+ const fileName = path.basename(file, path.extname(file));
|
|
|
|
|
+ output = path.join(destination, fileName + ext);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // Default: same directory with new extension
|
|
|
|
|
+ output = path.join(
|
|
|
|
|
+ path.dirname(file),
|
|
|
|
|
+ path.basename(file, path.extname(file)) + ext,
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Fallback to default preset if no dataset-specific preset found
|
|
|
|
|
|
|
+ // Fallback to default preset if no preset found
|
|
|
if (!processingPreset) {
|
|
if (!processingPreset) {
|
|
|
processingPreset = 'Fast 1080p30';
|
|
processingPreset = 'Fast 1080p30';
|
|
|
}
|
|
}
|
|
@@ -162,17 +206,18 @@ export class AppController {
|
|
|
// Create a task for processing
|
|
// Create a task for processing
|
|
|
const task = this.appService.createTask({
|
|
const task = this.appService.createTask({
|
|
|
dataset,
|
|
dataset,
|
|
|
- input: fileRecord.input,
|
|
|
|
|
- output: fileRecord.output,
|
|
|
|
|
|
|
+ input: file,
|
|
|
|
|
+ output: output,
|
|
|
preset: processingPreset,
|
|
preset: processingPreset,
|
|
|
priority: 1, // Higher priority for manual requeues
|
|
priority: 1, // Higher priority for manual requeues
|
|
|
status: 'requeued', // Mark as manually requeued
|
|
status: 'requeued', // Mark as manually requeued
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // Update file status to pending
|
|
|
|
|
|
|
+ // Update file status to pending (this will create the file record if it doesn't exist)
|
|
|
this.appService.setFile(dataset, file, {
|
|
this.appService.setFile(dataset, file, {
|
|
|
status: 'pending',
|
|
status: 'pending',
|
|
|
date: new Date().toISOString(),
|
|
date: new Date().toISOString(),
|
|
|
|
|
+ output: output,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// Emit file update
|
|
// Emit file update
|
|
@@ -188,8 +233,8 @@ export class AppController {
|
|
|
type: 'created',
|
|
type: 'created',
|
|
|
taskId: task.id,
|
|
taskId: task.id,
|
|
|
task: 'handbrake',
|
|
task: 'handbrake',
|
|
|
- input: fileRecord.input,
|
|
|
|
|
- output: fileRecord.output,
|
|
|
|
|
|
|
+ input: file,
|
|
|
|
|
+ output: output,
|
|
|
preset: processingPreset,
|
|
preset: processingPreset,
|
|
|
});
|
|
});
|
|
|
|
|
|