startDate: string // ISO 8601
endDate: string // ISO 8601
+ originallyPublishedStartDate: string // ISO 8601
+ originallyPublishedEndDate: string // ISO 8601
+
nsfw: NSFWQuery
categoryOneOf: string
constructor (options?: {
startDate?: string
endDate?: string
+ originallyPublishedStartDate?: string
+ originallyPublishedEndDate?: string
nsfw?: NSFWQuery
categoryOneOf?: string
licenceOneOf?: string
this.startDate = options.startDate || undefined
this.endDate = options.endDate || undefined
+ this.originallyPublishedStartDate = options.originallyPublishedStartDate || undefined
+ this.originallyPublishedEndDate = options.originallyPublishedEndDate || undefined
+
this.nsfw = options.nsfw || undefined
this.categoryOneOf = options.categoryOneOf || undefined
this.licenceOneOf = options.licenceOneOf || undefined
reset () {
this.startDate = undefined
this.endDate = undefined
+ this.originallyPublishedStartDate = undefined
+ this.originallyPublishedEndDate = undefined
this.nsfw = undefined
this.categoryOneOf = undefined
this.licenceOneOf = undefined
return {
startDate: this.startDate,
endDate: this.endDate,
+ originallyPublishedStartDate: this.originallyPublishedStartDate,
+ originallyPublishedEndDate: this.originallyPublishedEndDate,
nsfw: this.nsfw,
categoryOneOf: this.categoryOneOf,
licenceOneOf: this.licenceOneOf,
return {
startDate: this.startDate,
endDate: this.endDate,
+ originallyPublishedStartDate: this.originallyPublishedStartDate,
+ originallyPublishedEndDate: this.originallyPublishedEndDate,
nsfw: this.nsfw,
categoryOneOf: this.intoArray(this.categoryOneOf),
licenceOneOf: this.intoArray(this.licenceOneOf),
</div>
</div>
+ <div class="form-group">
+ <label i18n for="original-publication-after">Original publication year</label>
+
+ <div class="row">
+ <div class="col-sm-6">
+ <input
+ type="text" id="original-publication-after" name="original-publication-after"
+ i18n-placeholder placeholder="After..."
+ [(ngModel)]="originallyPublishedStartYear"
+ >
+ </div>
+ <div class="col-sm-6">
+ <input
+ type="text" id="original-publication-before" name="original-publication-before"
+ i18n-placeholder placeholder="Before..."
+ [(ngModel)]="originallyPublishedEndYear"
+ >
+ </div>
+ </div>
+ </div>
+
<div class="form-group">
<div i18n class="radio-label">Duration</div>
<div class="submit-button">
<input type="submit" i18n-value value="Filter">
</div>
-</form>
\ No newline at end of file
+</form>
publishedDateRange: string
durationRange: string
+ originallyPublishedStartYear: string
+ originallyPublishedEndYear: string
+
constructor (
private i18n: I18n,
private serverService: ServerService
this.loadFromDurationRange()
this.loadFromPublishedRange()
+ this.loadOriginallyPublishedAtYears()
}
formUpdated () {
this.updateModelFromDurationRange()
this.updateModelFromPublishedRange()
+ this.updateModelFromOriginallyPublishedAtYears()
this.filtered.emit(this.advancedSearch)
}
+ private loadOriginallyPublishedAtYears () {
+ this.originallyPublishedStartYear = this.advancedSearch.originallyPublishedStartDate
+ ? new Date(this.advancedSearch.originallyPublishedStartDate).getFullYear().toString()
+ : null
+
+ this.originallyPublishedEndYear = this.advancedSearch.originallyPublishedEndDate
+ ? new Date(this.advancedSearch.originallyPublishedEndDate).getFullYear().toString()
+ : null
+ }
+
private loadFromDurationRange () {
if (this.advancedSearch.durationMin || this.advancedSearch.durationMax) {
const fourMinutes = 60 * 4
}
}
+ private updateModelFromOriginallyPublishedAtYears () {
+ const baseDate = new Date()
+ baseDate.setHours(0, 0, 0, 0)
+ baseDate.setMonth(0, 1)
+
+ if (this.originallyPublishedStartYear) {
+ const year = parseInt(this.originallyPublishedStartYear, 10)
+ const start = new Date(baseDate)
+ start.setFullYear(year)
+
+ this.advancedSearch.originallyPublishedStartDate = start.toISOString()
+ } else {
+ this.advancedSearch.originallyPublishedStartDate = null
+ }
+
+ if (this.originallyPublishedEndYear) {
+ const year = parseInt(this.originallyPublishedEndYear, 10)
+ const end = new Date(baseDate)
+ end.setFullYear(year)
+
+ this.advancedSearch.originallyPublishedEndDate = end.toISOString()
+ } else {
+ this.advancedSearch.originallyPublishedEndDate = null
+ }
+ }
+
private updateModelFromDurationRange () {
if (!this.durationRange) return
this.advancedSearch.startDate = date.toISOString()
}
+
}
sort?: string
startDate?: string // ISO 8601
endDate?: string // ISO 8601
+ originallyPublishedStartDate?: string
+ originallyPublishedEndDate?: string
nsfw?: boolean
categoryOneOf?: number[]
licenceOneOf?: number[]
whereAnd.push({ publishedAt: publishedAtRange })
}
+ if (options.originallyPublishedStartDate || options.originallyPublishedEndDate) {
+ const originallyPublishedAtRange = {}
+
+ if (options.originallyPublishedStartDate) originallyPublishedAtRange[ Sequelize.Op.gte ] = options.originallyPublishedStartDate
+ if (options.originallyPublishedEndDate) originallyPublishedAtRange[ Sequelize.Op.lte ] = options.originallyPublishedEndDate
+
+ whereAnd.push({ originallyPublishedAt: originallyPublishedAtRange })
+ }
+
if (options.durationMin || options.durationMax) {
const durationRange = {}
const customQuery2 = immutableAssign(query, { endDate: 'hello' })
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
+
+ const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' })
+ await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 400 })
+
+ const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' })
+ await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 400 })
})
})
const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2 '] })
await uploadVideo(server.url, server.accessToken, attributes6)
- const attributes7 = immutableAssign(attributes1, { name: attributes1.name + ' - 7' })
+ const attributes7 = immutableAssign(attributes1, {
+ name: attributes1.name + ' - 7',
+ originallyPublishedAt: '2019-02-12T09:58:08.286Z'
+ })
await uploadVideo(server.url, server.accessToken, attributes7)
const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 })
expect(videos[0].name).to.equal('1111 2222 3333')
})
+ it('Should search on originally published date', async function () {
+ const baseQuery = {
+ search: '1111 2222 3333',
+ languageOneOf: [ 'pl', 'fr' ],
+ durationMax: 4,
+ nsfw: 'false' as 'false',
+ licenceOneOf: [ 1, 4 ]
+ }
+
+ {
+ const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' })
+ const res = await advancedVideosSearch(server.url, query)
+
+ expect(res.body.total).to.equal(1)
+ expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
+ }
+
+ {
+ const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' })
+ const res = await advancedVideosSearch(server.url, query)
+
+ expect(res.body.total).to.equal(1)
+ expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
+ }
+
+ {
+ const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' })
+ const res = await advancedVideosSearch(server.url, query)
+
+ expect(res.body.total).to.equal(0)
+ }
+
+ {
+ const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' })
+ const res = await advancedVideosSearch(server.url, query)
+
+ expect(res.body.total).to.equal(0)
+ }
+
+ {
+ const query = immutableAssign(baseQuery, {
+ originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
+ originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
+ })
+ const res = await advancedVideosSearch(server.url, query)
+
+ expect(res.body.total).to.equal(0)
+ }
+
+ {
+ const query = immutableAssign(baseQuery, {
+ originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
+ originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
+ })
+ const res = await advancedVideosSearch(server.url, query)
+
+ expect(res.body.total).to.equal(1)
+ expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
+ }
+ })
+
after(async function () {
killallServers([ server ])
startDate?: string // ISO 8601
endDate?: string // ISO 8601
+ originallyPublishedStartDate?: string // ISO 8601
+ originallyPublishedEndDate?: string // ISO 8601
+
nsfw?: NSFWQuery
categoryOneOf?: number[]