@nephele/adapter-nymph
Version:
Nymph.js based deduping file adapter for the Nephele WebDAV server.
100 lines • 3.45 kB
JavaScript
import { Entity, TilmeldAccessLevels, nymphJoiProps } from '@nymphjs/nymph';
import { enforceTilmeld, tilmeldJoiProps } from '@nymphjs/tilmeld';
import Joi from 'joi';
import { BadRequestError, UnauthorizedError } from 'nephele';
import { Resource } from './Resource.js';
export class Lock extends Entity {
constructor() {
super();
this.$clientEnabledMethods = [];
this.$allowlistData = [];
this.$allowlistTags = [];
this.$privateData = [];
this.$skipAcWhenSaving = false;
this.$skipAcWhenDeleting = false;
this.$data.token = '';
this.$data.date = new Date().getTime();
this.$data.timeout = 1000 * 60 * 60 * 24 * 2;
this.$data.scope = 'exclusive';
this.$data.depth = '0';
this.$data.provisional = false;
this.$data.owner = {};
this.$data.username = '';
this.$data.resource = Resource.factorySync();
}
$setNymph(nymph) {
this.$nymph = nymph;
if (!this.$asleep()) {
if (this.$data.user) {
this.$data.user.$setNymph(nymph);
}
if (this.$data.group) {
this.$data.group.$setNymph(nymph);
}
if (this.$data.resource) {
this.$data.resource.$setNymph(nymph);
}
}
}
async $save() {
try {
const tilmeld = enforceTilmeld(this);
if (!tilmeld.gatekeeper()) {
throw new UnauthorizedError('You must be logged in.');
}
}
catch (e) {
}
if (JSON.stringify(this.$data.owner).length > 8192) {
throw new BadRequestError('Lock owner must be less than 8KB.');
}
this.$data.acUser = TilmeldAccessLevels.FULL_ACCESS;
this.$data.acGroup = TilmeldAccessLevels.READ_ACCESS;
this.$data.acOther = TilmeldAccessLevels.READ_ACCESS;
try {
Joi.attempt(this.$getValidatable(), Joi.object().keys({
...nymphJoiProps,
...tilmeldJoiProps,
token: Joi.string().required(),
date: Joi.number().required(),
timeout: Joi.number().required(),
scope: Joi.string().allow('exclusive', 'shared').required(),
depth: Joi.string().allow('0', 'infinity').required(),
provisional: Joi.boolean().required(),
owner: Joi.any().required(),
username: Joi.string().required(),
resource: Joi.object().instance(Resource).required(),
}), 'Invalid Lock: ');
}
catch (e) {
throw new BadRequestError(e.message);
}
return await super.$save();
}
async $saveSkipAC() {
this.$skipAcWhenSaving = true;
return await this.$save();
}
$tilmeldSaveSkipAC() {
if (this.$skipAcWhenSaving) {
this.$skipAcWhenSaving = false;
return true;
}
return false;
}
async $deleteSkipAC() {
this.$skipAcWhenDeleting = true;
return await this.$delete();
}
$tilmeldDeleteSkipAC() {
if (this.$skipAcWhenDeleting) {
this.$skipAcWhenDeleting = false;
return true;
}
return false;
}
}
Lock.ETYPE = 'nephele_lock';
Lock.class = 'Lock';
Lock.clientEnabledStaticMethods = [];
//# sourceMappingURL=Lock.js.map