diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index d6c27f546..4eb50f6b4 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -1153,15 +1153,15 @@ const compareFunc = (first, second) => { return Math.random() > 0.5 ? 1 : -1; } + const a = first[power_user.sort_field]; + const b = second[power_user.sort_field]; + + if (power_user.sort_field === 'create_date') { + return sortMoments(timestampToMoment(b), timestampToMoment(a)); + } + switch (power_user.sort_rule) { case 'boolean': - const a = first[power_user.sort_field]; - const b = second[power_user.sort_field]; - - if (power_user.sort_field === 'create_date') { - return sortMoments(timestampToMoment(a), timestampToMoment(b)); - } - if (a === true || a === 'true') return 1; // Prioritize 'true' or true if (b === true || b === 'true') return -1; // Prioritize 'true' or true if (a && !b) return -1; // Move truthy values to the end @@ -1169,9 +1169,9 @@ const compareFunc = (first, second) => { if (a === b) return 0; // Sort equal values normally return a < b ? -1 : 1; // Sort non-boolean values normally default: - return typeof first[power_user.sort_field] == "string" - ? first[power_user.sort_field].localeCompare(second[power_user.sort_field]) - : first[power_user.sort_field] - second[power_user.sort_field]; + return typeof a == "string" + ? a.localeCompare(b) + : a - b; } }; diff --git a/server.js b/server.js index 126ab6e33..2488f0fcc 100644 --- a/server.js +++ b/server.js @@ -2178,6 +2178,7 @@ app.post("/importcharacter", urlencodedParser, async function (request, response importRisuSprites(jsonData); unsetFavFlag(jsonData); jsonData = readFromV2(jsonData); + jsonData["create_date"] = humanizedISO8601DateTime(); png_name = getPngName(jsonData.data?.name || jsonData.name); let char = JSON.stringify(jsonData); charaWrite(defaultAvatarPath, char, png_name, response, { file_name: png_name });