mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
5f5f0021db
no issue - support ends today - see https://github.com/nodejs/Release - removed `use strict`
60 lines
1.2 KiB
JavaScript
60 lines
1.2 KiB
JavaScript
const EventEmitter = require('events').EventEmitter,
|
|
common = require('../../lib/common');
|
|
|
|
class Resource extends EventEmitter {
|
|
constructor(type, obj) {
|
|
super();
|
|
|
|
this.data = {};
|
|
this.config = {
|
|
type: type,
|
|
reserved: false
|
|
};
|
|
|
|
Object.assign(this.data, obj);
|
|
}
|
|
|
|
getType() {
|
|
return this.config.type;
|
|
}
|
|
|
|
reserve() {
|
|
if (!this.config.reserved) {
|
|
this.config.reserved = true;
|
|
} else {
|
|
common.logging.error(new common.errors.InternalServerError({
|
|
message: 'Resource is already taken. This should not happen.',
|
|
code: 'URLSERVICE_RESERVE_RESOURCE'
|
|
}));
|
|
}
|
|
}
|
|
|
|
release() {
|
|
this.config.reserved = false;
|
|
}
|
|
|
|
isReserved() {
|
|
return this.config.reserved === true;
|
|
}
|
|
|
|
update(obj) {
|
|
this.data = obj;
|
|
|
|
if (!this.isReserved()) {
|
|
return;
|
|
}
|
|
|
|
this.emit('updated', this);
|
|
}
|
|
|
|
remove() {
|
|
if (!this.isReserved()) {
|
|
return;
|
|
}
|
|
|
|
this.emit('removed', this);
|
|
}
|
|
}
|
|
|
|
module.exports = Resource;
|