Browse Source

pub tribe last_active to tribe server, broadcast action for testing github integration

push-params
Evan Feenstra 5 years ago
parent
commit
bd0f3261f4
  1. 49
      api/controllers/actions.ts
  2. 2
      api/network/send.ts
  3. 13
      api/utils/tribes.ts
  4. 51
      dist/api/controllers/actions.js
  5. 2
      dist/api/controllers/actions.js.map
  6. 2
      dist/api/network/send.js
  7. 2
      dist/api/network/send.js.map
  8. 16
      dist/api/utils/tribes.js
  9. 2
      dist/api/utils/tribes.js.map

49
api/controllers/actions.ts

@ -2,8 +2,16 @@ import { success, failure } from '../utils/res'
import * as path from 'path'
import * as fs from 'fs'
import * as network from '../network'
import { models } from '../models'
import * as short from 'short-uuid'
import * as rsa from '../crypto/rsa'
/*
hexdump -n 16 -e '4/4 "%08X" 1 "\n"' /dev/random
*/
const actionFile = '../../../actions.json'
const constants = require(path.join(__dirname,'../../config/constants.json'))
export async function doAction(req, res) {
const thePath = path.join(__dirname,actionFile)
@ -24,7 +32,7 @@ async function processExtra(req, res) {
if(!(actions&&actions.length)) {
return failure(res, 'no actions defined')
}
const {action,app,secret,pubkey,amount} = req.body
const {action,app,secret,pubkey,amount,chat_uuid,text} = req.body
const theApp = actions.find(a=>a.app===app)
if(!theApp) {
@ -33,11 +41,14 @@ async function processExtra(req, res) {
if(!(theApp.secret&&theApp.secret===secret)) {
return failure(res, 'wrong secret')
}
if(!(pubkey&&pubkey.length===66&&amount&&action)) {
return failure(res, 'wrong params')
if(!action){
return failure(res, 'no action')
}
if(action==='keysend') {
if(!(pubkey&&pubkey.length===66&&amount)) {
return failure(res, 'wrong params')
}
const MIN_SATS = 3
const destkey = pubkey
const opts = {
@ -51,6 +62,38 @@ async function processExtra(req, res) {
} catch(e) {
return failure(res, e)
}
} else if (action==='broadcast') {
if(!chat_uuid || !text) return failure(res,'no uuid or text')
const owner = await models.Contact.findOne({ where: { isOwner: true } })
const theChat = await models.Chat.findOne({where:{uuid: chat_uuid}})
if(!theChat) return failure(res,'no chat')
if(!theChat.type===constants.chat_types.tribe) return failure(res,'not a tribe')
const encryptedForMeText = rsa.encrypt(owner.contactKey, text)
const encryptedText = rsa.encrypt(theChat.groupKey, text)
const textMap = {'chat': encryptedText}
var date = new Date();
date.setMilliseconds(0)
const msg:{[k:string]:any}={
chatId: theChat.id,
uuid: short.generate(),
type: constants.message_types.message,
sender: owner.id,
amount: amount||0,
date: date,
messageContent: encryptedForMeText,
remoteMessageContent: JSON.stringify(textMap),
status: constants.statuses.confirmed,
createdAt: date,
updatedAt: date,
}
const message = await models.Message.create(msg)
network.sendMessage({
chat: theChat,
sender: owner,
message: { content:textMap, id:message.id, uuid: message.uuid },
type: constants.message_types.message,
})
} else {
return failure(res, 'no action')
}

2
api/network/send.ts

@ -48,6 +48,8 @@ export async function sendMessage(params) {
networkType = 'mqtt' // broadcast to all
// decrypt message.content and message.mediaKey w groupKey
msg = await decryptMessage(msg, chat)
// post last_active to tribes server
tribes.putActivity(chat.uuid, chat.host)
} else {
// if tribe, send to owner only
const tribeOwner = await models.Contact.findOne({where: {publicKey:tribeOwnerPubKey}})

13
api/utils/tribes.ts

@ -123,6 +123,19 @@ export async function edit({ uuid, host, name, description, tags, img, price_per
}
}
export async function putActivity( uuid:string, host:string ) {
try {
const token = await genSignedTimestamp()
await fetch(`https://${host}/tribeactivity/${uuid}?token=` + token, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' }
})
} catch(e) {
console.log('[tribes] unauthorized to putActivity')
throw e
}
}
export async function putstats({ uuid, host, member_count }) {
try {
const token = await genSignedTimestamp()

51
dist/api/controllers/actions.js

@ -13,7 +13,14 @@ const res_1 = require("../utils/res");
const path = require("path");
const fs = require("fs");
const network = require("../network");
const models_1 = require("../models");
const short = require("short-uuid");
const rsa = require("../crypto/rsa");
/*
hexdump -n 16 -e '4/4 "%08X" 1 "\n"' /dev/random
*/
const actionFile = '../../../actions.json';
const constants = require(path.join(__dirname, '../../config/constants.json'));
function doAction(req, res) {
return __awaiter(this, void 0, void 0, function* () {
const thePath = path.join(__dirname, actionFile);
@ -38,7 +45,7 @@ function processExtra(req, res) {
if (!(actions && actions.length)) {
return res_1.failure(res, 'no actions defined');
}
const { action, app, secret, pubkey, amount } = req.body;
const { action, app, secret, pubkey, amount, chat_uuid, text } = req.body;
const theApp = actions.find(a => a.app === app);
if (!theApp) {
return res_1.failure(res, 'app not found');
@ -46,10 +53,13 @@ function processExtra(req, res) {
if (!(theApp.secret && theApp.secret === secret)) {
return res_1.failure(res, 'wrong secret');
}
if (!(pubkey && pubkey.length === 66 && amount && action)) {
return res_1.failure(res, 'wrong params');
if (!action) {
return res_1.failure(res, 'no action');
}
if (action === 'keysend') {
if (!(pubkey && pubkey.length === 66 && amount)) {
return res_1.failure(res, 'wrong params');
}
const MIN_SATS = 3;
const destkey = pubkey;
const opts = {
@ -65,6 +75,41 @@ function processExtra(req, res) {
return res_1.failure(res, e);
}
}
else if (action === 'broadcast') {
if (!chat_uuid || !text)
return res_1.failure(res, 'no uuid or text');
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const theChat = yield models_1.models.Chat.findOne({ where: { uuid: chat_uuid } });
if (!theChat)
return res_1.failure(res, 'no chat');
if (!theChat.type === constants.chat_types.tribe)
return res_1.failure(res, 'not a tribe');
const encryptedForMeText = rsa.encrypt(owner.contactKey, text);
const encryptedText = rsa.encrypt(theChat.groupKey, text);
const textMap = { 'chat': encryptedText };
var date = new Date();
date.setMilliseconds(0);
const msg = {
chatId: theChat.id,
uuid: short.generate(),
type: constants.message_types.message,
sender: owner.id,
amount: amount || 0,
date: date,
messageContent: encryptedForMeText,
remoteMessageContent: JSON.stringify(textMap),
status: constants.statuses.confirmed,
createdAt: date,
updatedAt: date,
};
const message = yield models_1.models.Message.create(msg);
network.sendMessage({
chat: theChat,
sender: owner,
message: { content: textMap, id: message.id, uuid: message.uuid },
type: constants.message_types.message,
});
}
else {
return res_1.failure(res, 'no action');
}

2
dist/api/controllers/actions.js.map

@ -1 +1 @@
{"version":3,"file":"actions.js","sourceRoot":"","sources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CAAC,aAAa,CAAC,OAAO;aACxC,CAAC,CAAA;SACL;aAAM;YACH,OAAO,aAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;SACnC;IACL,CAAC;CAAA"}

2
dist/api/network/send.js

@ -53,6 +53,8 @@ function sendMessage(params) {
networkType = 'mqtt'; // broadcast to all
// decrypt message.content and message.mediaKey w groupKey
msg = yield msg_1.decryptMessage(msg, chat);
// post last_active to tribes server
tribes.putActivity(chat.uuid, chat.host);
}
else {
// if tribe, send to owner only

2
dist/api/network/send.js.map

File diff suppressed because one or more lines are too long

16
dist/api/utils/tribes.js

@ -146,6 +146,22 @@ function edit({ uuid, host, name, description, tags, img, price_per_message, pri
});
}
exports.edit = edit;
function putActivity(uuid, host) {
return __awaiter(this, void 0, void 0, function* () {
try {
const token = yield genSignedTimestamp();
yield fetch(`https://${host}/tribeactivity/${uuid}?token=` + token, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' }
});
}
catch (e) {
console.log('[tribes] unauthorized to putActivity');
throw e;
}
});
}
exports.putActivity = putActivity;
function putstats({ uuid, host, member_count }) {
return __awaiter(this, void 0, void 0, function* () {
try {

2
dist/api/utils/tribes.js.map

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save