core Image update
This commit is contained in:
1 parent
51ea05cd61
commit
c3676a02be
3 files changed
+62
-1
No files matched your search
+35
-1
@@ -1,11 +1,45 @@
|
||||
const Data = require('./Data')
|
||||
const {findOne} = require('../lib/store')
|
||||
const {mapOf} = require('../lib/common')
|
||||
|
||||
const store = () => Data.getStore(Image)
|
||||
|
||||
class Image {
|
||||
static async findById(id) {
|
||||
return findOne(store(), {_id: id})
|
||||
const data = await findOne(store(), {_id: id})
|
||||
if (!data) return null
|
||||
|
||||
const artifacts = data.data
|
||||
return new Image({...data, artifacts})
|
||||
}
|
||||
|
||||
constructor({hash, file, artifacts}) {
|
||||
this.hash = hash
|
||||
this.file = file
|
||||
|
||||
this.artifacts = mapOf(ImageArtifact, artifacts)
|
||||
}
|
||||
|
||||
getArtifact(size) {
|
||||
return this.artifacts.get(size)
|
||||
}
|
||||
|
||||
findArtifact(sizes) {
|
||||
for (let size of sizes) {
|
||||
const a = this.getArtifact(size)
|
||||
if (a) return a
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
class ImageArtifact {
|
||||
constructor({url, size, width, height}) {
|
||||
this.url = url
|
||||
this.size = size
|
||||
this.width = width
|
||||
this.height = height
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user