-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcapture-details.ts
More file actions
77 lines (60 loc) · 1.73 KB
/
capture-details.ts
File metadata and controls
77 lines (60 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { UserPermission } from 'utils/user/types'
import { Capture, ServerCapture } from './capture'
import { Job } from './job'
export type ServerCaptureDetails = ServerCapture & any // TODO: Update this type
export class CaptureDetails extends Capture {
private readonly _jobs: Job[] = []
public constructor(capture: ServerCaptureDetails) {
super(capture)
if (this._capture.jobs) {
this._jobs = this._capture.jobs.map((job: any) => new Job(job))
}
}
get currentIndex(): number | undefined {
return this._capture.event_current_capture_index
}
get currentJob(): Job | undefined {
if (!this._jobs.length) {
return
}
return this._jobs.sort((j1: Job, j2: Job) => {
const time1 = j1.updatedAt?.getTime() ?? 0
const time2 = j2.updatedAt?.getTime() ?? 0
return time2 - time1
})[0]
}
get hasJobInProgress(): boolean {
return this._jobs.some(
(job) =>
job.status.code === 'CREATED' ||
job.status.code === 'PENDING' ||
job.status.code === 'STARTED'
)
}
get isStarred(): boolean {
return this._capture.collections?.some(
(collection: any) => collection.method === 'starred'
)
}
get jobs(): Job[] {
return this._jobs
}
get nextCaptureId(): string | undefined {
return this._capture.event_next_capture_id
}
get prevCaptureId(): string | undefined {
return this._capture.event_prev_capture_id
}
get sizeLabel(): string {
return `${this._capture.size_display}`
}
get totalCaptures(): number | undefined {
return this._capture.event_total_captures
}
get url(): string {
return this._capture.url
}
get userPermissions(): UserPermission[] {
return this._capture.user_permissions
}
}