Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Mar 17, 2021
1 parent cddf54b commit 39a1b61
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 107 deletions.
4 changes: 3 additions & 1 deletion src/api/helpers/layers-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export function checkValuesSender(data: any) {
let result =
data[i].type && data[i].value && infoType(data[i].value, data[i].type)
? true
: !data[i].value && data[i].isUser === false ? true : false;
: !data[i].value && data[i].isUser === false
? true
: false;
if (!result) {
return {
erro: true,
Expand Down
149 changes: 74 additions & 75 deletions src/api/layers/sender.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,86 +178,86 @@ export class SenderLayer extends ListenerLayer {
});
}

/**
/**
* Sends image message base64
* @param to Chat id
* @param base64 File path, http link or base64Encoded
* @param filename
* @param filename
* @param caption
*/
public async sendImageFromBase64(
to: string,
base64: string,
filename?: string,
caption?: string
): Promise<SendFileResult> {
return new Promise(async (resolve, reject) => {
const typeFunction = 'sendImageFromBase64';
const type = 'string';
const check = [
{
param: 'to',
type: type,
value: to,
function: typeFunction,
isUser: true,
},
{
param: 'base64',
type: type,
value: base64,
function: typeFunction,
isUser: true,
},
{
param: 'filename',
type: type,
value: filename,
function: typeFunction,
isUser: false,
},
];
const validating = checkValuesSender(check);
if (typeof validating === 'object') {
return reject(validating);
}
public async sendImageFromBase64(
to: string,
base64: string,
filename?: string,
caption?: string
): Promise<SendFileResult> {
return new Promise(async (resolve, reject) => {
const typeFunction = 'sendImageFromBase64';
const type = 'string';
const check = [
{
param: 'to',
type: type,
value: to,
function: typeFunction,
isUser: true,
},
{
param: 'base64',
type: type,
value: base64,
function: typeFunction,
isUser: true,
},
{
param: 'filename',
type: type,
value: filename,
function: typeFunction,
isUser: false,
},
];
const validating = checkValuesSender(check);
if (typeof validating === 'object') {
return reject(validating);
}

let mimeType = base64MimeType(base64);

if (!mimeType) {
obj = {
erro: true,
to: to,
text: 'Invalid base64!',
};
return reject(obj);
}

if (!mimeType.includes('image')) {
const obj = {
erro: true,
to: to,
text: 'Not an image, allowed formats png, jpeg and webp',
};
return reject(obj);
}

filename = filenameFromMimeType(filename, mimeType);

const result = await this.page.evaluate(
({ to, base64, filename, caption }) => {
return WAPI.sendImage(base64, to, filename, caption);
},
{ to, base64, filename, caption }
);
if (result['erro'] == true) {
return reject(result);
} else {
return resolve(result);
}
});
}

let mimeType = base64MimeType(base64);

if (!mimeType) {
obj = {
erro: true,
to: to,
text: 'Invalid base64!',
};
return reject(obj);
}

if (!mimeType.includes('image')) {
const obj = {
erro: true,
to: to,
text: 'Not an image, allowed formats png, jpeg and webp',
};
return reject(obj);
}

filename = filenameFromMimeType(filename, mimeType);

const result = await this.page.evaluate(
({ to, base64, filename, caption }) => {
return WAPI.sendImage(base64, to, filename, caption);
},
{ to, base64, filename, caption }
);
if (result['erro'] == true) {
return reject(result);
} else {
return resolve(result);
}
});
}

public async sendMessageOptions(
chat: any,
content: any,
Expand Down Expand Up @@ -327,7 +327,6 @@ export class SenderLayer extends ListenerLayer {
});
}


/**
* Sends message with thumbnail
* @param thumb
Expand Down
73 changes: 42 additions & 31 deletions src/lib/wapi/functions/check-send-exist.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export async function sendExist(chatId, returnChat = true, Send = true) {
}
if (
contact === chatId.substr(-contact.length, contact.length) &&
(chatId.match(/(@c.us)/g) && chatId.match(/(@c.us)/g).length > 1 ||
((chatId.match(/(@c.us)/g) && chatId.match(/(@c.us)/g).length > 1) ||
!chatId.match(/^(\d+(\d)*@c.us)$/g))
) {
return WAPI.scope(
Expand All @@ -113,7 +113,8 @@ export async function sendExist(chatId, returnChat = true, Send = true) {

if (
broadcast === chatId.substr(-broadcast.length, broadcast.length) &&
(chatId.match(/(@broadcast)/g) && chatId.match(/(@broadcast)/g).length > 1 ||
((chatId.match(/(@broadcast)/g) &&
chatId.match(/(@broadcast)/g).length > 1) ||
!chatId.match(/^(\d+(\d)*@broadcast)$/g))
) {
return WAPI.scope(
Expand All @@ -126,7 +127,7 @@ export async function sendExist(chatId, returnChat = true, Send = true) {

if (
grup === chatId.substr(-grup.length, grup.length) &&
(chatId.match(/(@g.us)/g) && chatId.match(/(@g.us)/g).length > 1 ||
((chatId.match(/(@g.us)/g) && chatId.match(/(@g.us)/g).length > 1) ||
!chatId.match(/^\d+(-)+(\d)*@g.us$/g))
) {
return WAPI.scope(
Expand All @@ -136,41 +137,51 @@ export async function sendExist(chatId, returnChat = true, Send = true) {
'incorrect parameters! Use as an example: [email protected]'
);
}
}
}

let ck = await window.WAPI.checkNumberStatus(chatId),
chat = await window.WAPI.getChat(ck.id._serialized);
let ck = await window.WAPI.checkNumberStatus(chatId),
chat = await window.WAPI.getChat(ck.id._serialized);

if (!chat) {
const storeChat = await window.Store.Chat.find(chatId);
if (storeChat) {
chat = await window.WAPI.getChat(storeChat.id._serialized);
}
}

if (!ck.numberExists && !chat.t && chat.isUser) {
return WAPI.scope(chatId, true, ck.status, 'The number does not exist');
if (!chat) {
const storeChat = await window.Store.Chat.find(chatId);
if (storeChat) {
chat = await window.WAPI.getChat(storeChat.id._serialized);
}
}

if (!ck.numberExists && !chat.t && chat.isGroup) {
return WAPI.scope(chatId, true, ck.status, 'The group number does not exist on your chat list, or it does not exist at all!');
}
if (!ck.numberExists && !chat.t && chat.isUser) {
return WAPI.scope(chatId, true, ck.status, 'The number does not exist');
}

if (!ck.numberExists && !chat.t && chat.isBroadcast) {
return WAPI.scope(chatId, true, ck.status, 'The transmission list number does not exist on your chat list, or it does not exist at all!');
}
if (!ck.numberExists && !chat.t && chat.isGroup) {
return WAPI.scope(
chatId,
true,
ck.status,
'The group number does not exist on your chat list, or it does not exist at all!'
);
}

if (!chat) {
return WAPI.scope(ck.id._serialized, true, 404);
}
if (!ck.numberExists && !chat.t && chat.isBroadcast) {
return WAPI.scope(
chatId,
true,
ck.status,
'The transmission list number does not exist on your chat list, or it does not exist at all!'
);
}

if (Send) {
await window.Store.SendSeen(chat, false);
}
if (!chat) {
return WAPI.scope(ck.id._serialized, true, 404);
}

if (returnChat) {
return chat;
}
if (Send) {
await window.Store.SendSeen(chat, false);
}

if (returnChat) {
return chat;
}

return WAPI.scope(ck.id._serialized, false, 200);
return WAPI.scope(ck.id._serialized, false, 200);
}

0 comments on commit 39a1b61

Please sign in to comment.