2022-03-09 02:31:44 +01:00
|
|
|
class FileMetadata {
|
|
|
|
constructor(metadata) {
|
|
|
|
this.filename = null
|
|
|
|
this.ext = null
|
|
|
|
this.path = null
|
|
|
|
this.relPath = null
|
|
|
|
this.size = null
|
|
|
|
this.mtimeMs = null
|
|
|
|
this.ctimeMs = null
|
|
|
|
this.birthtimeMs = null
|
|
|
|
|
|
|
|
if (metadata) {
|
|
|
|
this.construct(metadata)
|
|
|
|
}
|
2022-03-13 00:45:32 +01:00
|
|
|
|
|
|
|
// Temp flag used in scans
|
|
|
|
this.wasModified = false
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
construct(metadata) {
|
|
|
|
this.filename = metadata.filename
|
|
|
|
this.ext = metadata.ext
|
|
|
|
this.path = metadata.path
|
|
|
|
this.relPath = metadata.relPath
|
|
|
|
this.size = metadata.size
|
|
|
|
this.mtimeMs = metadata.mtimeMs
|
|
|
|
this.ctimeMs = metadata.ctimeMs
|
|
|
|
this.birthtimeMs = metadata.birthtimeMs
|
|
|
|
}
|
|
|
|
|
|
|
|
toJSON() {
|
|
|
|
return {
|
|
|
|
filename: this.filename,
|
|
|
|
ext: this.ext,
|
|
|
|
path: this.path,
|
|
|
|
relPath: this.relPath,
|
|
|
|
size: this.size,
|
|
|
|
mtimeMs: this.mtimeMs,
|
|
|
|
ctimeMs: this.ctimeMs,
|
|
|
|
birthtimeMs: this.birthtimeMs
|
|
|
|
}
|
|
|
|
}
|
2022-03-10 02:23:17 +01:00
|
|
|
|
|
|
|
clone() {
|
|
|
|
return new FileMetadata(this.toJSON())
|
|
|
|
}
|
2022-03-11 01:45:02 +01:00
|
|
|
|
|
|
|
get format() {
|
|
|
|
if (!this.ext) return ''
|
|
|
|
return this.ext.slice(1)
|
|
|
|
}
|
2022-03-13 00:45:32 +01:00
|
|
|
|
|
|
|
update(payload) {
|
|
|
|
var hasUpdates = false
|
|
|
|
for (const key in payload) {
|
|
|
|
if (this[key] !== undefined && this[key] !== payload[key]) {
|
|
|
|
this[key] = payload[key]
|
|
|
|
hasUpdates = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hasUpdates
|
|
|
|
}
|
|
|
|
|
|
|
|
setData(payload) {
|
|
|
|
for (const key in payload) {
|
|
|
|
if (this[key] !== undefined) {
|
|
|
|
this[key] = payload[key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-09 02:31:44 +01:00
|
|
|
}
|
|
|
|
module.exports = FileMetadata
|