mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-05-22 06:46:38 +00:00
Add new POST: Poll
This commit is contained in:
parent
64a87127a0
commit
c317b04d08
14
src/post/Poll.js
Normal file
14
src/post/Poll.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Post = require('./BasePost');
|
||||||
|
|
||||||
|
// A poll / vote
|
||||||
|
class Poll extends Post {
|
||||||
|
constructor(question, options) {
|
||||||
|
super("poll");
|
||||||
|
this.question = question;
|
||||||
|
this.options = options;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Poll;
|
@ -1,14 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const async = require('asyncawait/async');
|
|
||||||
const await = require('asyncawait/await');
|
|
||||||
|
|
||||||
const Post = require('./BasePost');
|
const Post = require('./BasePost');
|
||||||
const TextPost = require('./TextPost');
|
const TextPost = require('./TextPost');
|
||||||
const FilePost = require('./FilePost');
|
const FilePost = require('./FilePost');
|
||||||
const DirectoryPost = require('./DirectoryPost');
|
const DirectoryPost = require('./DirectoryPost');
|
||||||
const OrbitDBItem = require('./OrbitDBItem');
|
const OrbitDBItem = require('./OrbitDBItem');
|
||||||
const MetaInfo = require('./MetaInfo');
|
const MetaInfo = require('./MetaInfo');
|
||||||
|
const Poll = require('./Poll');
|
||||||
|
|
||||||
const PostTypes = {
|
const PostTypes = {
|
||||||
Message: TextPost,
|
Message: TextPost,
|
||||||
@ -16,7 +14,8 @@ const PostTypes = {
|
|||||||
File: FilePost,
|
File: FilePost,
|
||||||
Directory: DirectoryPost,
|
Directory: DirectoryPost,
|
||||||
Link: "link",
|
Link: "link",
|
||||||
OrbitDBItem: OrbitDBItem
|
OrbitDBItem: OrbitDBItem,
|
||||||
|
Poll: Poll
|
||||||
};
|
};
|
||||||
|
|
||||||
// Factory
|
// Factory
|
||||||
@ -33,13 +32,16 @@ class Posts {
|
|||||||
post = new PostTypes.Directory(data.name, data.hash, data.size);
|
post = new PostTypes.Directory(data.name, data.hash, data.size);
|
||||||
} else if(type == PostTypes.OrbitDBItem) {
|
} else if(type == PostTypes.OrbitDBItem) {
|
||||||
post = new PostTypes.OrbitDBItem(data.operation, data.key, data.value);
|
post = new PostTypes.OrbitDBItem(data.operation, data.key, data.value);
|
||||||
|
} else if(type == PostTypes.Poll) {
|
||||||
|
post = new PostTypes.Poll(data.question, data.options);
|
||||||
}
|
}
|
||||||
|
|
||||||
const size = data.size ? data.size : Buffer.byteLength(data, 'utf8');
|
const size = data.size ? data.size : Buffer.byteLength(data, 'utf8');
|
||||||
post.meta = new MetaInfo(post.type, size, new Date().getTime(), data.from);
|
post.meta = new MetaInfo(post.type, size, new Date().getTime(), data.from);
|
||||||
if(post.type) delete post.type;
|
if(post.type) delete post.type;
|
||||||
const res = await(ipfs.object.put(new Buffer(JSON.stringify({ Data: JSON.stringify(post) })), "json"));
|
ipfs.object.put(new Buffer(JSON.stringify({ Data: JSON.stringify(post) })), "json")
|
||||||
resolve({ Post: post, Hash: res.Hash });
|
.then((res) => resolve({ Post: post, Hash: res.Hash }))
|
||||||
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user