Browse Source

make sure to include the amount from the original purchase message in the terms

feature/dockerfile-arm
Evan Feenstra 5 years ago
parent
commit
1d73402cac
  1. 2
      api/controllers/media.ts
  2. 9
      api/network/modify.ts
  3. 2
      dist/api/controllers/media.js
  4. 2
      dist/api/controllers/media.js.map
  5. 7
      dist/api/network/modify.js
  6. 2
      dist/api/network/modify.js.map

2
api/controllers/media.ts

@ -182,6 +182,7 @@ const purchase = async (req, res) => {
uuid: short.generate(),
sender: owner.id,
type: constants.message_types.purchase,
amount: amount||0,
mediaToken: media_token,
date: date,
createdAt: date,
@ -223,6 +224,7 @@ const receivePurchase = async (payload) => {
uuid: msg_uuid,
sender: sender.id,
type: constants.message_types.purchase,
amount: amount||0,
mediaToken: mediaToken,
date: date,
createdAt: date,

9
api/network/modify.ts

@ -105,15 +105,14 @@ export async function sendFinalMemeIfFirstPurchaser(payload, chat, sender){
const existingMediaKey = await models.MediaKey.findOne({where:{muid}})
if(existingMediaKey) return // no need, its already been sent
console.log("DOWNLOAD AND REIP:OAD",mt)
const termsAndKey = await downloadAndUploadAndSaveReturningTermsAndKey(payload,chat,sender)
const host = mt.split('.')[0]
const ogPurchaseMessage = await models.Message.findOne({where:{
mediaToken: {[Op.like]: `${host}.${muid}%`},
type: msgtypes.purchase,
}})
const termsAndKey = await downloadAndUploadAndSaveReturningTermsAndKey(payload,chat,sender,ogPurchaseMessage.amount)
console.log('ogPurchaseMessage',ogPurchaseMessage.dataValues)
// send it to the purchaser
@ -151,7 +150,7 @@ async function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
export async function downloadAndUploadAndSaveReturningTermsAndKey(payload, chat, sender){
export async function downloadAndUploadAndSaveReturningTermsAndKey(payload, chat, sender, injectedAmount?:number){
const mt = payload.message && payload.message.mediaToken
const key = payload.message && payload.message.mediaKey
const typ = payload.message && payload.message.mediaType
@ -198,7 +197,7 @@ export async function downloadAndUploadAndSaveReturningTermsAndKey(payload, chat
if(!json.muid) throw new Error('no muid')
// PUT NEW TERMS, to finish in personalizeMessage
const amt = terms.meta&&terms.meta.amt
const amt = (terms.meta&&terms.meta.amt)||injectedAmount
const ttl = terms.meta&&terms.meta.ttl
const mediaTerms: {[k:string]:any} = {
muid:json.muid, ttl:ttl||31536000, host:'',

2
dist/api/controllers/media.js

@ -162,6 +162,7 @@ const purchase = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
uuid: short.generate(),
sender: owner.id,
type: constants.message_types.purchase,
amount: amount || 0,
mediaToken: media_token,
date: date,
createdAt: date,
@ -198,6 +199,7 @@ const receivePurchase = (payload) => __awaiter(void 0, void 0, void 0, function*
uuid: msg_uuid,
sender: sender.id,
type: constants.message_types.purchase,
amount: amount || 0,
mediaToken: mediaToken,
date: date,
createdAt: date,

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

File diff suppressed because one or more lines are too long

7
dist/api/network/modify.js

@ -114,13 +114,12 @@ function sendFinalMemeIfFirstPurchaser(payload, chat, sender) {
const existingMediaKey = yield models_1.models.MediaKey.findOne({ where: { muid } });
if (existingMediaKey)
return; // no need, its already been sent
console.log("DOWNLOAD AND REIP:OAD", mt);
const termsAndKey = yield downloadAndUploadAndSaveReturningTermsAndKey(payload, chat, sender);
const host = mt.split('.')[0];
const ogPurchaseMessage = yield models_1.models.Message.findOne({ where: {
mediaToken: { [sequelize_1.Op.like]: `${host}.${muid}%` },
type: msgtypes.purchase,
} });
const termsAndKey = yield downloadAndUploadAndSaveReturningTermsAndKey(payload, chat, sender, ogPurchaseMessage.amount);
console.log('ogPurchaseMessage', ogPurchaseMessage.dataValues);
// send it to the purchaser
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
@ -144,7 +143,7 @@ function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
});
}
function downloadAndUploadAndSaveReturningTermsAndKey(payload, chat, sender) {
function downloadAndUploadAndSaveReturningTermsAndKey(payload, chat, sender, injectedAmount) {
return __awaiter(this, void 0, void 0, function* () {
const mt = payload.message && payload.message.mediaToken;
const key = payload.message && payload.message.mediaKey;
@ -181,7 +180,7 @@ function downloadAndUploadAndSaveReturningTermsAndKey(payload, chat, sender) {
if (!json.muid)
throw new Error('no muid');
// PUT NEW TERMS, to finish in personalizeMessage
const amt = terms.meta && terms.meta.amt;
const amt = (terms.meta && terms.meta.amt) || injectedAmount;
const ttl = terms.meta && terms.meta.ttl;
const mediaTerms = {
muid: json.muid, ttl: ttl || 31536000, host: '',

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

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