Skip to content

Commit

Permalink
refactor(project): limit size of audio files in favor for better stab…
Browse files Browse the repository at this point in the history
…ility
  • Loading branch information
julianpoemp committed Nov 12, 2024
1 parent 8603490 commit 361dd37
Show file tree
Hide file tree
Showing 128 changed files with 67 additions and 12,572 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ deploy
/deploy.sh
/typedocs

vite.config.*.timestamp*
vite.config.*.timestamp*
/tests/testfiles
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
[ngbPopover]="file.warning"
style="font-size: 16px; color: orange"
></i>
} @if (file.name.indexOf('.wav') < 0) { @if (file.status === 'progress')
{
} @if (file.status === 'waiting') {
<div
class="spinner-border icon-wait"
role="status"
style="width: 16px; height: 16px; border-width: 2px; color: gray"
>
<span class="visually-hidden">Loading...</span>
</div>
} } @if ( file.name.indexOf('.wav') > -1 && file.status === 'progress' )
} @else if (file.name.indexOf(".wav") < 0 && file.status === "progress")
{
<i class="bi bi-building-gear"></i>
} @if ( file.name.indexOf('.wav') > -1 && file.status === 'progress' ) {
<div class="progress">
<div
class="progress-bar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, Input, ViewChild } from '@angular/core';
import { AppInfo } from '../../../app.info';
import { DropZoneComponent } from '../drop-zone';
import { OctraModalService } from '../../modals/octra-modal.service';
import { contains, FileSize, getFileSize } from '@octra/utilities';
import { contains, escapeRegex, FileSize, getFileSize } from '@octra/utilities';
import { FileProgress } from '../../obj/objects';
import {
AnnotationLevelType,
Expand Down Expand Up @@ -72,7 +72,7 @@ export class OctraDropzoneComponent extends DefaultComponent {
const files = fileListToArray(this.dropzone.files!);
for (const file of files) {
const fileProcess: FileProgress = {
status: 'progress',
status: 'waiting',
name: file.name,
file,
type: file.type,
Expand All @@ -82,6 +82,10 @@ export class OctraDropzoneComponent extends DefaultComponent {
error: '',
};

const supportedAudioFormats = [
...AppInfo.audioformats.map((a) => a.supportedFormats),
].flat();

if (AudioManager.isValidAudioFileName(file.name, AppInfo.audioformats)) {
// the latest dropped file is an audio file
this.resetFormatFileProgresses();
Expand All @@ -90,29 +94,38 @@ export class OctraDropzoneComponent extends DefaultComponent {
this.dropFiles('audio');
this._oaudiofile = undefined;

this._files.push(fileProcess);
const formatLimitation = supportedAudioFormats.find((a) =>
file.name.includes(a.extension)
);

this.subscriptionManager.add(
readFile<ArrayBuffer>(file, 'arraybuffer').subscribe({
next: (a) => {
fileProcess.progress = a.progress;

if (a.progress === 1) {
if (file.size <= AppInfo.maxAudioFileSize * 1024 * 1024) {
this.decodeArrayBuffer(a.result!, this._files.length - 1);
} else {
fileProcess.status = 'invalid';
fileProcess.error = `The file size is bigger than ${AppInfo.maxAudioFileSize} MB.`;
this._files.push(fileProcess);
fileProcess.status = 'progress';
if (formatLimitation && file.size <= formatLimitation.maxFileSize) {
this.subscriptionManager.add(
readFile<ArrayBuffer>(file, 'arraybuffer').subscribe({
next: (a) => {
fileProcess.progress = a.progress;

if (a.progress === 1) {
if (file.size <= AppInfo.maxAudioFileSize * 1024 * 1024) {
this.decodeArrayBuffer(a.result!, this._files.length - 1);
} else {
fileProcess.status = 'invalid';
fileProcess.error = `The file size is bigger than ${AppInfo.maxAudioFileSize} MB.`;
}
}
}
},
})
);
},
})
);
} else {
fileProcess.status = 'invalid';
fileProcess.error = 'File size is invalid.';
}
break;
} else {
this.dropFiles('transcript');
this._files.push(fileProcess);

fileProcess.error = 'progress';
this.subscribe(readFile<string>(file, 'text', 'utf-8'), {
next: (a) => {
fileProcess.progress = a.progress;
Expand All @@ -134,10 +147,9 @@ export class OctraDropzoneComponent extends DefaultComponent {
for (let i = 0; i < AppInfo.converters.length; i++) {
const converter: Converter = AppInfo.converters[i];
if (
contains(
fileProgress.name.toLowerCase(),
AppInfo.converters[i].extension.toLowerCase()
)
new RegExp(`${escapeRegex(converter.extension)}$`).exec(
fileProgress.name.toLowerCase()
) !== null
) {
if (converter.conversion.import) {
const ofile: IFile = {
Expand Down Expand Up @@ -276,6 +288,9 @@ export class OctraDropzoneComponent extends DefaultComponent {
this._files.push(audioProcess);
} else {
await setAnnotation();
if (this._oannotation) {
break;
}
}

fileProgress.checked_converters++;
Expand All @@ -285,6 +300,11 @@ export class OctraDropzoneComponent extends DefaultComponent {
} else {
fileProgress.checked_converters++;
}

if (converter.name === 'AnnotJSON') {
// stop because there is only one file format with ending "_annot.json"
break;
}
}
if (
fileProgress.checked_converters === AppInfo.converters.length &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ <h4>{{ 'modal.supported.audio files' | transloco }}:</h4>
@for (extension of format.supportedFormats; track extension) {
<tr>
<td>
*{{extension.extension}}
*{{extension.extension}} @if(extension.extension === ".wav") {
<span class="pill rounded-pill bg-success text-light px-2 py-1" style="font-size: 0.85rem;">{{"g.recommended" | transloco}}</span>
}
</td>
<td>
max. {{extension.maxFileSize | filesize}}
Expand Down
2 changes: 1 addition & 1 deletion apps/octra/src/app/core/obj/objects.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Converter } from '@octra/annotation';

export interface FileProgress {
status: 'progress' | 'valid' | 'invalid';
status: 'progress' | 'valid' | 'invalid' | "waiting";
name: string;
type: string;
size: number;
Expand Down
3 changes: 2 additions & 1 deletion apps/octra/src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@
"validation": "Validierung",
"wanted": "Gesucht wird",
"website": "Webseite",
"yes": "Ja"
"yes": "Ja",
"recommended": "empfohlen"
},
"interfaces": {
"2D editor": "2D-Editor",
Expand Down
3 changes: 2 additions & 1 deletion apps/octra/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@
"validation": "Validation",
"wanted": "Wanted",
"website": "Website",
"yes": "Yes"
"yes": "Yes",
"recommended": "recommended"
},
"interfaces": {
"2D editor": "2D-Editor",
Expand Down
3 changes: 2 additions & 1 deletion apps/octra/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"noPropertyAccessFromIndexSignature": false,
"noImplicitReturns": false,
"noFallthroughCasesInSwitch": false,
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true
},
"files": [],
"include": [],
Expand Down
8 changes: 4 additions & 4 deletions libs/assets/src/lib/schemata/inputs_outputs.set.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"inputs": {
"name": "One audio file (*.wav / *.ogg / *.mp3 / *.flac / *.m4a) and one optional transcript file.",
"description": "Needs an audio file (.wav <= 1.9 GB) and an optional supported transcript file",
"name": "audio with optional transcript",
"description": "One audio file (*.wav / *.ogg / *.mp3 / *.flac / *.m4a) and one optional transcript file.",
"combine": {
"type": "and",
"expressions": [
Expand All @@ -16,8 +16,8 @@
"extension": [".wav"]
},
{
"size": "<= 300MB",
"extension": [".mp3", ".m4a", ".flac", ".ogg"]
"size": "<= 100MB",
"extension": [".mp3", ".m4a", ".mp3", ".flac"]
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ export class MusicMetadataFormat extends AudioFormat {
this._supportedFormats = [
{
extension: '.flac',
maxFileSize: 300000000, // 300 MB,
maxFileSize: 100000000, // 300 MB,
info: 'The duration in samples is going to be estimated and may differ with the used application.',
},
{
extension: '.ogg',
maxFileSize: 300000000, // 300 MB
maxFileSize: 100000000, // 300 MB
},
{
extension: '.mp3',
maxFileSize: 300000000, // 300 MB,
maxFileSize: 100000000, // 300 MB,
info: 'The duration in samples is going to be estimated and may differ with the used application.',
},
{
extension: '.m4a',
maxFileSize: 300000000, // 300 MB,
maxFileSize: 100000000, // 300 MB,
info: 'The duration in samples is going to be estimated and may differ with the used application.',
},
];
Expand Down
7 changes: 0 additions & 7 deletions pdfconverter/Converter.php

This file was deleted.

44 changes: 0 additions & 44 deletions pdfconverter/GuidelinesConverter.php

This file was deleted.

Loading

0 comments on commit 361dd37

Please sign in to comment.