-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathmodels.py
2845 lines (1905 loc) · 76.2 KB
/
models.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Crawl-related models and types
"""
from datetime import datetime
from enum import Enum, IntEnum
from uuid import UUID
import base64
import hashlib
import mimetypes
import os
from typing import Optional, List, Dict, Union, Literal, Any, get_args
from typing_extensions import Annotated
from pydantic import (
BaseModel,
Field,
HttpUrl as HttpUrlNonStr,
AnyHttpUrl as AnyHttpUrlNonStr,
EmailStr as CasedEmailStr,
validate_email,
RootModel,
BeforeValidator,
TypeAdapter,
)
from pathvalidate import sanitize_filename
# from fastapi_users import models as fastapi_users_models
from .db import BaseMongoModel
# crawl scale for constraint
MAX_CRAWL_SCALE = int(os.environ.get("MAX_CRAWL_SCALE", 3))
# Presign duration must be less than 604800 seconds (one week),
# so set this one minute short of a week
PRESIGN_MINUTES_MAX = 10079
PRESIGN_MINUTES_DEFAULT = PRESIGN_MINUTES_MAX
# Expire duration seconds for presigned urls
PRESIGN_DURATION_MINUTES = int(
os.environ.get("PRESIGN_DURATION_MINUTES") or PRESIGN_MINUTES_DEFAULT
)
PRESIGN_DURATION_SECONDS = min(PRESIGN_DURATION_MINUTES, PRESIGN_MINUTES_MAX) * 60
# Minimum part size for file uploads
MIN_UPLOAD_PART_SIZE = 10000000
# annotated types
# ============================================================================
EmptyStr = Annotated[str, Field(min_length=0, max_length=0)]
Scale = Annotated[int, Field(strict=True, ge=1, le=MAX_CRAWL_SCALE)]
ReviewStatus = Optional[Annotated[int, Field(strict=True, ge=1, le=5)]]
any_http_url_adapter = TypeAdapter(AnyHttpUrlNonStr)
AnyHttpUrl = Annotated[
str, BeforeValidator(lambda value: str(any_http_url_adapter.validate_python(value)))
]
http_url_adapter = TypeAdapter(HttpUrlNonStr)
HttpUrl = Annotated[
str, BeforeValidator(lambda value: str(http_url_adapter.validate_python(value)))
]
# pylint: disable=too-few-public-methods
class EmailStr(CasedEmailStr):
"""EmailStr type that lowercases the full email"""
@classmethod
def _validate(cls, value: CasedEmailStr, /) -> CasedEmailStr:
return validate_email(value)[1].lower()
# pylint: disable=invalid-name, too-many-lines
# ============================================================================
class UserRole(IntEnum):
"""User role"""
VIEWER = 10
CRAWLER = 20
OWNER = 40
SUPERADMIN = 100
# ============================================================================
### INVITES ###
# ============================================================================
class InvitePending(BaseMongoModel):
"""An invite for a new user, with an email and invite token as id"""
id: UUID
created: datetime
tokenHash: str
inviterEmail: EmailStr
fromSuperuser: Optional[bool] = False
oid: Optional[UUID] = None
role: UserRole = UserRole.VIEWER
email: Optional[EmailStr] = None
# set if existing user
userid: Optional[UUID] = None
# ============================================================================
class InviteOut(BaseModel):
"""Single invite output model"""
created: datetime
inviterEmail: Optional[EmailStr] = None
inviterName: Optional[str] = None
fromSuperuser: bool
oid: Optional[UUID] = None
orgName: Optional[str] = None
orgSlug: Optional[str] = None
role: UserRole = UserRole.VIEWER
email: Optional[EmailStr] = None
firstOrgAdmin: bool = False
# ============================================================================
class InviteRequest(BaseModel):
"""Request to invite another user"""
email: EmailStr
# ============================================================================
class InviteToOrgRequest(InviteRequest):
"""Request to invite another user to an organization"""
role: UserRole
# ============================================================================
class AddToOrgRequest(InviteRequest):
"""Request to add a new user to an organization directly"""
role: UserRole
password: str
name: str
# ============================================================================
class InviteAddedResponse(BaseModel):
"""Response for API endpoints that add resource and return id and name"""
added: bool
id: UUID
invited: str
token: UUID
# ============================================================================
### MAIN USER MODEL ###
# ============================================================================
class User(BaseModel):
"""
User Model
"""
id: UUID
name: str = ""
email: EmailStr
is_superuser: bool = False
is_verified: bool = False
hashed_password: str
def dict(self, *a, **kw):
"""ensure invites / hashed_password never serialize, just in case"""
exclude = kw.get("exclude") or set()
exclude.add("invites")
exclude.add("hashed_password")
return super().dict(*a, **kw)
# ============================================================================
class FailedLogin(BaseMongoModel):
"""
Failed login model
"""
attempted: datetime
email: str
# Consecutive failed logins, reset to 0 on successful login or after
# password is reset. On failed_logins >= 5 within the hour before this
# object is deleted, the user is unable to log in until they reset their
# password.
count: int = 1
# ============================================================================
class UserOrgInfoOut(BaseModel):
"""org per user"""
id: UUID
name: str
slug: str
default: bool
role: UserRole
# ============================================================================
class UserOut(BaseModel):
"""Output User model"""
id: UUID
name: str = ""
email: EmailStr
is_superuser: bool = False
is_verified: bool = False
orgs: List[UserOrgInfoOut]
# ============================================================================
class UserEmailWithOrgInfo(BaseModel):
"""Output model for getting user email list with org info for each"""
email: EmailStr
orgs: List[UserOrgInfoOut]
# ============================================================================
### CRAWL STATES
# ============================================================================
TYPE_RUNNING_STATES = Literal[
"running", "pending-wait", "generate-wacz", "uploading-wacz"
]
RUNNING_STATES = get_args(TYPE_RUNNING_STATES)
TYPE_WAITING_STATES = Literal["starting", "waiting_capacity", "waiting_org_limit"]
WAITING_STATES = get_args(TYPE_WAITING_STATES)
TYPE_FAILED_STATES = Literal[
"canceled",
"failed",
"skipped_storage_quota_reached",
"skipped_time_quota_reached",
]
FAILED_STATES = get_args(TYPE_FAILED_STATES)
TYPE_SUCCESSFUL_STATES = Literal[
"complete",
"stopped_by_user",
"stopped_storage_quota_reached",
"stopped_time_quota_reached",
"stopped_org_readonly",
]
SUCCESSFUL_STATES = get_args(TYPE_SUCCESSFUL_STATES)
TYPE_RUNNING_AND_WAITING_STATES = Literal[TYPE_WAITING_STATES, TYPE_RUNNING_STATES]
RUNNING_AND_WAITING_STATES = [*WAITING_STATES, *RUNNING_STATES]
RUNNING_AND_STARTING_ONLY = ["starting", *RUNNING_STATES]
TYPE_NON_RUNNING_STATES = Literal[TYPE_FAILED_STATES, TYPE_SUCCESSFUL_STATES]
NON_RUNNING_STATES = [*FAILED_STATES, *SUCCESSFUL_STATES]
TYPE_ALL_CRAWL_STATES = Literal[
TYPE_RUNNING_AND_WAITING_STATES, TYPE_NON_RUNNING_STATES
]
ALL_CRAWL_STATES = [*RUNNING_AND_WAITING_STATES, *NON_RUNNING_STATES]
# ============================================================================
### CRAWL CONFIGS ###
# ============================================================================
class JobType(str, Enum):
"""Job Types"""
URL_LIST = "url-list"
SEED_CRAWL = "seed-crawl"
CUSTOM = "custom"
# ============================================================================
class ScopeType(str, Enum):
"""Crawl scope type"""
PAGE = "page"
PAGE_SPA = "page-spa"
PREFIX = "prefix"
HOST = "host"
DOMAIN = "domain"
ANY = "any"
CUSTOM = "custom"
# ============================================================================
class Seed(BaseModel):
"""Crawl seed"""
url: HttpUrl
scopeType: Optional[ScopeType] = None
include: Union[str, List[str], None] = None
exclude: Union[str, List[str], None] = None
sitemap: Union[bool, HttpUrl, None] = None
allowHash: Optional[bool] = None
depth: Optional[int] = None
extraHops: Optional[int] = None
# ============================================================================
class RawCrawlConfig(BaseModel):
"""Base Crawl Config"""
seeds: Optional[List[Seed]] = []
scopeType: Optional[ScopeType] = ScopeType.PREFIX
include: Union[str, List[str], None] = None
exclude: Union[str, List[str], None] = None
depth: Optional[int] = -1
limit: Optional[int] = 0
extraHops: Optional[int] = 0
lang: Optional[str] = None
blockAds: Optional[bool] = False
behaviorTimeout: Optional[int] = None
pageLoadTimeout: Optional[int] = None
pageExtraDelay: Optional[int] = 0
postLoadDelay: Optional[int] = 0
workers: Optional[int] = None
headless: Optional[bool] = None
generateWACZ: Optional[bool] = None
combineWARC: Optional[bool] = None
useSitemap: Optional[bool] = False
failOnFailedSeed: Optional[bool] = False
logging: Optional[str] = None
behaviors: Optional[str] = "autoscroll,autoplay,autofetch,siteSpecific"
userAgent: Optional[str] = None
# ============================================================================
class CrawlConfigIn(BaseModel):
"""CrawlConfig input model, submitted via API"""
schedule: Optional[str] = ""
runNow: bool = False
config: RawCrawlConfig
name: str
description: Optional[str] = ""
jobType: Optional[JobType] = JobType.CUSTOM
profileid: Union[UUID, EmptyStr, None] = None
crawlerChannel: str = "default"
proxyId: Optional[str] = None
autoAddCollections: Optional[List[UUID]] = []
tags: Optional[List[str]] = []
crawlTimeout: int = 0
maxCrawlSize: int = 0
scale: Scale = 1
crawlFilenameTemplate: Optional[str] = None
# ============================================================================
class ConfigRevision(BaseMongoModel):
"""Crawl Config Revision"""
cid: UUID
schedule: Optional[str] = ""
config: RawCrawlConfig
profileid: Optional[UUID] = None
crawlerChannel: Optional[str] = None
proxyId: Optional[str] = None
crawlTimeout: Optional[int] = 0
maxCrawlSize: Optional[int] = 0
scale: Scale = 1
modified: datetime
modifiedBy: Optional[UUID] = None
rev: int = 0
# ============================================================================
class CrawlConfigCore(BaseMongoModel):
"""Core data shared between crawls and crawlconfigs"""
schedule: Optional[str] = ""
jobType: Optional[JobType] = JobType.CUSTOM
config: Optional[RawCrawlConfig] = None
tags: Optional[List[str]] = []
crawlTimeout: Optional[int] = 0
maxCrawlSize: Optional[int] = 0
scale: Scale = 1
oid: UUID
profileid: Optional[UUID] = None
crawlerChannel: Optional[str] = None
proxyId: Optional[str] = None
# ============================================================================
class CrawlConfigAdditional(BaseModel):
"""Additional fields shared by CrawlConfig and CrawlConfigOut."""
name: Optional[str] = None
description: Optional[str] = None
created: datetime
createdBy: Optional[UUID] = None
modified: Optional[datetime] = None
modifiedBy: Optional[UUID] = None
autoAddCollections: Optional[List[UUID]] = []
inactive: Optional[bool] = False
rev: int = 0
crawlAttemptCount: Optional[int] = 0
crawlCount: Optional[int] = 0
crawlSuccessfulCount: Optional[int] = 0
totalSize: Optional[int] = 0
lastCrawlId: Optional[str] = None
lastCrawlStartTime: Optional[datetime] = None
lastStartedBy: Optional[UUID] = None
lastCrawlTime: Optional[datetime] = None
lastCrawlState: Optional[str] = None
lastCrawlSize: Optional[int] = None
lastRun: Optional[datetime] = None
isCrawlRunning: Optional[bool] = False
crawlFilenameTemplate: Optional[str] = None
# ============================================================================
class CrawlConfig(CrawlConfigCore, CrawlConfigAdditional):
"""Schedulable config"""
id: UUID
config: RawCrawlConfig
createdByName: Optional[str] = None
modifiedByName: Optional[str] = None
lastStartedByName: Optional[str] = None
def get_raw_config(self):
"""serialize config for browsertrix-crawler"""
return self.config.dict(exclude_unset=True, exclude_none=True)
# ============================================================================
class CrawlConfigOut(CrawlConfigCore, CrawlConfigAdditional):
"""Crawl Config Output"""
id: UUID
lastCrawlStopping: Optional[bool] = False
profileName: Optional[str] = None
firstSeed: Optional[str] = None
seedCount: int = 0
createdByName: Optional[str] = None
modifiedByName: Optional[str] = None
lastStartedByName: Optional[str] = None
# ============================================================================
class CrawlConfigProfileOut(BaseMongoModel):
"""Crawl Config basic info for profiles"""
name: str
firstSeed: str
seedCount: int
# ============================================================================
class UpdateCrawlConfig(BaseModel):
"""Update crawl config name, crawl schedule, or tags"""
# metadata: not revision tracked
name: Optional[str] = None
tags: Optional[List[str]] = None
description: Optional[str] = None
autoAddCollections: Optional[List[UUID]] = None
runNow: bool = False
# crawl data: revision tracked
schedule: Optional[str] = None
profileid: Union[UUID, EmptyStr, None] = None
crawlerChannel: Optional[str] = None
proxyId: Optional[str] = None
crawlTimeout: Optional[int] = None
maxCrawlSize: Optional[int] = None
scale: Scale = 1
crawlFilenameTemplate: Optional[str] = None
config: Optional[RawCrawlConfig] = None
# ============================================================================
class CrawlConfigDefaults(BaseModel):
"""Crawl Config Org Defaults"""
crawlTimeout: Optional[int] = None
maxCrawlSize: Optional[int] = None
pageLoadTimeout: Optional[int] = None
postLoadDelay: Optional[int] = None
behaviorTimeout: Optional[int] = None
pageExtraDelay: Optional[int] = None
blockAds: Optional[bool] = None
profileid: Optional[UUID] = None
crawlerChannel: Optional[str] = None
proxyId: Optional[str] = None
lang: Optional[str] = None
userAgent: Optional[str] = None
exclude: Optional[List[str]] = None
# ============================================================================
class CrawlConfigAddedResponse(BaseModel):
"""Response model for adding crawlconfigs"""
added: bool
id: str
run_now_job: Optional[str] = None
storageQuotaReached: bool
execMinutesQuotaReached: bool
# ============================================================================
class CrawlConfigTags(BaseModel):
"""Response model for crawlconfig tags"""
tags: List[str]
# ============================================================================
class CrawlConfigSearchValues(BaseModel):
"""Response model for adding crawlconfigs"""
names: List[str]
descriptions: List[str]
firstSeeds: List[AnyHttpUrl]
workflowIds: List[UUID]
# ============================================================================
class CrawlConfigUpdateResponse(BaseModel):
"""Response model for updating crawlconfigs"""
updated: bool
settings_changed: bool
metadata_changed: bool
storageQuotaReached: Optional[bool] = False
execMinutesQuotaReached: Optional[bool] = False
started: Optional[str] = None
# ============================================================================
class CrawlConfigDeletedResponse(BaseModel):
"""Response model for deleting crawlconfigs"""
success: bool
status: str
# ============================================================================
### CRAWLER VERSIONS ###
# ============================================================================
class CrawlerChannel(BaseModel):
"""Crawler version available to use in workflows"""
id: str
image: str
# ============================================================================
class CrawlerChannels(BaseModel):
"""List of CrawlerChannel instances for API"""
channels: List[CrawlerChannel] = []
# ============================================================================
### PROXIES ###
class CrawlerProxy(BaseModel):
"""proxy definition"""
id: str
url: str
label: str
description: str = ""
country_code: str = ""
has_host_public_key: bool = False
has_private_key: bool = False
shared: bool = False
# ============================================================================
class CrawlerProxies(BaseModel):
"""List of CrawlerProxy instances for API"""
default_proxy_id: Optional[str] = None
servers: List[CrawlerProxy] = []
# ============================================================================
class OrgProxies(BaseModel):
"""Org proxy settings for API"""
allowSharedProxies: bool
allowedProxies: list[str]
# ============================================================================
### BASE CRAWLS ###
# ============================================================================
class StorageRef(BaseModel):
"""Reference to actual storage"""
name: str
custom: Optional[bool] = False
def __init__(self, *args, **kwargs):
if args:
if args[0].startswith("cs-"):
super().__init__(name=args[0][2:], custom=True)
else:
super().__init__(name=args[0], custom=False)
else:
super().__init__(**kwargs)
def __str__(self):
if not self.custom:
return self.name
return "cs-" + self.name
def get_storage_secret_name(self, oid: str) -> str:
"""get k8s secret name for this storage and oid"""
if not self.custom:
return "storage-" + self.name
return f"storage-cs-{self.name}-{oid[:12]}"
def get_storage_extra_path(self, oid: str) -> str:
"""return extra path added to the endpoint
using oid for default storages, no extra path for custom"""
if not self.custom:
return oid + "/"
return ""
# ============================================================================
class BaseFile(BaseModel):
"""Base model for crawl and profile files"""
filename: str
hash: str
size: int
storage: StorageRef
replicas: Optional[List[StorageRef]] = []
# ============================================================================
class CrawlFile(BaseFile):
"""file from a crawl"""
presignedUrl: Optional[str] = None
expireAt: Optional[datetime] = None
# ============================================================================
class CrawlFileOut(BaseModel):
"""output for file from a crawl (conformance to Data Resource Spec)"""
name: str
path: str
hash: str
size: int
crawlId: Optional[str] = None
numReplicas: int = 0
expireAt: Optional[str] = None
# ============================================================================
class CrawlStats(BaseModel):
"""Crawl Stats for pages and size"""
found: int = 0
done: int = 0
size: int = 0
# ============================================================================
class CoreCrawlable(BaseModel):
# pylint: disable=too-few-public-methods
"""Core properties for crawlable run (crawl or qa run)"""
id: str
userid: UUID
userName: Optional[str] = None
started: datetime
finished: Optional[datetime] = None
state: str
crawlExecSeconds: int = 0
image: Optional[str] = None
stats: Optional[CrawlStats] = CrawlStats()
files: List[CrawlFile] = []
fileSize: int = 0
fileCount: int = 0
errors: Optional[List[str]] = []
# ============================================================================
class BaseCrawl(CoreCrawlable, BaseMongoModel):
"""Base Crawl object (representing crawls, uploads and manual sessions)"""
type: str
oid: UUID
cid: Optional[UUID] = None
name: Optional[str] = ""
description: Optional[str] = ""
tags: Optional[List[str]] = []
collectionIds: Optional[List[UUID]] = []
reviewStatus: ReviewStatus = None
pageCount: Optional[int] = 0
uniquePageCount: Optional[int] = 0
filePageCount: Optional[int] = 0
errorPageCount: Optional[int] = 0
# ============================================================================
class CollIdName(BaseModel):
"""Collection id and name object"""
id: UUID
name: str
# ============================================================================
class CrawlOut(BaseMongoModel):
"""Crawl output model, shared across all crawl types"""
# pylint: disable=duplicate-code
type: str
id: str
userid: UUID
userName: Optional[str] = None
oid: UUID
profileid: Optional[UUID] = None
name: Optional[str] = None
description: Optional[str] = None
started: datetime
finished: Optional[datetime] = None
state: str
stats: Optional[CrawlStats] = None
fileSize: int = 0
fileCount: int = 0
tags: Optional[List[str]] = []
errors: Optional[List[str]] = []
collectionIds: Optional[List[UUID]] = []
crawlExecSeconds: int = 0
qaCrawlExecSeconds: int = 0
# automated crawl fields
config: Optional[RawCrawlConfig] = None
cid: Optional[UUID] = None
firstSeed: Optional[str] = None
seedCount: Optional[int] = None
profileName: Optional[str] = None
stopping: Optional[bool] = False
manual: bool = False
cid_rev: Optional[int] = None
scale: Scale = 1
storageQuotaReached: Optional[bool] = False
execMinutesQuotaReached: Optional[bool] = False
crawlerChannel: str = "default"
proxyId: Optional[str] = None
image: Optional[str] = None
reviewStatus: ReviewStatus = None
qaRunCount: int = 0
activeQAStats: Optional[CrawlStats] = None
lastQAState: Optional[str] = None
lastQAStarted: Optional[datetime] = None
pageCount: Optional[int] = 0
uniquePageCount: Optional[int] = 0
filePageCount: Optional[int] = 0
errorPageCount: Optional[int] = 0
# ============================================================================
class CrawlOutWithResources(CrawlOut):
"""Crawl output model including resources"""
resources: Optional[List[CrawlFileOut]] = []
collections: Optional[List[CollIdName]] = []
# ============================================================================
class UpdateCrawl(BaseModel):
"""Update crawl"""
name: Optional[str] = None
description: Optional[str] = None
tags: Optional[List[str]] = None
collectionIds: Optional[List[UUID]] = []
reviewStatus: ReviewStatus = None
# ============================================================================
class DeleteCrawlList(BaseModel):
"""delete crawl list POST body"""
crawl_ids: List[str]
# ============================================================================
class DeleteQARunList(BaseModel):
"""delete qa run list POST body"""
qa_run_ids: List[str]
# ============================================================================
class CrawlSearchValuesResponse(BaseModel):
"""Response model for crawl search values"""
names: List[str]
descriptions: List[str]
firstSeeds: List[AnyHttpUrl]
# ============================================================================
class CrawlQueueResponse(BaseModel):
"""Response model for GET crawl queue"""
total: int
results: List[AnyHttpUrl]
matched: List[AnyHttpUrl]
# ============================================================================
class MatchCrawlQueueResponse(BaseModel):
"""Response model for match crawl queue"""
total: int
matched: List[AnyHttpUrl]
nextOffset: int
# ============================================================================
### AUTOMATED CRAWLS ###
# ============================================================================
class CrawlScale(BaseModel):
"""scale the crawl to N parallel containers"""
scale: Scale = 1
# ============================================================================
class QARun(CoreCrawlable, BaseModel):
"""Subdocument to track QA runs for given crawl"""
# ============================================================================
class QARunWithResources(QARun):
"""QA crawl output model including resources"""
resources: Optional[List[CrawlFileOut]] = []
# ============================================================================
class QARunOut(BaseModel):
"""QA Run Output"""
id: str
userName: Optional[str] = None
started: datetime
finished: Optional[datetime] = None
state: str
crawlExecSeconds: int = 0
stats: CrawlStats = CrawlStats()
# ============================================================================
class QARunBucketStats(BaseModel):
"""Model for per-bucket aggregate stats results"""
lowerBoundary: str
count: int
# ============================================================================
class QARunAggregateStatsOut(BaseModel):
"""QA Run aggregate stats out"""
screenshotMatch: List[QARunBucketStats]
textMatch: List[QARunBucketStats]