From 2efd32f697549c59337db5177a93749af8e605d8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 16 May 2018 09:28:18 +0200 Subject: Fix updating video tags to empty field --- client/src/app/shared/misc/utils.ts | 5 ++ .../+video-edit/shared/video-edit.component.ts | 2 +- client/src/assets/player/peertube-chunk-store.ts | 59 +++++++++++++--------- 3 files changed, 41 insertions(+), 25 deletions(-) (limited to 'client') diff --git a/client/src/app/shared/misc/utils.ts b/client/src/app/shared/misc/utils.ts index b5bf99be2..b9aa223cf 100644 --- a/client/src/app/shared/misc/utils.ts +++ b/client/src/app/shared/misc/utils.ts @@ -66,6 +66,11 @@ function objectToFormData (obj: any, form?: FormData, namespace?: string) { if (obj[key] === undefined) continue + if (Array.isArray(obj[key]) && obj[key].length === 0) { + fd.append(key, null) + continue + } + if (obj[key] !== null && typeof obj[ key ] === 'object' && !(obj[ key ] instanceof File)) { objectToFormData(obj[ key ], fd, key) } else { diff --git a/client/src/app/videos/+video-edit/shared/video-edit.component.ts b/client/src/app/videos/+video-edit/shared/video-edit.component.ts index af4438bd2..d4567e26c 100644 --- a/client/src/app/videos/+video-edit/shared/video-edit.component.ts +++ b/client/src/app/videos/+video-edit/shared/video-edit.component.ts @@ -80,7 +80,7 @@ export class VideoEditComponent implements OnInit { this.form.addControl('licence', new FormControl('', VIDEO_LICENCE.VALIDATORS)) this.form.addControl('language', new FormControl('', VIDEO_LANGUAGE.VALIDATORS)) this.form.addControl('description', new FormControl('', VIDEO_DESCRIPTION.VALIDATORS)) - this.form.addControl('tags', new FormControl('')) + this.form.addControl('tags', new FormControl([])) this.form.addControl('thumbnailfile', new FormControl('')) this.form.addControl('previewfile', new FormControl('')) this.form.addControl('support', new FormControl('', VIDEO_SUPPORT.VALIDATORS)) diff --git a/client/src/assets/player/peertube-chunk-store.ts b/client/src/assets/player/peertube-chunk-store.ts index 84fbaf146..e14e31c04 100644 --- a/client/src/assets/player/peertube-chunk-store.ts +++ b/client/src/assets/player/peertube-chunk-store.ts @@ -155,17 +155,17 @@ export class PeertubeChunkStore extends EventEmitter { this.cleanerInterval = null } + if (this.db) { + await this.db.close() + + await this.dropDatabase(this.databaseName) + } + if (this.expirationDB) { await this.expirationDB.close() this.expirationDB = null } - if (this.db) { - console.log('Destroying IndexDB database %s.', this.databaseName) - await this.db.close() - await this.db.delete() - } - return cb() } catch (err) { console.error('Cannot destroy peertube chunk store.', err) @@ -181,31 +181,42 @@ export class PeertubeChunkStore extends EventEmitter { }, PeertubeChunkStore.CLEANER_INTERVAL_MS) } - private checkExpiration () { - this.expirationDB.transaction('rw', this.expirationDB.databases, async () => { - // Update our database expiration since we are alive - await this.expirationDB.databases.put({ - name: this.databaseName, - expiration: new Date().getTime() + PeertubeChunkStore.CLEANER_EXPIRATION_MS - }) + private async checkExpiration () { + let databasesToDeleteInfo: { name: string }[] = [] - const now = new Date().getTime() - const databasesToDeleteInfo = await this.expirationDB.databases.where('expiration').below(now).toArray() + try { + await this.expirationDB.transaction('rw', this.expirationDB.databases, async () => { + // Update our database expiration since we are alive + await this.expirationDB.databases.put({ + name: this.databaseName, + expiration: new Date().getTime() + PeertubeChunkStore.CLEANER_EXPIRATION_MS + }) - for (const databaseToDeleteInfo of databasesToDeleteInfo) { - await this.dropDatabase(databaseToDeleteInfo.name) + const now = new Date().getTime() + databasesToDeleteInfo = await this.expirationDB.databases.where('expiration').below(now).toArray() + }) + } catch (err) { + console.error('Cannot update expiration of fetch expired databases.', err) + } - await this.expirationDB.databases.where({ name: databaseToDeleteInfo.name }).delete() - } - }).catch(err => console.error('Cannot check expiration.', err)) + for (const databaseToDeleteInfo of databasesToDeleteInfo) { + await this.dropDatabase(databaseToDeleteInfo.name) + } } - private dropDatabase (databaseName: string) { + private async dropDatabase (databaseName: string) { const dbToDelete = new ChunkDatabase(databaseName) + console.log('Destroying IndexDB database %s.', databaseName) - console.log('Deleting %s.', databaseName) - return dbToDelete.delete() - .catch(err => console.error('Cannot delete %s.', databaseName)) + try { + await dbToDelete.delete() + + await this.expirationDB.transaction('rw', this.expirationDB.databases, () => { + return this.expirationDB.databases.where({ name: databaseName }).delete() + }) + } catch (err) { + console.error('Cannot delete %s.', databaseName, err) + } } private nextTick (cb, err, val?) { -- cgit v1.2.3