Skip to content

Commit 2aaec4f

Browse files
committed
feat: refactor database entries
1 parent 5519905 commit 2aaec4f

4 files changed

Lines changed: 24 additions & 21 deletions

File tree

‎src/MediaConverter.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class MediaConverter extends EventEmitter {
4141
return
4242
}
4343

44-
await this.store.lock(id, file.filename, file.data)
44+
await this.store.lock(id, file.data)
4545

4646
const context: FileContext = {
4747
dryrun,
@@ -81,7 +81,7 @@ export class MediaConverter extends EventEmitter {
8181
this.log.error(error)
8282
this.log.trace(stdout)
8383
this.log.trace(stderr)
84-
await this.store.unlock(id, context.file.filename, context.file.data)
84+
await this.store.unlock(id, context.file.data)
8585
reject(new MediaError(stdout, stderr, error))
8686
})
8787
.run()
@@ -108,7 +108,7 @@ export class MediaConverter extends EventEmitter {
108108
}
109109

110110
const id = fs.basename(context.filename.original, false)
111-
await this.store.unlock(id, context.file.filename, context.file.data)
111+
await this.store.unlock(id, context.file.data)
112112

113113
this.emit(MediaConverter.events.stop)
114114
resolve()

‎src/MediaInfo.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { FfprobeData } from 'fluent-ffmpeg'
33
export type DocumentInfo = PouchDB.Core.IdMeta
44

55
export interface MediaInfo extends DocumentInfo {
6-
filename: string
76
host: string | null
87
locked: boolean
98
source: FfprobeData

‎src/MediaScanner.ts‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ export class MediaScanner extends EventEmitter {
7070

7171
if (await this.media.exists(id)) {
7272
const document = await this.media.get(id)
73-
return this.convertible(document, index, total)
73+
return this.convertible(filename, document, index, total)
7474
}
7575

7676
const info = await getMediaInfo(filename)
77-
const document: MediaInfo = { _id: id, filename, host: null, locked: false, source: info }
78-
await this.media.upsert(id, filename, info)
79-
return this.convertible(document, index, total)
77+
const document: MediaInfo = { _id: id, host: null, locked: false, source: info }
78+
await this.media.upsert(id, info)
79+
return this.convertible(filename, document, index, total)
8080
} catch (error) {
8181
this.log.error(error)
8282
}
@@ -91,8 +91,13 @@ export class MediaScanner extends EventEmitter {
9191
return files.reduce<StreamFile[]>((results, file) => (file !== null ? [...results, file] : results), [])
9292
}
9393

94-
private async convertible(info: MediaInfo, index: number, total: number): Promise<StreamFile | null> {
95-
const id = fs.basename(info.filename, false)
94+
private async convertible(
95+
filename: string,
96+
info: MediaInfo,
97+
index: number,
98+
total: number,
99+
): Promise<StreamFile | null> {
100+
const id = fs.basename(filename, false)
96101

97102
const audio = this.findAudioStream(info.source)
98103
const video = this.findVideoStream(info.source)
@@ -102,16 +107,16 @@ export class MediaScanner extends EventEmitter {
102107

103108
const locked = await this.media.locked(id)
104109
this.log.trace(id, 'lock-status', locked, 'progress', index, total)
105-
this.emit(MediaScanner.events.progress, info.filename, locked)
110+
this.emit(MediaScanner.events.progress, filename, locked)
106111

107112
if ((audioCodeDisallowed || videoCodecDisallowed) && locked === false) {
108113
this.log.debug(id, 'convertible')
109114

110115
const streamFile: StreamFile = {
111116
audio,
112117
video,
118+
filename,
113119
data: info.source,
114-
filename: info.filename,
115120
format: info.source.format,
116121
}
117122

‎src/MediaStore.ts‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ export class MediaStore {
3535
}
3636
}
3737

38-
get (id: string) {
38+
get(id: string) {
3939
return this.database.get<MediaInfo>(id)
4040
}
4141

42-
lock(id: string, filename: string, source: FfprobeData) {
43-
this.log.trace('locked', id, filename)
44-
return this.upsert(id, filename, source, true, os.hostname())
42+
lock(id: string, source: FfprobeData) {
43+
this.log.trace('locked', id)
44+
return this.upsert(id, source, true, os.hostname())
4545
}
4646

4747
async locked(id: string) {
@@ -53,14 +53,13 @@ export class MediaStore {
5353
}
5454
}
5555

56-
unlock(id: string, filename: string, source: FfprobeData) {
57-
this.log.trace('unlocked', id, filename)
58-
return this.upsert(id, filename, source, false, null)
56+
unlock(id: string, source: FfprobeData) {
57+
this.log.trace('unlocked', id)
58+
return this.upsert(id, source, false, null)
5959
}
6060

61-
upsert(id: string, filename: string, source: FfprobeData, locked: boolean = false, host: string | null = null) {
61+
upsert(id: string, source: FfprobeData, locked: boolean = false, host: string | null = null) {
6262
return this.database.upsert<MediaInfo>(id, (target: MediaInfo) => {
63-
target.filename = filename
6463
target.host = host
6564
target.locked = locked
6665
target.source = source

0 commit comments

Comments
 (0)