Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bc 5170 no preview for larger files #4457

Merged
merged 43 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1d5ff37
BC-5170 - wip v1
SevenWaysDP Oct 5, 2023
46203c9
BC-5170 - wip v2
SevenWaysDP Oct 5, 2023
cd1ddfc
Merge branch 'main' into BC-5170-no-preview-for-larger-files
SevenWaysDP Oct 6, 2023
2c73716
Adjust tests in file storage service and uc
bischofmax Oct 9, 2023
8b7c957
Fix imports of testmodules
bischofmax Oct 9, 2023
13a53c3
BC-5170 - fix api tests
SevenWaysDP Oct 9, 2023
ec15838
BC-5170 - add test + code review
SevenWaysDP Oct 9, 2023
97daebc
Merge remote-tracking branch 'origin/main' into BC-5170-no-preview-fo…
SevenWaysDP Oct 11, 2023
c8999a4
BC-5170 devops code review
SevenWaysDP Oct 11, 2023
9b2708b
Merge branch 'main' into BC-5170-no-preview-for-larger-files
SevenWaysDP Oct 12, 2023
37bfd65
BC-5170 - code review
SevenWaysDP Oct 13, 2023
75cb61c
BC-5170 - rename method
SevenWaysDP Oct 13, 2023
7565814
BC-5170 - change logger
SevenWaysDP Oct 13, 2023
d609e9b
BC-5170 - add configmap
SevenWaysDP Oct 13, 2023
1f4ab96
fixup! BC-5170 - add configmap
SevenWaysDP Oct 13, 2023
6bad348
fixup! fixup! BC-5170 - add configmap
SevenWaysDP Oct 13, 2023
1c63d61
BC-5170 - remove required envs
SevenWaysDP Oct 13, 2023
c827105
BC-5170 - add scaled object
SevenWaysDP Oct 13, 2023
5939d0e
Merge branch 'main' into BC-5170-no-preview-for-larger-files
SevenWaysDP Oct 13, 2023
9bda5ae
BC-5170 code review
SevenWaysDP Oct 13, 2023
9af1a5a
Merge remote-tracking branch 'origin/BC-5170-no-preview-for-larger-fi…
SevenWaysDP Oct 13, 2023
24d1440
BC-5170 - code review
SevenWaysDP Oct 14, 2023
ceef528
Merge remote-tracking branch 'origin/main' into BC-5170-no-preview-fo…
SevenWaysDP Oct 23, 2023
25da0bd
BC-5170 - fix tests
SevenWaysDP Oct 23, 2023
cebb08b
BC-5170 - code review
SevenWaysDP Oct 23, 2023
2f3f7fd
Merge remote-tracking branch 'origin/main' into BC-5170-no-preview-fo…
SevenWaysDP Oct 23, 2023
711d1d6
BC-5170 - fix tests
SevenWaysDP Oct 24, 2023
5e05e10
BC-5170 - fix lintner
SevenWaysDP Oct 24, 2023
1623cd5
BC-5170 - change keda config
SevenWaysDP Oct 24, 2023
36e4137
BC-5170 - code review
SevenWaysDP Oct 24, 2023
da6cd81
Update ansible/roles/schulcloud-server-core/tasks/main.yml
SevenWaysDP Oct 25, 2023
588e022
Update ansible/roles/schulcloud-server-core/tasks/main.yml
SevenWaysDP Oct 25, 2023
634db78
Update ansible/roles/schulcloud-server-core/tasks/main.yml
SevenWaysDP Oct 25, 2023
26563ed
Update ansible/roles/schulcloud-server-core/tasks/main.yml
SevenWaysDP Oct 25, 2023
6966569
Update ansible/roles/schulcloud-server-core/templates/preview-generat…
SevenWaysDP Oct 25, 2023
20f5164
Merge remote-tracking branch 'origin/main' into BC-5170-no-preview-fo…
SevenWaysDP Oct 25, 2023
bfc70c9
BC-5170 - code review
SevenWaysDP Oct 25, 2023
bebde5c
Update ansible/roles/schulcloud-server-core/templates/preview-generat…
SevenWaysDP Oct 25, 2023
44e0eaf
BC-5170 - add label
SevenWaysDP Oct 25, 2023
4ebdb1d
BC-5170 - add configs
SevenWaysDP Oct 26, 2023
96989b2
BC-5170 - code review
SevenWaysDP Oct 26, 2023
a5f0fb0
BC-5170 - change logic for file name
SevenWaysDP Oct 26, 2023
5ea34cc
BC-5170 - because Cedric wishs ;o)
SevenWaysDP Oct 26, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -783,4 +783,38 @@ describe('FileRecord Entity', () => {
});
});
});

describe('fileNameWithoutExtension is called', () => {
describe('WHEN file name has extension', () => {
const setup = () => {
const fileRecord = fileRecordFactory.build({ name: 'file-name.jpg' });

return { fileRecord };
};

it('should return the correct file name without extension', () => {
const { fileRecord } = setup();

const result = fileRecord.fileNameWithoutExtension;

expect(result).toEqual('file-name');
});
});

describe('WHEN file name has not extension', () => {
const setup = () => {
const fileRecord = fileRecordFactory.build({ name: 'file-name' });

return { fileRecord };
};

it('should return the correct file name without extension', () => {
const { fileRecord } = setup();

const result = fileRecord.fileNameWithoutExtension;

expect(result).toEqual('file-name');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,10 @@ export class FileRecord extends BaseEntityWithTimestamps {

return PreviewStatus.PREVIEW_NOT_POSSIBLE_SCAN_STATUS_ERROR;
}

public get fileNameWithoutExtension(): string {
const fileNameWithoutExtension = this.name.split('.')[0];
Copy link
Contributor

@CeEv CeEv Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das kann auch ein undefined zurück liefern, wenn nach dem Split in [0] nichts vorhanden ist.
Wenn es schon nicht behandelt wird, dann müsste zumindest der return Wert string | undefined sein.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nein? Wir haben immer ein string im name auch wenn das leer ist wird zu ""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im spec ist auch ein test dazu

Copy link
Contributor

@CeEv CeEv Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stimmt das liefert immer "" zurück.
Nur ".bild.123.jpg" als Test hinfügen und sollte dann ".bild.123" zurück liefern.


return fileNameWithoutExtension;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ describe('File Record Helper', () => {

expect(result).toEqual('jpeg');
});

it('should throw error', () => {
const mimeType = 'image';

expect(() => getFormat(mimeType)).toThrowError(`could not get format from mime type: ${mimeType}`);
});
});

describe('getPreviewName is called', () => {
Expand All @@ -116,7 +122,7 @@ describe('File Record Helper', () => {
expect(result).toEqual(fileRecord.name);
});

it('should return preview name', () => {
it('should return preview name with format', () => {
const { fileRecord, outputFormat } = setup();

const result = getPreviewName(fileRecord, outputFormat);
Expand Down
14 changes: 10 additions & 4 deletions apps/server/src/modules/files-storage/helper/file-record.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { InternalServerErrorException } from '@nestjs/common';
import { FileRecordParams } from '../controller/dto';
import { FileRecord } from '../entity';
import { PreviewOutputMimeTypes } from '../interface';
Expand Down Expand Up @@ -43,17 +44,22 @@ export function createFileRecord(
export function getFormat(mimeType: string): string {
const format = mimeType.split('/')[1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validation fehlt ...was ist wenn [0] bzw. [1] undefined ist Das muss behandelt werden.


if (!format) {
throw new InternalServerErrorException(`could not get format from mime type: ${mimeType}`);
}

return format;
}

export function getPreviewName(fileRecord: FileRecord, outputFormat?: PreviewOutputMimeTypes): string {
const { fileNameWithoutExtension, name } = fileRecord;

if (!outputFormat) {
return fileRecord.name;
return name;
}

const fileNameWithoutExtension = fileRecord.name.split('.')[0];
const format = getFormat(outputFormat);
const name = `${fileNameWithoutExtension}.${format}`;
const previewFileName = `${fileNameWithoutExtension}.${format}`;

return name;
return previewFileName;
}
Loading