Fix [BUG] Card sorting is broken #1069

This commit is contained in:
Cohee 2023-09-03 18:52:04 +03:00
parent e8545db9a5
commit 3e1815f599
2 changed files with 7 additions and 6 deletions

View File

@ -3532,8 +3532,8 @@
<select id="character_sort_order" title="Characters sorting order" data-i18n="[title]Characters sorting order"> <select id="character_sort_order" title="Characters sorting order" data-i18n="[title]Characters sorting order">
<option data-field="name" data-order="asc" data-i18n="A-Z">A-Z</option> <option data-field="name" data-order="asc" data-i18n="A-Z">A-Z</option>
<option data-field="name" data-order="desc" data-i18n="Z-A">Z-A</option> <option data-field="name" data-order="desc" data-i18n="Z-A">Z-A</option>
<option data-field="date_added" data-order="desc" data-i18n="Newest">Newest</option> <option data-field="create_date" data-order="desc" data-i18n="Newest">Newest</option>
<option data-field="date_added" data-order="asc" data-i18n="Oldest">Oldest</option> <option data-field="create_date" data-order="asc" data-i18n="Oldest">Oldest</option>
<option data-field="fav" data-order="desc" data-rule="boolean" data-i18n="Favorites">Favorites</option> <option data-field="fav" data-order="desc" data-rule="boolean" data-i18n="Favorites">Favorites</option>
<option data-field="date_last_chat" data-order="desc" data-i18n="Recent">Recent</option> <option data-field="date_last_chat" data-order="desc" data-i18n="Recent">Recent</option>
<option data-field="chat_size" data-order="desc" data-i18n="Most chats">Most chats</option> <option data-field="chat_size" data-order="desc" data-i18n="Most chats">Most chats</option>

View File

@ -309,8 +309,8 @@ function getTiktokenTokenizer(model) {
return tokenizer; return tokenizer;
} }
function humanizedISO8601DateTime() { function humanizedISO8601DateTime(date = Date.now()) {
let baseDate = new Date(Date.now()); let baseDate = new Date(date);
let humanYear = baseDate.getFullYear(); let humanYear = baseDate.getFullYear();
let humanMonth = (baseDate.getMonth() + 1); let humanMonth = (baseDate.getMonth() + 1);
let humanDate = baseDate.getDate(); let humanDate = baseDate.getDate();
@ -923,7 +923,7 @@ function convertToV2(char) {
}); });
result.chat = char.chat ?? humanizedISO8601DateTime(); result.chat = char.chat ?? humanizedISO8601DateTime();
result.create_date = char.create_date || humanizedISO8601DateTime(); result.create_date = char.create_date ?? humanizedISO8601DateTime();
return result; return result;
} }
@ -981,7 +981,7 @@ function readFromV2(char) {
}); });
char['chat'] = char['chat'] ?? humanizedISO8601DateTime(); char['chat'] = char['chat'] ?? humanizedISO8601DateTime();
char['create_date'] = char['create_date'] || humanizedISO8601DateTime(); char['create_date'] = char['create_date'] ?? humanizedISO8601DateTime();
return char; return char;
} }
@ -1383,6 +1383,7 @@ const processCharacter = async (item, i) => {
characters[i]['json_data'] = img_data; characters[i]['json_data'] = img_data;
const charStat = fs.statSync(path.join(charactersPath, item)); const charStat = fs.statSync(path.join(charactersPath, item));
characters[i]['date_added'] = charStat.birthtimeMs; characters[i]['date_added'] = charStat.birthtimeMs;
characters[i]['create_date'] = jsonObject['create_date'] || humanizedISO8601DateTime(charStat.birthtimeMs);
const char_dir = path.join(chatsPath, item.replace('.png', '')); const char_dir = path.join(chatsPath, item.replace('.png', ''));
const { chatSize, dateLastChat } = calculateChatSize(char_dir); const { chatSize, dateLastChat } = calculateChatSize(char_dir);