forked from PluralFlux/PluralFlux
allows invalid propic to still be imported
This commit is contained in:
@@ -245,10 +245,11 @@ mh.removeMember = async function(authorId, args) {
|
||||
* @param {string | null} displayName - The display name of the member.
|
||||
* @param {string | null} proxy - The proxy tag of the member.
|
||||
* @param {string | null} propic - The profile picture URL of the member.
|
||||
* @param {string | null} isImport - Whether calling from the import function or not.
|
||||
* @returns {Promise<model>} A successful addition.
|
||||
* @throws {Error | RangeError} When the member already exists, there are validation errors, or adding a member doesn't work.
|
||||
*/
|
||||
mh.addFullMember = async function(authorId, memberName, displayName = null, proxy = null, propic= null) {
|
||||
mh.addFullMember = async function(authorId, memberName, displayName = null, proxy = null, propic= null, isImport = false) {
|
||||
await mh.getMemberByName(authorId, memberName).then((member) => {
|
||||
if (member) {
|
||||
throw new Error(`Can't add ${memberName}. ${enums.err.MEMBER_EXISTS}`);
|
||||
@@ -263,16 +264,24 @@ mh.addFullMember = async function(authorId, memberName, displayName = null, prox
|
||||
if (proxy) {
|
||||
await mh.checkIfProxyExists(authorId, proxy).catch((e) =>{throw e});
|
||||
}
|
||||
let validPropic;
|
||||
if (propic) {
|
||||
await mh.checkImageFormatValidity(propic).catch((e) =>{throw e});
|
||||
validPropic = await mh.checkImageFormatValidity(propic).then((valid) => {
|
||||
return valid;
|
||||
}).catch((e) =>{
|
||||
if (!isImport) {
|
||||
throw (e);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
return await db.members.create({
|
||||
await db.members.create({
|
||||
name: memberName,
|
||||
userid: authorId,
|
||||
displayname: displayName,
|
||||
proxy: proxy,
|
||||
propic: propic,
|
||||
propic: validPropic ? propic : null,
|
||||
}).catch(e => {
|
||||
throw new Error(`Can't add ${memberName}. ${enums.err.ADD_ERROR}: ${e.message}`)
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {enums} from "./enums.js";
|
||||
import {memberHelper} from "./helpers/memberHelper.js";
|
||||
import {messageHelper} from "./helpers/messageHelper.js";
|
||||
|
||||
const ih = {};
|
||||
|
||||
@@ -22,11 +23,14 @@ ih.pluralKitImport = async function (authorId, attachmentUrl) {
|
||||
const addedMembers = [];
|
||||
for (let pkMember of pkMembers) {
|
||||
const proxy = pkMember.proxy_tags[0] ? `${pkMember.proxy_tags[0].prefix ?? ''}text${pkMember.proxy_tags[0].suffix ?? ''}` : null;
|
||||
await memberHelper.addFullMember(authorId, pkMember.name, pkMember.display_name, proxy, pkMember.avatar_url).then((member) => {
|
||||
await memberHelper.addFullMember(authorId, pkMember.name, pkMember.display_name, proxy, pkMember.avatar_url, true).then((member) => {
|
||||
addedMembers.push(member.name);
|
||||
}).catch(e => {
|
||||
errors.push(`${pkMember.name}: ${e.message}`);
|
||||
});
|
||||
await messageHelper.checkImageFormatValidity(pkMember.avatar_url).catch(e => {
|
||||
errors.push(`${pkMember.name}: ${e.message}`)
|
||||
});
|
||||
}
|
||||
const aggregatedText = addedMembers.length > 0 ? `Successfully added members: ${addedMembers.join(', ')}` : enums.err.NO_MEMBERS_IMPORTED;
|
||||
if (errors.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user