77 lines
3.1 KiB
JavaScript
77 lines
3.1 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.getAllJobs = getAllJobs;
|
|
exports.getJob = getJob;
|
|
exports.createJob = createJob;
|
|
exports.updateJobStatus = updateJobStatus;
|
|
exports.saveCheckpoint = saveCheckpoint;
|
|
exports.saveJobOutputs = saveJobOutputs;
|
|
exports.deleteJob = deleteJob;
|
|
exports.getConfigValue = getConfigValue;
|
|
exports.setConfigValue = setConfigValue;
|
|
exports.getAllConfig = getAllConfig;
|
|
const db_1 = require("../db");
|
|
const uuid_1 = require("uuid");
|
|
function getAllJobs() {
|
|
const db = (0, db_1.getDb)();
|
|
return db.prepare('SELECT * FROM jobs ORDER BY created_at DESC').all();
|
|
}
|
|
function getJob(id) {
|
|
const db = (0, db_1.getDb)();
|
|
return db.prepare('SELECT * FROM jobs WHERE id = ?').get(id);
|
|
}
|
|
function createJob(videoPath, filename, config, outputOptions) {
|
|
const db = (0, db_1.getDb)();
|
|
const id = (0, uuid_1.v4)();
|
|
const now = new Date().toISOString();
|
|
db.prepare(`
|
|
INSERT INTO jobs (id, video_path, video_filename, config, output_options, created_at, updated_at)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
`).run(id, videoPath, filename, JSON.stringify(config), JSON.stringify(outputOptions), now, now);
|
|
return getJob(id);
|
|
}
|
|
function updateJobStatus(id, status, error) {
|
|
const db = (0, db_1.getDb)();
|
|
const now = new Date().toISOString();
|
|
const completedAt = status === 'completed' ? now : null;
|
|
db.prepare(`
|
|
UPDATE jobs SET status = ?, error = ?, updated_at = ?, completed_at = ? WHERE id = ?
|
|
`).run(status, error || null, now, completedAt, id);
|
|
}
|
|
function saveCheckpoint(id, segments, currentIndex, totalUnits, currentTimePosition, lastContext, progress) {
|
|
const db = (0, db_1.getDb)();
|
|
const now = new Date().toISOString();
|
|
db.prepare(`
|
|
UPDATE jobs SET segments = ?, current_index = ?, total_units = ?, current_time_position = ?, last_context = ?, progress = ?, updated_at = ? WHERE id = ?
|
|
`).run(segments, currentIndex, totalUnits, currentTimePosition, lastContext, progress, now, id);
|
|
}
|
|
function saveJobOutputs(id, outputs) {
|
|
const db = (0, db_1.getDb)();
|
|
const now = new Date().toISOString();
|
|
db.prepare(`
|
|
UPDATE jobs SET output_audio = ?, output_subtitles_srt = ?, output_subtitles_vtt = ?, output_muxed = ?, updated_at = ? WHERE id = ?
|
|
`).run(outputs.audio || null, outputs.subtitlesSrt || null, outputs.subtitlesVtt || null, outputs.muxed || null, now, id);
|
|
}
|
|
function deleteJob(id) {
|
|
const db = (0, db_1.getDb)();
|
|
db.prepare('DELETE FROM jobs WHERE id = ?').run(id);
|
|
}
|
|
function getConfigValue(key) {
|
|
const db = (0, db_1.getDb)();
|
|
const row = db.prepare('SELECT value FROM config WHERE key = ?').get(key);
|
|
return row?.value;
|
|
}
|
|
function setConfigValue(key, value) {
|
|
const db = (0, db_1.getDb)();
|
|
db.prepare('INSERT OR REPLACE INTO config (key, value) VALUES (?, ?)').run(key, value);
|
|
}
|
|
function getAllConfig() {
|
|
const db = (0, db_1.getDb)();
|
|
const rows = db.prepare('SELECT key, value FROM config').all();
|
|
const config = {};
|
|
for (const row of rows) {
|
|
config[row.key] = row.value;
|
|
}
|
|
return config;
|
|
}
|
|
//# sourceMappingURL=jobStore.js.map
|