Software: Apache. PHP/8.1.30 uname -a: Linux server1.tuhinhossain.com 5.15.0-163-generic #173-Ubuntu SMP Tue Oct 14 17:51:00 UTC uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root) Safe-mode: OFF (not secure) /home/picotech/domains/note.picotech.app/public_html/src/models/ drwxr-xr-x | |
| Viewing file: Select action/file-type: const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
const AudioChunk = sequelize.define('AudioChunk', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
recording_id: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'recordings',
key: 'id',
},
onDelete: 'CASCADE',
},
chunk_index: {
type: DataTypes.INTEGER,
allowNull: false,
comment: 'Index of the chunk in the sequence (0-based)',
},
file_path: {
type: DataTypes.STRING(500),
allowNull: false,
validate: {
notEmpty: true,
},
},
file_name: {
type: DataTypes.STRING(255),
allowNull: false,
validate: {
notEmpty: true,
},
},
start_time: {
type: DataTypes.INTEGER,
allowNull: false,
comment: 'Start time in milliseconds from the beginning of the recording',
},
end_time: {
type: DataTypes.INTEGER,
allowNull: false,
comment: 'End time in milliseconds from the beginning of the recording',
},
duration: {
type: DataTypes.INTEGER,
allowNull: false,
comment: 'Duration of this chunk in milliseconds',
},
file_size: {
type: DataTypes.BIGINT,
allowNull: false,
comment: 'File size in bytes',
validate: {
min: 0,
},
},
status: {
type: DataTypes.ENUM('pending', 'processing', 'completed', 'failed'),
defaultValue: 'pending',
allowNull: false,
},
transcription_status: {
type: DataTypes.ENUM('pending', 'processing', 'completed', 'failed'),
defaultValue: 'pending',
allowNull: false,
},
error_message: {
type: DataTypes.TEXT,
allowNull: true,
comment: 'Error message if processing failed',
},
checksum: {
type: DataTypes.STRING(64),
allowNull: true,
comment: 'File checksum for integrity verification',
},
transcription_data: {
type: DataTypes.TEXT,
allowNull: true,
comment: 'JSON string containing transcription data for this chunk',
},
}, {
tableName: 'audio_chunks',
timestamps: true,
indexes: [
{
fields: ['recording_id'],
},
{
fields: ['recording_id', 'chunk_index'],
unique: true,
},
{
fields: ['status'],
},
{
fields: ['transcription_status'],
},
],
});
// Instance methods
AudioChunk.prototype.getFileExtension = function() {
const path = require('path');
return path.extname(this.file_name).toLowerCase();
};
AudioChunk.prototype.getDurationInSeconds = function() {
return Math.floor(this.duration / 1000);
};
AudioChunk.prototype.getDurationFormatted = function() {
const totalSeconds = this.getDurationInSeconds();
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
return `${minutes}:${seconds.toString().padStart(2, '0')}`;
};
AudioChunk.prototype.getFileSizeFormatted = function() {
const bytes = this.file_size;
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
};
AudioChunk.prototype.isProcessed = function() {
return this.status === 'completed';
};
AudioChunk.prototype.canBeTranscribed = function() {
return this.status === 'completed' &&
['pending', 'failed'].includes(this.transcription_status);
};
AudioChunk.prototype.markAsCompleted = async function() {
this.status = 'completed';
return this.save();
};
AudioChunk.prototype.markAsFailed = async function(errorMessage) {
this.status = 'failed';
this.error_message = errorMessage;
return this.save();
};
AudioChunk.prototype.updateTranscriptionStatus = async function(status, errorMessage = null) {
this.transcription_status = status;
if (errorMessage) {
this.error_message = errorMessage;
}
return this.save();
};
AudioChunk.prototype.deleteFile = async function() {
const fs = require('fs').promises;
try {
await fs.unlink(this.file_path);
this.status = 'deleted';
await this.save();
return true;
} catch (error) {
console.error('Error deleting chunk file:', error);
return false;
}
};
// Class methods
AudioChunk.findByRecording = function(recordingId, options = {}) {
return this.findAll({
where: {
recording_id: recordingId,
...options.where,
},
order: options.order || [['chunk_index', 'ASC']],
...options,
});
};
AudioChunk.findPendingTranscription = function(limit = 10) {
return this.findAll({
where: {
status: 'completed',
transcription_status: 'pending',
},
order: [['created_at', 'ASC']],
limit,
});
};
AudioChunk.findByStatus = function(status, options = {}) {
return this.findAll({
where: {
status,
...options.where,
},
order: options.order || [['created_at', 'DESC']],
limit: options.limit,
});
};
AudioChunk.getTotalSizeByRecording = async function(recordingId) {
const result = await this.findOne({
where: {
recording_id: recordingId,
status: { [sequelize.Sequelize.Op.ne]: 'deleted' },
},
attributes: [
[sequelize.fn('SUM', sequelize.col('file_size')), 'total_size'],
],
raw: true,
});
return parseInt(result.total_size) || 0;
};
module.exports = AudioChunk; |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0037 ]-- |