-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add resource and service media classes (#2467)
* refactor: add resource and service media classes * test: spec EuropeanaMediaService * test: spec EuropeanaMediaResource
- Loading branch information
Showing
13 changed files
with
375 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Base from './Base.js'; | ||
import Service from './Service.js'; | ||
import EDMWebResource from '@/plugins/europeana/edm/WebResource.js'; | ||
|
||
export default class EuropeanaMediaResource extends Base { | ||
$edm; | ||
|
||
static fromEDM(edm) { | ||
if (!edm) { | ||
return undefined; | ||
} | ||
|
||
let data = {}; | ||
if (typeof edm === 'string') { | ||
data.id = edm; | ||
} else { | ||
data = this.omitIsUndefined({ | ||
edm, | ||
id: edm.about, | ||
format: edm.ebucoreHasMimeType, | ||
height: edm.ebucoreHeight, | ||
width: edm.ebucoreWidth, | ||
service: Service.fromEDM([].concat(edm.svcsHasService)[0]) | ||
}); | ||
} | ||
|
||
return new this(data); | ||
} | ||
|
||
parseData(data) { | ||
data = super.parseData(data); | ||
|
||
const parsed = { | ||
id: data.id, | ||
format: data.format, | ||
height: data.height, | ||
service: Service.parse([].concat(data.service)[0]), | ||
width: data.width | ||
}; | ||
|
||
return parsed; | ||
} | ||
|
||
get edm() { | ||
if (!this.$edm) { | ||
const data = this.constructor.omitIsUndefined({ | ||
about: this.id, | ||
ebucoreHasMimeType: this.format, | ||
ebucoreHeight: this.height, | ||
ebucoreWidth: this.width, | ||
svcsHasService: [].concat(this.service || [])[0]?.edm | ||
}); | ||
|
||
this.$edm = new EDMWebResource(data); | ||
} | ||
return this.$edm; | ||
} | ||
|
||
set edm(value) { | ||
this.$edm = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import Base from './Base.js'; | ||
import EDMService from '@/plugins/europeana/edm/Service.js'; | ||
|
||
export default class EuropeanaMediaService extends Base { | ||
$edm; | ||
|
||
static fromEDM(edm) { | ||
if (!edm) { | ||
return undefined; | ||
} | ||
|
||
let data = {}; | ||
if (typeof edm === 'string') { | ||
data.id = edm; | ||
} else { | ||
data = this.omitIsUndefined({ | ||
edm, | ||
context: 'http://iiif.io/api/image/2/context.json', | ||
id: edm.about, | ||
profile: edm.doapImplements | ||
}); | ||
} | ||
|
||
return new this(data); | ||
} | ||
|
||
get infoUrl() { | ||
return `${this.id}/info.json`; | ||
} | ||
|
||
fetchInfo() { | ||
return this.constructor.fetch({ | ||
url: this.infoUrl | ||
}); | ||
} | ||
|
||
get edm() { | ||
if (!this.$edm) { | ||
const data = this.constructor.omitIsUndefined({ | ||
about: this.id, | ||
doapImplements: this.profile, | ||
dctermsConformsTo: ['http://iiif.io/api/image'] | ||
}); | ||
|
||
this.$edm = new EDMService(data); | ||
} | ||
return this.$edm; | ||
} | ||
|
||
set edm(value) { | ||
this.$edm = value; | ||
} | ||
} |
Oops, something went wrong.