Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleBlockMove(index, nid, pos) {
const d = this.state.data;
// For some reason, we need to treat dragged object differently from selected
d.blocks[index].x = pos.x;
d.blocks[index].y = pos.y;
if (!this.moveOnlyCurrentBlock) {
const dx = pos.x - this.initialPos.x;
const dy = pos.y - this.initialPos.y;
const ts = new ObjectID().toString();
let idx;
for (let ii = 0; ii < d.blocks.length; ++ii) {
if (ii === index) {
continue;
}
idx = this.selectedNIDs.indexOf(d.blocks[ii].nid);
if (idx < 0) {
continue;
}
d.blocks[ii].x += dx;
d.blocks[ii].y += dy;
d.blocks[ii]._ts = ts;
}
}
this.initialPos = pos;
filename = undefined;
} else if(typeof mode == 'object') {
options = mode;
mode = filename;
filename = undefined;
}
if(id instanceof ObjectID) {
this.referenceBy = REFERENCE_BY_ID;
this.fileId = id;
this.filename = filename;
} else if(typeof filename == 'undefined') {
this.referenceBy = REFERENCE_BY_FILENAME;
this.filename = id;
if (mode.indexOf('w') != null) {
this.fileId = new ObjectID();
}
} else {
this.referenceBy = REFERENCE_BY_ID;
this.fileId = id;
this.filename = filename;
}
// Set up the rest
this.mode = mode == null ? "r" : mode;
this.options = options == null ? {w:1} : options;
// If we have no write concerns set w:1 as default
if(this.options.w == null
&& this.options.j == null
&& this.options.fsync == null) this.options.w = 1;
filename = undefined;
} else if (typeof mode == 'object') {
options = mode;
mode = filename;
filename = undefined;
}
if (id instanceof ObjectID) {
this.referenceBy = REFERENCE_BY_ID;
this.fileId = id;
this.filename = filename;
} else if (typeof filename == 'undefined') {
this.referenceBy = REFERENCE_BY_FILENAME;
this.filename = id;
if (mode.indexOf('w') != null) {
this.fileId = new ObjectID();
}
} else {
this.referenceBy = REFERENCE_BY_ID;
this.fileId = id;
this.filename = filename;
}
// Set up the rest
this.mode = mode == null ? "r" : mode;
this.options = options == null ? {} : options;
this.root = this.options['root'] == null ? exports.GridStore.DEFAULT_ROOT_COLLECTION : this.options['root'];
this.position = 0;
// Set default chunk size
this.internalChunkSize = this.options['chunkSize'] == null ? Chunk.DEFAULT_CHUNK_SIZE : this.options['chunkSize'];
}
if(err) return error(err);
// Check if the collection for the files exists otherwise prepare the new one
if(doc != null) {
self.fileId = doc._id;
// Prefer a new filename over the existing one if this is a write
self.filename = ((self.mode == 'r') || (self.filename == undefined)) ? doc.filename : self.filename;
self.contentType = doc.contentType;
self.internalChunkSize = doc.chunkSize;
self.uploadDate = doc.uploadDate;
self.aliases = doc.aliases;
self.length = doc.length;
self.metadata = doc.metadata;
self.internalMd5 = doc.md5;
} else if (self.mode != 'r') {
self.fileId = self.fileId == null ? new ObjectID() : self.fileId;
self.contentType = exports.GridStore.DEFAULT_CONTENT_TYPE;
self.internalChunkSize = self.internalChunkSize == null ? Chunk.DEFAULT_CHUNK_SIZE : self.internalChunkSize;
self.length = 0;
} else {
self.length = 0;
var txtId = self.fileId instanceof ObjectID ? self.fileId.toHexString() : self.fileId;
return error(new Error((self.referenceBy == REFERENCE_BY_ID ? txtId : self.filename) + " does not exist", self));
}
// Process the mode of the object
if(self.mode == "r") {
nthChunk(self, 0, options, function(err, chunk) {
if(err) return error(err);
self.currentChunk = chunk;
self.position = 0;
callback(null, self);
).thenResolve({
body: JSON.stringify([
new UserApiKey(new BSON.ObjectID().toHexString(), "2", "3", false)
]),
headers: {},
statusCode: 200
});
when(
requestClientMock.doAuthenticatedRequest(new RequestClassMatcher(
new RegExp(`.*\/${keyToFetch}$`),
Method.GET
) as any)
).thenResolve({
body: JSON.stringify(
new UserApiKey(new BSON.ObjectID().toHexString(), "2", "3", false)
),
headers: {},
statusCode: 200
});
when(
requestClientMock.doAuthenticatedRequest(new RequestClassMatcher(
new RegExp(`.*\/enable$`)
) as any)
).thenResolve({
headers: {},
statusCode: 200
});
when(
requestClientMock.doAuthenticatedRequest(new RequestClassMatcher(
async function getData(id: string, afterId: string) {
const filter: any = {
gameId: id,
};
if (afterId && ObjectID.isValid(afterId)) {
filter._id = { $gt: new ObjectID(afterId) };
}
return await Message.find(filter)
.select({
userId: 0,
updatedAt: 0,
__v: 0,
})
.sort({ _id: -1 })
.limit(100)
.lean();
}
submitSubComment = () => {
const secret = encoding.hex2ab(localStorage.getItem('mintPK'));
const publicKey = nacl.util.encodeBase64(nacl.sign.keyPair.fromSecretKey(secret).publicKey);
const id = new bson.ObjectID().toString();
let txBody = {
type: "createComment",
entity: {
id: id,
parentCommentId: this.props.comment._id,
postId: this.props.comment.postID,
content: this.content.value
}
}
makeRPC(txBody, publicKey, secret, () => {
window.location.href = '/post?id=' + this.props.comment.postID;
});
}
async tenants(@Parent() parent: User): Promise {
return await this.queryBus.execute(new GetTenantsQuery({
members: {$elemMatch: { userId: new ObjectID(parent.id)}},
}));
}
}
var Chunk = exports.Chunk = function(file, mongoObject, writeConcern) {
if(!(this instanceof Chunk)) return new Chunk(file, mongoObject);
this.file = file;
var self = this;
var mongoObjectFinal = mongoObject == null ? {} : mongoObject;
this.writeConcern = writeConcern || {w:1};
this.objectId = mongoObjectFinal._id == null ? new ObjectID() : mongoObjectFinal._id;
this.chunkNumber = mongoObjectFinal.n == null ? 0 : mongoObjectFinal.n;
this.data = new Binary();
if(mongoObjectFinal.data == null) {
} else if(typeof mongoObjectFinal.data == "string") {
var buffer = new Buffer(mongoObjectFinal.data.length);
buffer.write(mongoObjectFinal.data, 'binary', 0);
this.data = new Binary(buffer);
} else if(Array.isArray(mongoObjectFinal.data)) {
var buffer = new Buffer(mongoObjectFinal.data.length);
buffer.write(mongoObjectFinal.data.join(''), 'binary', 0);
this.data = new Binary(buffer);
} else if(mongoObjectFinal.data instanceof Binary || Object.prototype.toString.call(mongoObjectFinal.data) == "[object Binary]") {
this.data = mongoObjectFinal.data;
} else if(Buffer.isBuffer(mongoObjectFinal.data)) {
} else {
const cleanId = rawId => R.is(ObjectID, rawId) ? rawId : new ObjectID(rawId);