allows invalid propic to still be imported

This commit is contained in:
Aster Fialla
2026-02-16 00:16:38 -05:00
parent b83325785f
commit e67a10fa79
2 changed files with 18 additions and 5 deletions

View File

@@ -245,10 +245,11 @@ mh.removeMember = async function(authorId, args) {
* @param {string | null} displayName - The display name of the member. * @param {string | null} displayName - The display name of the member.
* @param {string | null} proxy - The proxy tag 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} 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. * @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. * @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) => { await mh.getMemberByName(authorId, memberName).then((member) => {
if (member) { if (member) {
throw new Error(`Can't add ${memberName}. ${enums.err.MEMBER_EXISTS}`); 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) { if (proxy) {
await mh.checkIfProxyExists(authorId, proxy).catch((e) =>{throw e}); await mh.checkIfProxyExists(authorId, proxy).catch((e) =>{throw e});
} }
let validPropic;
if (propic) { 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, name: memberName,
userid: authorId, userid: authorId,
displayname: displayName, displayname: displayName,
proxy: proxy, proxy: proxy,
propic: propic, propic: validPropic ? propic : null,
}).catch(e => { }).catch(e => {
throw new Error(`Can't add ${memberName}. ${enums.err.ADD_ERROR}: ${e.message}`) throw new Error(`Can't add ${memberName}. ${enums.err.ADD_ERROR}: ${e.message}`)
}) })

View File

@@ -1,5 +1,6 @@
import {enums} from "./enums.js"; import {enums} from "./enums.js";
import {memberHelper} from "./helpers/memberHelper.js"; import {memberHelper} from "./helpers/memberHelper.js";
import {messageHelper} from "./helpers/messageHelper.js";
const ih = {}; const ih = {};
@@ -22,11 +23,14 @@ ih.pluralKitImport = async function (authorId, attachmentUrl) {
const addedMembers = []; const addedMembers = [];
for (let pkMember of pkMembers) { for (let pkMember of pkMembers) {
const proxy = pkMember.proxy_tags[0] ? `${pkMember.proxy_tags[0].prefix ?? ''}text${pkMember.proxy_tags[0].suffix ?? ''}` : null; 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); addedMembers.push(member.name);
}).catch(e => { }).catch(e => {
errors.push(`${pkMember.name}: ${e.message}`); 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; const aggregatedText = addedMembers.length > 0 ? `Successfully added members: ${addedMembers.join(', ')}` : enums.err.NO_MEMBERS_IMPORTED;
if (errors.length > 0) { if (errors.length > 0) {