1 import { NSFWQuery } from '../../../../shared/models/search'
3 export class AdvancedSearch {
4 startDate: string // ISO 8601
5 endDate: string // ISO 8601
18 durationMin: number // seconds
19 durationMax: number // seconds
23 constructor (options?: {
27 categoryOneOf?: string
29 languageOneOf?: string
38 this.startDate = options.startDate || undefined
39 this.endDate = options.endDate || undefined
40 this.nsfw = options.nsfw || undefined
41 this.categoryOneOf = options.categoryOneOf || undefined
42 this.licenceOneOf = options.licenceOneOf || undefined
43 this.languageOneOf = options.languageOneOf || undefined
44 this.tagsOneOf = options.tagsOneOf || undefined
45 this.tagsAllOf = options.tagsAllOf || undefined
46 this.durationMin = parseInt(options.durationMin, 10)
47 this.durationMax = parseInt(options.durationMax, 10)
49 if (isNaN(this.durationMin)) this.durationMin = undefined
50 if (isNaN(this.durationMax)) this.durationMax = undefined
52 this.sort = options.sort || '-match'
56 const obj = this.toUrlObject()
57 for (const k of Object.keys(obj)) {
58 if (k === 'sort') continue // Exception
60 if (obj[k] !== undefined) return true
67 this.startDate = undefined
68 this.endDate = undefined
70 this.categoryOneOf = undefined
71 this.licenceOneOf = undefined
72 this.languageOneOf = undefined
73 this.tagsOneOf = undefined
74 this.tagsAllOf = undefined
75 this.durationMin = undefined
76 this.durationMax = undefined
83 startDate: this.startDate,
84 endDate: this.endDate,
86 categoryOneOf: this.categoryOneOf,
87 licenceOneOf: this.licenceOneOf,
88 languageOneOf: this.languageOneOf,
89 tagsOneOf: this.tagsOneOf,
90 tagsAllOf: this.tagsAllOf,
91 durationMin: this.durationMin,
92 durationMax: this.durationMax,
99 startDate: this.startDate,
100 endDate: this.endDate,
102 categoryOneOf: this.intoArray(this.categoryOneOf),
103 licenceOneOf: this.intoArray(this.licenceOneOf),
104 languageOneOf: this.intoArray(this.languageOneOf),
105 tagsOneOf: this.intoArray(this.tagsOneOf),
106 tagsAllOf: this.intoArray(this.tagsAllOf),
107 durationMin: this.durationMin,
108 durationMax: this.durationMax,
113 private intoArray (value: any) {
114 if (!value) return undefined
116 if (typeof value === 'string') return value.split(',')