1 import { NSFWQuery } from '../../../../shared/models/search'
3 export class AdvancedSearch {
4 startDate: string // ISO 8601
5 endDate: string // ISO 8601
7 originallyPublishedStartDate: string // ISO 8601
8 originallyPublishedEndDate: string // ISO 8601
21 durationMin: number // seconds
22 durationMax: number // seconds
26 constructor (options?: {
29 originallyPublishedStartDate?: string
30 originallyPublishedEndDate?: string
32 categoryOneOf?: string
34 languageOneOf?: string
43 this.startDate = options.startDate || undefined
44 this.endDate = options.endDate || undefined
45 this.originallyPublishedStartDate = options.originallyPublishedStartDate || undefined
46 this.originallyPublishedEndDate = options.originallyPublishedEndDate || undefined
48 this.nsfw = options.nsfw || undefined
49 this.categoryOneOf = options.categoryOneOf || undefined
50 this.licenceOneOf = options.licenceOneOf || undefined
51 this.languageOneOf = options.languageOneOf || undefined
52 this.tagsOneOf = options.tagsOneOf || undefined
53 this.tagsAllOf = options.tagsAllOf || undefined
54 this.durationMin = parseInt(options.durationMin, 10)
55 this.durationMax = parseInt(options.durationMax, 10)
57 if (isNaN(this.durationMin)) this.durationMin = undefined
58 if (isNaN(this.durationMax)) this.durationMax = undefined
60 this.sort = options.sort || '-match'
64 const obj = this.toUrlObject()
65 for (const k of Object.keys(obj)) {
66 if (k === 'sort') continue // Exception
68 if (obj[k] !== undefined && obj[k] !== '') return true
75 this.startDate = undefined
76 this.endDate = undefined
77 this.originallyPublishedStartDate = undefined
78 this.originallyPublishedEndDate = undefined
80 this.categoryOneOf = undefined
81 this.licenceOneOf = undefined
82 this.languageOneOf = undefined
83 this.tagsOneOf = undefined
84 this.tagsAllOf = undefined
85 this.durationMin = undefined
86 this.durationMax = undefined
93 startDate: this.startDate,
94 endDate: this.endDate,
95 originallyPublishedStartDate: this.originallyPublishedStartDate,
96 originallyPublishedEndDate: this.originallyPublishedEndDate,
98 categoryOneOf: this.categoryOneOf,
99 licenceOneOf: this.licenceOneOf,
100 languageOneOf: this.languageOneOf,
101 tagsOneOf: this.tagsOneOf,
102 tagsAllOf: this.tagsAllOf,
103 durationMin: this.durationMin,
104 durationMax: this.durationMax,
111 startDate: this.startDate,
112 endDate: this.endDate,
113 originallyPublishedStartDate: this.originallyPublishedStartDate,
114 originallyPublishedEndDate: this.originallyPublishedEndDate,
116 categoryOneOf: this.intoArray(this.categoryOneOf),
117 licenceOneOf: this.intoArray(this.licenceOneOf),
118 languageOneOf: this.intoArray(this.languageOneOf),
119 tagsOneOf: this.intoArray(this.tagsOneOf),
120 tagsAllOf: this.intoArray(this.tagsAllOf),
121 durationMin: this.durationMin,
122 durationMax: this.durationMax,
130 const obj = this.toUrlObject()
131 for (const k of Object.keys(obj)) {
132 if (k === 'sort') continue // Exception
134 if (obj[k] !== undefined && obj[k] !== '') acc++
140 private intoArray (value: any) {
141 if (!value) return undefined
142 if (Array.isArray(value)) return value
144 if (typeof value === 'string') return value.split(',')