Skip to content

Commit

Permalink
+ Update
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesCodesUFG committed Jan 29, 2025
1 parent 2585a8d commit 7187816
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 30 deletions.
37 changes: 9 additions & 28 deletions client/src/app/@core/services/analysis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export class AnalysisService {
return this.httpClient
.get<any>(`${environment.TASK_API}/result/${token}`)
.pipe(map((response) => response))
.pipe(catchError(this.errorHandler));
}

// TODO: Verificação do recaptcha.
Expand Down Expand Up @@ -60,43 +59,25 @@ export class AnalysisService {
map((response: any) => {
if (response == null) throw new Error('Erro');

console.log(response);

return response;
})
)
.pipe(catchError(this.errorHandler));
);
}

// TODO: Verificação do recaptcha.
public saveFile(file, user: UserInfo, recaptcha) {
public saveFile(file, user: UserInfo, recaptcha: string) {
const formData = new FormData();

formData.append('files', file, file.name);
formData.append('name', encodeURIComponent(user.name));
formData.append('email', encodeURIComponent(user.email));

return this.httpClient.post<any>(
`${this.apiURL}/savefile`,
formData
)
.pipe(
map((response: any) => {
// TODO: Retornar response_code e msg para o cliente.
})
)
.pipe(catchError(this.errorHandler));
}

errorHandler(error: any) {
let errorMessage = '';

if (error.error instanceof ErrorEvent) {
errorMessage = error.error.message;
} else if (typeof error.error == 'string') {
errorMessage = error.error;
} else {
errorMessage = `Message: ${error.message}`;
}

return throwError(errorMessage);
return this.httpClient.post<any>(`${this.apiURL}/savefile`, formData).pipe(
map((response: any) => {
console.log(response);
})
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ export class FileUploadComponent {
if (input.files === null || input.files.length <= 0) return;

this.userInfo.getUserInfo().subscribe({
next: (userInfo: UserInfo) => this.uploadFile(input.files![0], userInfo),
next: (userInfo: UserInfo) => {
this.uploadFile(input.files![0], userInfo);

this.reset(input)
},
});
}

Expand All @@ -86,10 +90,15 @@ export class FileUploadComponent {
.subscribe((recaptcha: string) => {
this.analysisService
.saveFile(file, user, recaptcha).subscribe((response) => {
// TODO: Avisar ao usuário que o token foi enviado para o e-mail.
console.log(response)
});
});
}

private reset(input) {
input.value = '';
input.files = null;
}
}

export interface FileUploadModel {
Expand Down

0 comments on commit 7187816

Please sign in to comment.