Skip to content
Merged
Changes from all commits
Commits
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
47 changes: 4 additions & 43 deletions src/app/core/_datasources/hashes.datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { catchError, finalize, of } from 'rxjs';
import { JHash } from '@models/hash.model';
import { Filter, FilterType } from '@models/request-params.model';
import { ResponseWrapper } from '@models/response.model';
import { JTask } from '@models/task.model';

import { JsonAPISerializer } from '@services/api/serializer-service';
import { SERV } from '@services/main.config';
Expand All @@ -27,59 +26,21 @@ export class HashesDataSource extends BaseDataSource<JHash> {
this.loading = true;

if (this._dataType === 'tasks') {
const paramsTasks = new RequestParamBuilder().addInitial(this).addInclude('hashlist');
if (query) {
paramsTasks.addFilter(query);
}
const taskService = this.service.get(SERV.TASKS, this._id, paramsTasks.create());
const hashesService = this.service.ghelper(SERV.HELPER, 'getCracksOfTask?task=' + this._id);

this.subscriptions.push(
taskService
hashesService
.pipe(
catchError(() => of([])),
finalize(() => (this.loading = false))
)
.subscribe((response: ResponseWrapper) => {
const task = new JsonAPISerializer().deserialize<JTask>({
const hashes = new JsonAPISerializer().deserialize<JHash[]>({
data: response.data,
included: response.included
});

const hashlistId = task.hashlist.id;

const paramsHashlist = new RequestParamBuilder()
.addInitial(this)
.addInclude('hashlist')
.addFilter({ field: 'hashlistId', operator: FilterType.EQUAL, value: hashlistId })
.addFilter({ field: 'isCracked', operator: FilterType.EQUAL, value: true })
.addFilter({ field: 'hashlistId', operator: FilterType.EQUAL, value: hashlistId });
if (query) {
paramsHashlist.addFilter(query);
}
const hashlistService = this.service.getAll(SERV.HASHES, paramsHashlist.create());

this.subscriptions.push(
hashlistService
.pipe(
catchError(() => of([])),
finalize(() => (this.loading = false))
)
.subscribe((responseHash: ResponseWrapper) => {
const hashes = new JsonAPISerializer().deserialize<JHash[]>({
data: responseHash.data,
included: responseHash.included
});

const length = responseHash.meta.page.total_elements;
const nextLink = responseHash.links.next;
const prevLink = responseHash.links.prev;
const after = nextLink ? new URL(nextLink).searchParams.get('page[after]') : null;
const before = prevLink ? new URL(prevLink).searchParams.get('page[before]') : null;

this.setPaginationConfig(this.pageSize, length, after, before, this.index);
this.setData(hashes);
})
);
this.setData(hashes);
})
);
} else {
Expand Down
Loading