File tree 4 files changed +12
-27
lines changed
4 files changed +12
-27
lines changed Original file line number Diff line number Diff line change @@ -6,5 +6,5 @@ export abstract class FileHandler {
6
6
* Loads the content of the given file and stores it in the store.
7
7
* @param file File to handle
8
8
*/
9
- public abstract handleFile ( file : Blob ) : Promise < any >
9
+ public abstract handleFile ( file : Blob ) : Promise < void >
10
10
}
Original file line number Diff line number Diff line change @@ -5,19 +5,13 @@ import { FileHandler } from './FileHandler'
5
5
* Class for handling single json files.
6
6
*/
7
7
export class JsonFileHandler extends FileHandler {
8
- public async handleFile (
9
- file : Blob
10
- ) : Promise < { fileType : 'overview' } | { fileType : 'comparison' ; id1 : string ; id2 : string } > {
8
+ public async handleFile ( file : Blob ) {
11
9
const content = await file . text ( )
12
10
const json = JSON . parse ( content )
13
11
14
12
store ( ) . setSingleFileRawContent ( content )
15
- if ( json [ 'submission_folder_path' ] ) {
16
- return { fileType : 'overview' }
17
- } else if ( json [ 'id1' ] && json [ 'id2' ] ) {
18
- return { fileType : 'comparison' , id1 : json [ 'id1' ] , id2 : json [ 'id2' ] }
19
- } else {
20
- throw new Error ( `Invalid JSON: ${ json } ` )
13
+ if ( ! json [ 'submission_folder_path' ] ) {
14
+ throw new Error ( `Invalid JSON: File is not an overview file.` )
21
15
}
22
16
}
23
17
}
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { FileHandler } from './FileHandler'
7
7
* Class for handling zip files.
8
8
*/
9
9
export class ZipFileHandler extends FileHandler {
10
- public async handleFile ( file : Blob ) : Promise < void > {
10
+ public async handleFile ( file : Blob ) {
11
11
console . log ( 'Start handling zip file and storing necessary data...' )
12
12
return jszip . loadAsync ( file ) . then ( async ( zip ) => {
13
13
for ( const originalFileName of Object . keys ( zip . files ) ) {
Original file line number Diff line number Diff line change @@ -107,32 +107,23 @@ function navigateToOverview() {
107
107
})
108
108
}
109
109
110
- function navigateToComparisonView(firstId: string, secondId: string) {
111
- router.push({
112
- name: 'ComparisonView',
113
- params: {
114
- firstId,
115
- secondId
116
- }
117
- })
118
- }
119
-
120
110
/**
121
111
* Handles a json file on drop. It read the file and passes the file string to next window.
122
112
* @param file The json file to handle
123
113
*/
124
114
async function handleJsonFile(file: Blob) {
115
+ try {
116
+ await new JsonFileHandler().handleFile(file)
117
+ } catch (e) {
118
+ registerError(e as Error, 'upload')
119
+ return
120
+ }
125
121
store().setLoadingType({
126
122
local: false,
127
123
zip: false,
128
124
single: true
129
125
})
130
- const fileContentType = await new JsonFileHandler().handleFile(file)
131
- if (fileContentType.fileType === 'overview') {
132
- navigateToOverview()
133
- } else if (fileContentType.fileType === 'comparison') {
134
- navigateToComparisonView(fileContentType.id1, fileContentType.id2)
135
- }
126
+ navigateToOverview()
136
127
}
137
128
138
129
/**
You can’t perform that action at this time.
0 commit comments