@nephele/adapter-s3
Version:
S3 (or compatible) object storage adapter for the Nephele WebDAV server.
38 lines • 1.16 kB
JavaScript
export default class Lock {
constructor({ resource, username, }) {
this.token = '';
this.date = new Date();
this.timeout = 1000 * 60 * 60 * 24 * 2;
this.scope = 'exclusive';
this.depth = '0';
this.provisional = false;
this.owner = {};
this.resource = resource;
this.username = username;
}
async save() {
const meta = await this.resource.getMetadata();
if (meta.locks == null) {
meta.locks = {};
}
meta.locks[this.token] = {
username: this.username,
date: this.date.getTime(),
timeout: this.timeout,
scope: this.scope,
depth: this.depth,
provisional: this.provisional,
owner: this.owner,
};
await this.resource.saveMetadata(meta);
}
async delete() {
const meta = await this.resource.getMetadata();
if (meta.locks == null || !(this.token in meta.locks)) {
return;
}
delete meta.locks[this.token];
await this.resource.saveMetadata(meta);
}
}
//# sourceMappingURL=Lock.js.map