From 0be26e035bb3e389406b1dd9fdb323b0de50907c Mon Sep 17 00:00:00 2001 From: haad Date: Wed, 27 Apr 2016 12:33:15 +0200 Subject: [PATCH] Remove post/ prototypes --- src/post/BasePost.js | 10 ------ src/post/DirectoryPost.js | 15 --------- src/post/FilePost.js | 15 --------- src/post/MetaInfo.js | 12 ------- src/post/OrbitDBItem.js | 67 --------------------------------------- src/post/Poll.js | 14 -------- src/post/Post.js | 54 ------------------------------- src/post/TextPost.js | 18 ----------- 8 files changed, 205 deletions(-) delete mode 100644 src/post/BasePost.js delete mode 100644 src/post/DirectoryPost.js delete mode 100644 src/post/FilePost.js delete mode 100644 src/post/MetaInfo.js delete mode 100644 src/post/OrbitDBItem.js delete mode 100644 src/post/Poll.js delete mode 100644 src/post/Post.js delete mode 100644 src/post/TextPost.js diff --git a/src/post/BasePost.js b/src/post/BasePost.js deleted file mode 100644 index 1d72a94..0000000 --- a/src/post/BasePost.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -// Base class -class Post { - constructor(type) { - this.type = type; - } -} - -module.exports = Post; diff --git a/src/post/DirectoryPost.js b/src/post/DirectoryPost.js deleted file mode 100644 index 7902f3e..0000000 --- a/src/post/DirectoryPost.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; - -const Post = require('./BasePost'); - -// A reference to a file -class DirectoryPost extends Post { - constructor(name, hash, size) { - super("directory"); - this.name = name; - this.hash = hash; - this.size = size; - } -} - -module.exports = DirectoryPost; diff --git a/src/post/FilePost.js b/src/post/FilePost.js deleted file mode 100644 index 5f4638c..0000000 --- a/src/post/FilePost.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; - -const Post = require('./BasePost'); - -// A reference to a file -class FilePost extends Post { - constructor(name, hash, size) { - super("file"); - this.name = name; - this.hash = hash; - this.size = size; - } -} - -module.exports = FilePost; diff --git a/src/post/MetaInfo.js b/src/post/MetaInfo.js deleted file mode 100644 index 997a0cc..0000000 --- a/src/post/MetaInfo.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -class MetaInfo { - constructor(type, size, ts, from) { - this.type = type; - this.size = size; - this.ts = ts; - this.from = from || ''; - } -} - -module.exports = MetaInfo; diff --git a/src/post/OrbitDBItem.js b/src/post/OrbitDBItem.js deleted file mode 100644 index e13f144..0000000 --- a/src/post/OrbitDBItem.js +++ /dev/null @@ -1,67 +0,0 @@ -'use strict'; - -const Post = require('./BasePost'); - -class OrbitDBItem extends Post { - constructor(operation, key, value) { - super("orbit-db-op"); - this.op = operation; - this.key = key; - this.value = value; - } -} - -/* -class HashCacheItem { - constructor(operation, key, sequenceNumber, targetHash, metaInfo, next) { - this.op = operation; - this.seq = sequenceNumber; - this.key = key; - this.target = targetHash; - this.meta = metaInfo; - this.next = next; - } -} - -class EncryptedHashCacheItem extends HashCacheItem { - constructor(operation, key, sequenceNumber, targetHash, metaInfo, next, publicKey, privateKey, salt) { - if(key) - key = Encryption.encrypt(key, privateKey, publicKey); - - super(operation, key, sequenceNumber, targetHash, metaInfo, next); - - try { - this.pubkey = publicKey; - this.target = Encryption.encrypt(targetHash, privateKey, publicKey); - this.meta = Encryption.encrypt(JSON.stringify(metaInfo), privateKey, publicKey); - this.sig = Encryption.sign(this.target, privateKey, this.seq, salt || ""); - } catch(e) { - console.log("Failed to create HashCacheItem:", e); - } - } - - static fromEncrypted(encryptedItem, publicKey, privateKey, salt) { - let data = JSON.parse(encryptedItem.Data); - - // verify signature - const verified = Encryption.verify(data.target, data.pubkey, data.sig, data.seq, salt); - if(!verified) throw "Invalid signature" - - // link to the next item - const next = encryptedItem.Links[0] ? encryptedItem.Links[0].Hash : null; - - // decrypt data structure - const targetDec = Encryption.decrypt(data.target, privateKey, 'TODO: pubkey'); - const metaDec = Encryption.decrypt(data.meta, privateKey, 'TODO: pubkey'); - data.target = targetDec; - data.meta = JSON.parse(metaDec); - - if(data.key) - data.key = Encryption.decrypt(data.key, privateKey, 'TODO: pubkey'); - - const item = new HashCacheItem(data.op, data.key, data.seq, data.target, data.meta, next, publicKey, privateKey, salt); - return item; - } -} -*/ -module.exports = OrbitDBItem; diff --git a/src/post/Poll.js b/src/post/Poll.js deleted file mode 100644 index 1485e94..0000000 --- a/src/post/Poll.js +++ /dev/null @@ -1,14 +0,0 @@ -'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; diff --git a/src/post/Post.js b/src/post/Post.js deleted file mode 100644 index 04952d2..0000000 --- a/src/post/Post.js +++ /dev/null @@ -1,54 +0,0 @@ -'use strict'; - -const Buffer = require('buffer').Buffer; -const Post = require('./BasePost'); -const TextPost = require('./TextPost'); -const FilePost = require('./FilePost'); -const DirectoryPost = require('./DirectoryPost'); -const OrbitDBItem = require('./OrbitDBItem'); -const MetaInfo = require('./MetaInfo'); -const Poll = require('./Poll'); - -const PostTypes = { - Message: TextPost, - Snippet: "snippet", - File: FilePost, - Directory: DirectoryPost, - Link: "link", - OrbitDBItem: OrbitDBItem, - Poll: Poll -}; - -// Factory -class Posts { - static create(ipfs, type, data) { - return new Promise((resolve, reject) => { - let post; - - if(type === PostTypes.Message) { - post = new PostTypes.Message(data.content); - } else if(type === PostTypes.File) { - post = new PostTypes.File(data.name, data.hash, data.size); - } else if(type == PostTypes.Directory) { - post = new PostTypes.Directory(data.name, data.hash, data.size); - } else if(type == PostTypes.OrbitDBItem) { - 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'); - post.meta = new MetaInfo(post.type, size, new Date().getTime(), data.from); - if(post.type) delete post.type; - ipfs.object.put(new Buffer(JSON.stringify({ Data: JSON.stringify(post) })), "json") - .then((res) => resolve({ Post: post, Hash: res.Hash })) - .catch(reject); - }); - } - - static get Types() { - return PostTypes; - } -} - -module.exports = Posts; diff --git a/src/post/TextPost.js b/src/post/TextPost.js deleted file mode 100644 index 9350f46..0000000 --- a/src/post/TextPost.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -const Post = require('./BasePost'); -// const Encryption = require('orbit-common/lib/Encryption'); - -// Simplest type of post: a string -class TextPost extends Post { - constructor(content) { - super("text"); - this.content = content; - } - - // encrypt(privkey, pubkey) { - // this.content = Encryption.encrypt(this.content, privkey, pubkey); - // } -} - -module.exports = TextPost;